{"record":{"id":"1c005addda5b264c","repo":"tracel-ai/burn","slug":"int-matmul-unsupported-dtype","errorCode":null,"errorMessage":"int_matmul: unsupported dtype {:?}","messagePattern":"int_matmul: unsupported dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/matmul.rs","lineNumber":516,"sourceCode":"pub fn int_matmul(lhs: FlexTensor, rhs: FlexTensor) -> FlexTensor {\n    assert_eq!(lhs.dtype(), rhs.dtype(), \"int_matmul: dtype mismatch\");\n\n    let lhs_shape = lhs.layout().shape();\n    let rhs_shape = rhs.layout().shape();\n    let lhs_rank = lhs_shape.num_dims();\n    let rhs_rank = rhs_shape.num_dims();\n\n    assert!(lhs_rank >= 2, \"int_matmul requires at least 2D tensors\");\n    assert!(rhs_rank >= 2, \"int_matmul requires at least 2D tensors\");\n\n    let k_lhs = lhs_shape[lhs_rank - 1];\n    let k_rhs = rhs_shape[rhs_rank - 2];\n    assert_eq!(k_lhs, k_rhs, \"int_matmul: inner dimensions must match\");\n\n    match lhs.dtype() {\n        DType::I32 => matmul_i32(lhs, rhs),\n        DType::I64 => matmul_i64(lhs, rhs),\n        _ => panic!(\"int_matmul: unsupported dtype {:?}\", lhs.dtype()),\n    }\n}\n\n/// i32 matmul using naive triple loop with SIMD dot product.\nfn matmul_i32(lhs: FlexTensor, rhs: FlexTensor) -> FlexTensor {\n    let lhs = lhs.to_contiguous();\n    let rhs = rhs.to_contiguous();\n\n    let lhs_shape = lhs.layout().shape();\n    let rhs_shape = rhs.layout().shape();\n    let lhs_rank = lhs_shape.num_dims();\n    let rhs_rank = rhs_shape.num_dims();\n\n    if lhs_rank == 2 && rhs_rank == 2 {\n        matmul_2d_i32(&lhs, &rhs)\n    } else {\n        matmul_batched_i32(lhs, rhs)\n    }","sourceCodeStart":498,"sourceCodeEnd":534,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/matmul.rs#L498-L534","documentation":"int_matmul performs integer matrix multiplication but only supports I32 and I64 dtypes; the match panics for all others (I8/I16, unsigned U8..U64, floats, Bool). Operands must also share the same inner (K) dimension, enforced by an assert just above the panic.","triggerScenarios":"Calling int matmul with operands of dtype I8/I16 or any unsigned dtype (U8/U16/U32/U64), or passing float tensors to the int matmul path.","commonSituations":"Quantized inference with int8 weights/activations; image tensors (u8) fed into an integer linear layer; dtype mismatch between lhs (i32) and rhs (u8) so lhs itself is fine but patterns like casting only one operand mislead; porting numpy int matmuls with 16-bit types.","solutions":["Cast both operands to I32 or I64 before the matmul: a.cast::<i32>().matmul(b.cast::<i32>()).","For int8 quantized workloads, upcast to i32 (standard practice to avoid accumulation overflow anyway).","For float tensors, use the float matmul path instead of int_matmul.","Add a dtype assert on both operands before entering the matmul helper."],"exampleFix":"// before\nlet out = w_u8.matmul(x_u8); // U8 -> panic\n// after\nlet out = w_u8.cast::<i32>().matmul(x_u8.cast::<i32>());","handlingStrategy":"validation","validationCode":"assert!(matches!(lhs.dtype(), DType::I32 | DType::I64) && matches!(rhs.dtype(), DType::I32 | DType::I64), \"int_matmul supports only I32/I64, got {:?} and {:?}\", lhs.dtype(), rhs.dtype());","typeGuard":"fn is_int_matmul_compatible(t: &FlexTensor) -> bool { matches!(t.dtype(), DType::I32 | DType::I64) }","tryCatchPattern":null,"preventionTips":["Cast I8/I16/unsigned operands to I32 before integer matmul","Upcast int8 quantized weights to i32 to avoid accumulation overflow","Use the float matmul path for float tensors","Assert both operand dtypes before helper matmul functions"],"tags":["rust","burn","matmul","dtype","int"],"backgroundTag":"unsupported-dtype-for-op","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}