{"record":{"id":"3b0d81b8ef396b55","repo":"tracel-ai/burn","slug":"reshape-of-nd-block-quantized-tensor-is-not-yet-su","errorCode":null,"errorMessage":"Reshape of ND block-quantized tensor is not yet supported.","messagePattern":"Reshape of ND block-quantized tensor is not yet supported\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-cubecl/src/ops/base.rs","lineNumber":382,"sourceCode":"        &shape_values,\n    );\n    let action_values =\n        analysis_values.action(values.meta.shape(), values.meta.strides(), &shape_values);\n\n    let n_new_dims = shape.num_dims().saturating_sub(curr_shape.num_dims());\n    let is_unsqueeze = n_new_dims > 0 && shape[n_new_dims..] == **curr_shape;\n\n    // Check valid reshapes\n    if let ReshapeAction::UpdateStrides { .. } = &action_values {\n        match analysis_values {\n            ReshapeAnalysis::IsContiguous => {\n                if let Some(block_size) = scheme.block_size()\n                    && block_size.len() > 1\n                    && !is_unsqueeze\n                {\n                    // General reshape (e.g. [32, 4] -> [16, 8]): only valid if\n                    // reshaped dimension is aligned with the block boundaries.\n                    unimplemented!(\"Reshape of ND block-quantized tensor is not yet supported.\");\n                }\n            }\n            ReshapeAnalysis::Broadcasted => {} // only preprends unit dims\n            ReshapeAnalysis::Split => {\n                if let Some(block_size) = scheme.block_size()\n                    && block_size.len() > 1\n                {\n                    // Split reshape (e.g. [32, 4] -> [32, 2, 2]): only valid if\n                    // reshaped dimension is aligned with the block boundaries.\n                    unimplemented!(\n                        \"Split reshape of ND block-quantized tensor is not yet supported.\"\n                    );\n                }\n            }\n            other => unreachable!(\"Reshape analysis {other:?} should not update strides.\"),\n        }\n    }\n","sourceCodeStart":364,"sourceCodeEnd":400,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-cubecl/src/ops/base.rs#L364-L400","documentation":"q_reshape analyzes how the requested reshape interacts with a block-quantized tensor's scales. A general reshape (neither pure broadcast-like prepend nor a split) of a tensor with ND blocks (block_size.len() > 1) would require recomputing block boundaries, which is not implemented, so it panics.","triggerScenarios":"Calling reshape on a tensor quantized with multi-dimensional block sizes (e.g. block_size [16,4]) where the reshape is a general shape change like [32,4] -> [16,8], and it is not an unsqueeze.","commonSituations":"Using ND block quantization (e.g. NVFP4-style 2D blocks) and reorganizing tensor shapes between layers; dynamic model code that reshapes activations between ops.","solutions":["Avoid reshaping ND block-quantized tensors; keep the original shape until after dequantization","Dequantize, reshape, then re-quantize","Use 1D (per-row/per-tensor) block sizes if reshaping is essential","Upgrade burn to check for added ND block reshape support"],"exampleFix":"// before\nlet y = x.reshape([16, 8]); // ND block quant -> panic\n// after\nlet y = x.dequantize().reshape([16, 8]); // reshape in floating point","handlingStrategy":"validation","validationCode":"fn nd_block_reshape_safe(scheme: &QuantScheme, is_unsqueeze: bool) -> bool {\n    match scheme.block_size() {\n        Some(bs) if bs.len() > 1 && !is_unsqueeze => false,\n        _ => true,\n    }\n}","typeGuard":"fn is_1d_block(scheme: &QuantScheme) -> bool {\n    scheme.block_size().map_or(true, |b| b.len() <= 1)\n}","tryCatchPattern":"// Guard before reshape:\nif nd_block_reshape_safe(&scheme, false) { x.reshape(shape) } else { x.dequantize().reshape(shape) }","preventionTips":["Avoid ND block quantization if tensors are reshaped downstream","Dequantize before shape changes","Restrict reshapes to unsqueezes for ND-block tensors"],"tags":["quantization","reshape","block-quantization","unimplemented"],"backgroundTag":"unsupported-quantized-reshape","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"}