{"record":{"id":"18a6db20b15b3f26","repo":"tracel-ai/burn","slug":"float-storage-as-f32-unsupported-dtype","errorCode":null,"errorMessage":"float_storage_as_f32: unsupported dtype {:?}","messagePattern":"float_storage_as_f32: unsupported dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/mod.rs","lineNumber":87,"sourceCode":"pub(crate) fn float_storage_as_f32(tensor: &FlexTensor) -> Cow<'_, [f32]> {\n    match tensor.dtype() {\n        DType::F32 => Cow::Borrowed(tensor.storage::<f32>()),\n        DType::F64 => Cow::Owned(tensor.storage::<f64>().iter().map(|&x| x as f32).collect()),\n        DType::F16 => Cow::Owned(\n            tensor\n                .storage::<f16>()\n                .iter()\n                .map(|x| f32::from(*x))\n                .collect(),\n        ),\n        DType::BF16 => Cow::Owned(\n            tensor\n                .storage::<bf16>()\n                .iter()\n                .map(|x| f32::from(*x))\n                .collect(),\n        ),\n        other => panic!(\"float_storage_as_f32: unsupported dtype {:?}\", other),\n    }\n}\n\npub mod activation;\npub mod attention;\npub mod binary;\nmod bool;\npub mod cat;\npub mod comparison;\n#[macro_use]\nmod conv_common;\npub mod conv;\npub mod conv_transpose;\npub mod cumulative;\npub mod deform_conv;\npub mod expand;\npub mod fft;\npub mod flip;","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/mod.rs#L69-L105","documentation":"float_storage_as_f32 is a helper in the burn-flex backend that reads a tensor's storage as f32 for float operations (with special cases for f32, f16, bf16). It panics when the tensor's dtype is none of the supported float types. This happens when a non-float tensor (e.g. integer/bool) or an exotic dtype reaches a float-only path such as quantize_dynamic or a half-precision mean reduction.","triggerScenarios":"Calling quantize_dynamic or quantize on a tensor whose dtype is not F32/F16/BF16 (e.g. an I8/I64/U8 tensor); calling mean_dim_half or mean_scalar_half on a non-float tensor; any code path that passes an integer tensor where a float tensor was expected.","commonSituations":"Quantizing a model whose input/output embeddings are stored as int8 or int4; loading checkpoints whose weights were saved with integer dtypes and using them without casting; dtype inference on const tensors returning integers unintentionally.","solutions":["Cast the tensor to a supported float dtype (F32 or BF16) before calling the op, e.g. tensor.cast(burn::tensor::DType::F32).","Inspect the offending tensor with tensor.dtype() (or a debug print) to confirm what dtype actually arrived; trace where it was created or loaded.","If weights come from a checkpoint/quantized loader, configure the loader to dequantize to f32/bf16 at load time instead of keeping integer storage.","If the dtype should be supported by the backend, add an arm to float_storage_as_f32 (e.g. I8 dequantization) in crates/burn-flex/src/ops/mod.rs."],"exampleFix":"// before\nlet quantized = quantize_dynamic(int_weights_tensor);\n// panic: float_storage_as_f32: unsupported dtype I8\n\n// after\nlet float_weights = int_weights_tensor.cast(burn::tensor::DType::F32);\nlet quantized = quantize_dynamic(float_weights);","handlingStrategy":"validation","validationCode":"fn assert_float(t: &burn::tensor::Tensor<burn::backend::Flex>) {\n    assert!(\n        matches!(t.dtype(), burn::tensor::DType::F32 | burn::tensor::DType::F64 | burn::tensor::DType::F16 | burn::tensor::DType::BF16),\n        \"float op requires float dtype, got {:?}\",\n        t.dtype()\n    );\n}\n// call before: assert_float(&t); quantize_dynamic(t, ...)","typeGuard":"fn is_float_dtype(d: burn::tensor::DType) -> bool {\n    matches!(d, burn::tensor::DType::F32 | burn::tensor::DType::F64 | burn::tensor::DType::F16 | burn::tensor::DType::BF16)\n}","tryCatchPattern":"// burn-flex panics rather than returning Result; wrap risky calls to isolate the abort\nlet result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| quantize_dynamic(t.clone())));\nmatch result {\n    Ok(q) => q,\n    Err(_) => quantize_dynamic(t.clone().cast(burn::tensor::DType::F32)),\n}","preventionTips":["Always cast loaded checkpoints/quantized weights to F32 or BF16 before float ops.","Add a debug assertion on tensor.dtype() at model input boundaries.","Never feed raw integer token ids or int8 payloads to float-only backend ops.","Keep a dtype test that runs every model op once on a tiny tensor to catch dispatch gaps."],"tags":["burn","dtype","panic","backend","quantization"],"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"}