Problem
mx.einsum supports integer inputs for non-matmul forms, but a valid integer contraction such as "ij,jk->ik" is lowered to matmul, which rejects non-floating types.
This is related to #516, which declined dedicated integer GEMM kernels. einsum may still be able to support these equations without an integer GEMM by using its existing multiply-and-reduce lowering as a fallback when the optimized matmul path does not support the dtype.
This matters for ONNX interoperability because ONNX Einsum-28 permits all numeric tensor types. In mlx-c applications, reaching this error with the default error handler terminates the host process (exit(-1)), so downstream runtimes must currently reject integer contractions before calling MLX.
Reproduction
import mlx.core as mx
x = mx.array([[1, 2], [3, 4]], dtype=mx.int32)
# Integer Einsum forms without a matmul contraction work.
print(mx.einsum("ij->ji", x))
print(mx.einsum("ij->", x))
print(mx.einsum("i,j->ij", x[0], x[1]))
# A contraction selected for the matmul path fails.
y = mx.einsum("ij,jk->ik", x, x)
mx.eval(y)
Observed with MLX 0.32.2:
ValueError: [matmul] Only inexact types are supported but int32 and int32 were provided which results in int32, which is not a floating point type.
The same behavior occurs for int8/int16/int64 and uint8/uint16/uint32/uint64.
Expected behavior
Preferably, integer contractions should fall back to an integer-compatible multiply-and-reduce Einsum path when the optimized matmul path is unavailable. If integer contractions are intentionally unsupported, einsum should document that only non-contraction integer equations are supported.
Problem
mx.einsumsupports integer inputs for non-matmul forms, but a valid integer contraction such as"ij,jk->ik"is lowered tomatmul, which rejects non-floating types.This is related to #516, which declined dedicated integer GEMM kernels.
einsummay still be able to support these equations without an integer GEMM by using its existing multiply-and-reduce lowering as a fallback when the optimized matmul path does not support the dtype.This matters for ONNX interoperability because ONNX Einsum-28 permits all numeric tensor types. In mlx-c applications, reaching this error with the default error handler terminates the host process (
exit(-1)), so downstream runtimes must currently reject integer contractions before calling MLX.Reproduction
Observed with MLX 0.32.2:
The same behavior occurs for int8/int16/int64 and uint8/uint16/uint32/uint64.
Expected behavior
Preferably, integer contractions should fall back to an integer-compatible multiply-and-reduce Einsum path when the optimized matmul path is unavailable. If integer contractions are intentionally unsupported,
einsumshould document that only non-contraction integer equations are supported.