{"record":{"id":"8d49bf8bb67683e2","repo":"tracel-ai/burn","slug":"can-t-store-native-sub-byte-values","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-backend/src/cubecl.rs","lineNumber":100,"sourceCode":"        DType::U32 => ElemType::UInt(UIntKind::U32),\n        DType::U16 => ElemType::UInt(UIntKind::U16),\n        DType::U8 => ElemType::UInt(UIntKind::U8),\n        DType::Bool(store) => match store {\n            BoolStore::Native => ElemType::Bool,\n            BoolStore::U8 => ElemType::UInt(UIntKind::U8),\n            BoolStore::U32 => ElemType::UInt(UIntKind::U32),\n        },\n        DType::QFloat(scheme) => match scheme.store {\n            QuantStore::Native => match scheme.value {\n                QuantValue::Q8F | QuantValue::Q8S => ElemType::Int(IntKind::I8),\n                QuantValue::E4M3 => ElemType::Float(FloatKind::E4M3),\n                QuantValue::E5M2 => ElemType::Float(FloatKind::E5M2),\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::PackedU32(_) => ElemType::UInt(UIntKind::U32),\n            QuantStore::PackedNative(_) => match scheme.value {\n                QuantValue::E2M1 => panic!(\"Can't store native sub-byte values\"),\n                other => panic!(\"{other:?} doesn't support native packing\"),\n            },\n        },\n    }\n}\n\n/// Convert a burn [`DType`] into the corresponding cubecl [`ElemType`].\n///\n/// Handles sub-byte packed quantization configurations that cannot be expressed\n/// as a plain [`ElemType`] by emitting a direct `ElemType`.\npub fn dtype_to_storage_type(dtype: DType) -> ElemType {\n    match dtype {\n        DType::QFloat(QuantScheme {","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-backend/src/cubecl.rs#L82-L118","documentation":"`dtype_to_elem_type` maps a quantization scheme's store/value into a cubecl `ElemType`. Under `QuantStore::Native`, sub-byte quantized values (Q4F, Q4S, Q2F, Q2S, E2M1) cannot be represented as a native single-byte-plus elem type, so it panics. Sub-byte values must use a packed store mode instead.","triggerScenarios":"Converting a quantization scheme to elem type (via `dtype_to_storage_type`, `fuse_base`, `create_key`, `generate_reduce_autotune_key`, `compute_input_grad`, `with_bounds`) where the scheme uses `QuantStore::Native` with a 4-bit or 2-bit `QuantValue` (Q4F/Q4S/Q2F/Q2S/E2M1).","commonSituations":"Configuring quantization with `QuantScheme::from(...).with_store(Native)` and a sub-byte value; loading a quantized checkpoint serialized with packed storage and rebuilding it with native storage; selecting 4-bit quantization (Q4) while forcing native storage in kernel/fusion code.","solutions":["Set the scheme's store to `QuantStore::PackedU32` for sub-byte values (Q4/Q2/E2M1) instead of `QuantStore::Native`.","Use a byte-or-larger QuantValue (e.g. E4M3, E5M2, Q8F) if you must keep native storage.","Fix the quantization configuration so storage mode matches value width before running kernels."],"exampleFix":"// before\nlet scheme = QuantScheme::new(QuantStore::Native, QuantValue::Q4F, ...);\n\n// after\nlet scheme = QuantScheme::new(QuantStore::PackedU32(PackingFactor::Uniform8), QuantValue::Q4F, ...);","handlingStrategy":"validation","validationCode":"// validate store/value compatibility before dispatch\nfn native_store_ok(scheme: &burn::tensor::QuantScheme) -> bool {\n    !matches!(scheme.store, burn::tensor::QuantStore::Native)\n        || !matches!(scheme.value,\n            burn::tensor::QuantValue::Q4F | burn::tensor::QuantValue::Q4S\n            | burn::tensor::QuantValue::Q2F | burn::tensor::QuantValue::Q2S\n            | burn::tensor::QuantValue::E2M1)\n}","typeGuard":"fn sub_byte(v: &burn::tensor::QuantValue) -> bool {\n    matches!(v, burn::tensor::QuantValue::Q4F | burn::tensor::QuantValue::Q4S\n        | burn::tensor::QuantValue::Q2F | burn::tensor::QuantValue::Q2S\n        | burn::tensor::QuantValue::E2M1)\n}","tryCatchPattern":null,"preventionTips":["Pair sub-byte QuantValues with PackedU32 storage at scheme construction.","Validate scheme store/value combinations when deserializing configs.","Add an assertion in quantization setup tests for storage compatibility."],"tags":["quantization","cubecl","dtype","panic","burn"],"backgroundTag":"unsupported-quantization-storage","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"}