{"record":{"id":"21a68fe80972295c","repo":"tracel-ai/burn","slug":"todo-reshape-with-sub-byte-values-is-not-support","errorCode":null,"errorMessage":"todo!(\"Reshape with sub-byte values is not supported when the buffer must be recomputed\")","messagePattern":"todo!\\(\"Reshape with sub-byte values is not supported when the buffer must be recomputed\"\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-cubecl/src/ops/base.rs","lineNumber":458,"sourceCode":"            ReshapeAction::UpdateStrides {\n                strides: scales_strides,\n            },\n        ) => {\n            let qparams = tensor.qparams.as_mut().unwrap();\n\n            qparams.scales.metadata = Metadata::new(shape_scales, scales_strides);\n        }\n        // Any action to recompute\n        (ReshapeAction::Recompute, _) | (_, ReshapeAction::Recompute) => {\n            // Rewriting the buffer would have to repack values that share a\n            // storage element; a metadata-only reshape leaves the packing alone.\n            if !is_unsqueeze\n                && matches!(\n                    scheme.value,\n                    QuantValue::Q4S | QuantValue::Q4F | QuantValue::Q2S | QuantValue::Q2F\n                )\n            {\n                todo!(\n                    \"Reshape with sub-byte values is not supported when the buffer must be recomputed\"\n                )\n            }\n\n            if scheme.block_size().is_some() && shape_scales.num_elements() > 1 {\n                // Original block boundaries no longer align with the layout, would have to be recomputed\n                unimplemented!(\n                    \"Cannot reshape a block-quantized tensor when the reshape requires recomputing the buffer.\"\n                );\n            }\n\n            tensor = kernel::into_contiguous(tensor);\n            *tensor.meta = Metadata::new(shape, contiguous_strides(&shape_values));\n\n            let qparams = tensor.qparams.as_mut().unwrap();\n\n            let strides = contiguous_strides(&shape_scales);\n            qparams.scales.metadata = Metadata::new(shape_scales, strides);","sourceCodeStart":440,"sourceCodeEnd":476,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-cubecl/src/ops/base.rs#L440-L476","documentation":"In the CubeCL backend, reshaping a quantized tensor normally works when the buffer layout can be kept; but when the buffer must be recomputed and the quantization scheme packs sub-byte values (Q4S/Q4F/Q2S/Q2F), repacking is unsupported, so `q_reshape` panics with a `todo!`. Sub-byte packed layouts cannot be safely re-chunked without a repacking kernel.","triggerScenarios":"Calling `.reshape(...)` (or ops that internally reshape) on a quantized tensor with a 4-bit or 2-bit scheme (Q4S, Q4F, Q2S, Q2F) on the CubeCL backend in a case where the reshape is not a plain unsqueeze and forces buffer recomputation (e.g. merging/splitting packed dimensions).","commonSituations":"Reshaping 4-bit/2-bit quantized model activations or weights between layers; dynamic shape changes in a quantized pipeline; squeezing dimensions that hold packed nibbles.","solutions":["Reshape via dequantize → reshape → re-quantize instead of reshaping the packed tensor.","Use only unsqueeze-style reshapes (adding size-1 dims), which are allowed for sub-byte schemes.","Switch the quantization scheme to a byte-aligned one (e.g. Q8S) if reshaping is required.","Keep the original layout and pad instead of reshaping packed dimensions."],"exampleFix":"// before\nlet reshaped = q_tensor.reshape([b, h * w]); // Q4S, panics\n// after\nlet f = q_tensor.dequantize();\nlet reshaped = f.reshape([b, h * w]).quantize(&q_params, QuantScheme::Q4S);","handlingStrategy":"validation","validationCode":"fn reshape_safe(scheme: QuantScheme, is_unsqueeze: bool) -> bool {\n    is_unsqueeze || !matches!(scheme.value, QuantValue::Q4S | QuantValue::Q4F | QuantValue::Q2S | QuantValue::Q2F)\n}","typeGuard":"fn is_sub_byte(v: &QuantValue) -> bool { matches!(v, QuantValue::Q4S | QuantValue::Q4F | QuantValue::Q2S | QuantValue::Q2F) }","tryCatchPattern":null,"preventionTips":["Restrict reshapes of sub-byte quantized tensors to unsqueeze-style shape changes.","Dequantize → reshape → requantize for arbitrary reshapes.","Prefer Q8 schemes when layouts must change dynamically.","Check block-size alignment before reshaping quantized activations."],"tags":["burn","quantization","cubecl","reshape","sub-byte"],"backgroundTag":"unsupported-dtype","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"}