{"record":{"id":"e89ddf59b1468737","repo":"tracel-ai/burn","slug":"can-t-store-native-sub-byte-values-e89ddf","errorCode":null,"errorMessage":"Can't store native sub-byte values","messagePattern":"Can't store native sub-byte values","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-cubecl/src/ops/qtensor.rs","lineNumber":102,"sourceCode":"\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>(),\n            other => panic!(\"{other:?} doesn't support native packing\"),\n        },\n    };\n\n    let scales_dtype = match scheme.scale_dtype() {\n        ScaleDtype::F32 => DType::F32,\n        ScaleDtype::F16 => DType::F16,\n        ScaleDtype::BF16 => DType::BF16,\n        // Represented by U8 and reinterpreted in the kernel\n        ScaleDtype::UE8M0 | ScaleDtype::UE4M3 => DType::U8,\n    };\n\n    let scales_shape = params_shape(&shape, &scheme);\n    let data_desc = MemoryLayoutDescriptor::new(alloc_kind, shape_value.clone(), data_size);","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-cubecl/src/ops/qtensor.rs#L84-L120","documentation":"Sub-byte quantized values (Q4, Q2, E2M1) cannot be stored in Native mode, which stores one value per element slot in memory. They must be packed (PackedU32 or PackedNative). Attempting to allocate a native-stored tensor with one of these value types panics.","triggerScenarios":"Calling new_qtensor/empty_qtensor with a QuantScheme whose store is QuantStore::Native while scheme.value is Q4F, Q4S, Q2F, Q2S, or E2M1.","commonSituations":"Configuring quantization from a preset that selects sub-byte values but forgetting to enable packing, or migrating configs where the store field was reset to Native.","solutions":["Set the scheme's store to QuantStore::PackedU32 or PackedNative for sub-byte value types","Or switch the value type to a byte-sized one (Q8F/Q8S/E4M3/E5M2) to keep Native storage","Validate the store/value combination when constructing QuantScheme"],"exampleFix":"// before\nlet scheme = QuantScheme::default().with_value(QuantValue::Q4F); // Native store -> panics\n// after\nlet scheme = QuantScheme::default()\n    .with_value(QuantValue::Q4F)\n    .with_store(QuantStore::PackedU32(QuantAccurate::No));","handlingStrategy":"validation","validationCode":"const SUB_BYTE: &[QuantValue] = &[QuantValue::Q4F, QuantValue::Q4S, QuantValue::Q2F, QuantValue::Q2S, QuantValue::E2M1];\nassert!(!(scheme.store == QuantStore::Native && SUB_BYTE.contains(&scheme.value)),\n    \"sub-byte values need a packed store\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pair sub-byte QuantValue with PackedU32/PackedNative in one helper constructor","Unit-test scheme construction for every QuantValue you use","Never hand-edit QuantScheme store fields ad hoc"],"tags":["quantization","packing","config","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"}