{"record":{"id":"cfcee6920a579d81","repo":"tracel-ai/burn","slug":"can-t-store-in-u32","errorCode":null,"errorMessage":"Can't store in u32","messagePattern":"Can't store in u32","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-cubecl/src/ops/qtensor.rs","lineNumber":88,"sourceCode":"fn new_quantized(\n    shape: impl Into<Shape>,\n    scheme: QuantScheme,\n    device: &CubeDevice,\n    data: Option<Bytes>,\n    alloc_kind: MemoryLayoutStrategy,\n) -> CubeTensor {\n    let client = device.client();\n    let shape: Shape = shape.into();\n    let mut shape_value: Shape = shape.clone();\n\n    let rank = shape.rank();\n    let shape_last = shape[rank - 1];\n    let num_quants = scheme.num_quants();\n\n    let data_size = match scheme.store {\n        QuantStore::PackedU32(_) => {\n            if !shape_last.is_multiple_of(num_quants) {\n                panic!(\"Can't store in u32\")\n            }\n            shape_value[rank - 1] = shape_last.div_ceil(num_quants);\n            size_of::<u32>()\n        }\n        QuantStore::Native => match scheme.value {\n            QuantValue::Q8F | QuantValue::Q8S | QuantValue::E4M3 | QuantValue::E5M2 => {\n                size_of::<i8>()\n            }\n            QuantValue::Q4F\n            | QuantValue::Q4S\n            | QuantValue::Q2F\n            | QuantValue::Q2S\n            | QuantValue::E2M1 => {\n                panic!(\"Can't store native sub-byte values\")\n            }\n        },\n        QuantStore::PackedNative(_) => match scheme.value {\n            QuantValue::E2M1 => size_of::<e2m1x2>(),","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-cubecl/src/ops/qtensor.rs#L70-L106","documentation":"Quantized tensors stored as PackedU32 pack multiple quantized values per u32; this requires the last tensor dimension to be a multiple of the number of values packed per u32 (num_quants). If it isn't, the data cannot be laid out in whole u32 words and the library panics during tensor allocation.","triggerScenarios":"Creating a quantized tensor with QuantStore::PackedU32 (e.g. Q4/Q2 packing into u32) where shape[rank-1] % num_quants != 0, via new_qtensor or empty_qtensor.","commonSituations":"Quantizing a model whose last linear layer output (or embedding dim) isn't divisible by the pack factor (e.g. dim 1002 with 4-bit values packing 8 per u32), or reshaping packed quant tensors to non-divisible last dims.","solutions":["Pad or choose the quantized dimension so the last dim is divisible by num_quants for the scheme","Switch the scheme to QuantStore::Native with a byte-aligned value like Q8 if the dim can't change","Check num_quants() for your QuantScheme to know the required divisibility","Adjust model architecture (e.g. set the last linear out-features divisible by the pack factor)"],"exampleFix":"// before: last dim 1002 with Q4 packed in u32 (needs %8==0)\nlet qt = Tensor::new_quantized(data, scheme); // panics\n// after: pad weights to 1008 or use Native store\nlet scheme = scheme.with_store(QuantStore::Native);\nlet qt = Tensor::new_quantized(data, scheme);","handlingStrategy":"validation","validationCode":"let num_quants = scheme.num_quants();\nassert_eq!(shape[shape.len() - 1] % num_quants, 0,\n    \"last dim must be divisible by {num_quants} for PackedU32\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make quantized feature dims multiples of the pack factor","Check scheme.num_quants() whenever the store is PackedU32","Pad weights before quantization in your export pipeline"],"tags":["quantization","packing","shape","burn"],"backgroundTag":"quant-store-alignment","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"}