Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

int4 type support for matmul #8566

Closed
rybakov opened this issue Nov 17, 2021 · 2 comments
Closed

int4 type support for matmul #8566

rybakov opened this issue Nov 17, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@rybakov
Copy link

rybakov commented Nov 17, 2021

Hello,

I am working on hardware-accelerated matmul with int4 input tensors and get back an int16/int32 tensor.
I would like to be able to run matmul and emit MHLO with example below (or let me know if there are better options):

x=jnp.array(100).reshape((1,1)).astype(jnp.int4)
jnp.matmul(x,x)

Thanks!

@rybakov rybakov added the enhancement New feature or request label Nov 17, 2021
@zhangqiaorjc
Copy link
Member

cc @hawkinsp

@hawkinsp hawkinsp self-assigned this Nov 22, 2021
@hawkinsp
Copy link
Member

hawkinsp commented Nov 3, 2023

This is fixed these days!

In [5]: import jax, jax.numpy as jnp, numpy as np
In [8]: x=np.array(100).reshape((1,1)).astype(jnp.int4)
   ...: print(jax.jit(jnp.matmul).lower(x,x).as_text())
module @jit_matmul attributes {mhlo.num_partitions = 1 : i32, mhlo.num_replicas = 1 : i32} {
  func.func public @main(%arg0: tensor<1x1xi4> {mhlo.sharding = "{replicated}"}, %arg1: tensor<1x1xi4> {mhlo.sharding = "{replicated}"}) -> (tensor<1x1xi4> {jax.result_info = ""}) {
    %0 = stablehlo.dot_general %arg0, %arg1, contracting_dims = [1] x [0], precision = [DEFAULT, DEFAULT] : (tensor<1x1xi4>, tensor<1x1xi4>) -> tensor<1x1xi4>
    return %0 : tensor<1x1xi4>
  }
}

(There's no guarantee any given JAX backend knows how to compile that, but producing the stablehlo is no problem.)

@hawkinsp hawkinsp closed this as completed Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants