{"record":{"id":"294aa5379b0e5a67","repo":"tracel-ai/burn","slug":"invalid-ref-layout","errorCode":null,"errorMessage":"Invalid ref layout","messagePattern":"Invalid ref layout","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-cubecl-fusion/src/optim/matmul/optimization.rs","lineNumber":429,"sourceCode":"        if matrix_batch_layout(&lhs_strides, lhs_scheme) == MatrixBatchLayout::HighlyPermuted {\n            return Err(FusedMatmulError::InvalidInput(\n                \"Lhs needs to be contiguous, but can't when fusing.\",\n            ));\n        }\n        if matrix_batch_layout(&rhs_strides, rhs_scheme) == MatrixBatchLayout::HighlyPermuted {\n            return Err(FusedMatmulError::InvalidInput(\n                \"Rhs needs to be contiguous, but can't when fusing.\",\n            ));\n        }\n\n        let mut vector_sizes = MatmulVectorSizes {\n            lhs: inputs.vector_size(self.matmul.lhs.data()),\n            rhs: inputs.vector_size(self.matmul.rhs.data()),\n            out: match &config.ref_layout {\n                RefLayout::Concrete(arg) => match arg {\n                    FuseArg::Input(..) => inputs.vector_size(arg),\n                    FuseArg::Output(..) => outputs.vector_size(arg),\n                    _ => panic!(\"Invalid ref layout\"),\n                },\n                RefLayout::Virtual(_) => 1,\n            },\n        };\n\n        let address_type = inputs\n            .required_address_type()\n            .max(outputs.required_address_type());\n\n        if vector_sizes.out == 1 && (vector_sizes.lhs > 1 || vector_sizes.rhs > 1) {\n            return Err(FusedMatmulError::InvalidInput(\n                \"Output vector size of 1 removes the gain from fusion\",\n            ));\n        }\n\n        if let MatmulArg::Quantized { scheme, .. } = self.matmul.lhs {\n            vector_sizes.lhs *= scheme.num_quants();\n        }","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-cubecl-fusion/src/optim/matmul/optimization.rs#L411-L447","documentation":"`MatmulVectorSizes` derives vectorization widths for lhs/rhs/out. When the output's `RefLayout::Concrete` wraps something other than `FuseArg::Input` or `FuseArg::Output`, the vector size cannot be resolved and the code panics — a structural invariant of the fusion optimizer.","triggerScenarios":"Building/running a fused matmul whose `ref_layout` is Concrete over an unexpected FuseArg variant (neither Input nor Output).","commonSituations":"Custom matmul optimization providers mislabeling their output arg; restored fusion states from incompatible burn versions.","solutions":["Ensure the matmul output arg's ref_layout is Concrete over FuseArg::Output (or Input)","Audit custom provider code that sets RefLayout for the output tensor","Keep all burn crates on the same version; report internal-trigger cases upstream"],"exampleFix":"// before\nRefLayout::Concrete(FuseArg::Constant(..))\n// after\nRefLayout::Concrete(FuseArg::Output(out_pos, ..))","handlingStrategy":"validation","validationCode":"if let RefLayout::Concrete(a) = &config.ref_layout {\n    assert!(matches!(a, FuseArg::Input(..) | FuseArg::Output(..)));\n}","typeGuard":"fn valid_vector_size_layout(l: &RefLayout) -> bool {\n    matches!(l, RefLayout::Concrete(FuseArg::Input(..) | FuseArg::Output(..)) | RefLayout::Virtual(_))\n}","tryCatchPattern":null,"preventionTips":["Set output ref_layout only to Concrete(Output) or Virtual","Version-lock burn crates when serializing fusion state","Cover MatmulVectorSizes in provider integration tests"],"tags":["fusion","matmul","gpu","internal-invariant"],"backgroundTag":"invalid-fusion-ref-layout","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"}