{"record":{"id":"4cd85035a18e845b","repo":"tracel-ai/burn","slug":"not-a-valid-dtype-for-tensors","errorCode":null,"errorMessage":"Not a valid DType for tensors.","messagePattern":"Not a valid DType for tensors\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-backend/src/cubecl.rs","lineNumber":38,"sourceCode":"pub use cubecl::Device;\n/// Which runtime a [`Device`] belongs to. Re-exported alongside it: with one\n/// backend covering every runtime, naming a runtime is how a caller asks for a\n/// subset of the devices.\npub use cubecl::RuntimeId;\npub use cubecl::std::throughput::measure_peak_throughput;\n\n/// Convert a cubecl [`ElemType`] into the corresponding burn [`DType`].\n///\n/// Panics if the cubecl type has no direct burn equivalent (e.g. `TF32`).\npub fn elem_type_to_dtype(value: ElemType) -> DType {\n    match value {\n        ElemType::Float(float_kind) => match float_kind {\n            FloatKind::F16 => DType::F16,\n            FloatKind::BF16 => DType::BF16,\n            FloatKind::Flex32 => DType::Flex32,\n            FloatKind::F32 => DType::F32,\n            FloatKind::F64 => DType::F64,\n            FloatKind::TF32 => panic!(\"Not a valid DType for tensors.\"),\n            FloatKind::E2M1\n            | FloatKind::E2M1x2\n            | FloatKind::E2M3\n            | FloatKind::E3M2\n            | FloatKind::E4M3\n            | FloatKind::E5M2\n            | FloatKind::UE8M0 => {\n                unimplemented!(\"Not yet supported, will be used for quantization\")\n            }\n        },\n        ElemType::Int(int_kind) => match int_kind {\n            IntKind::I8 => DType::I8,\n            IntKind::I16 => DType::I16,\n            IntKind::I32 => DType::I32,\n            IntKind::I64 => DType::I64,\n        },\n        ElemType::UInt(uint_kind) => match uint_kind {\n            UIntKind::U8 => DType::U8,","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-backend/src/cubecl.rs#L20-L56","documentation":"`elem_type_to_dtype` converts a cubecl `ElemType` into a burn `DType`. `FloatKind::TF32` has no corresponding tensor DType in burn, so mapping it panics. TF32 exists in cubecl only as a GPU compute mode, not as a storable tensor dtype.","triggerScenarios":"Any code path calling `elem_type_to_dtype` (cubecl kernel `run`, `reduce_logical`, `reduce_dim_with_indices`, `init_reduce_output`) with a kernel whose element type resolves to `ElemType::Float(FloatKind::TF32)`.","commonSituations":"Writing a custom cubecl kernel with `ElemType::Float(FloatKind::TF32)` output and bridging it back into a burn tensor; autotune selecting a TF32 kernel config whose output must be materialized; copy-pasting kernel code using TF32 for storage.","solutions":["Use `FloatKind::F32` (or F16/BF16/Flex32) as the tensor storage elem type instead of TF32; TF32 is only valid for internal compute.","In the kernel, keep TF32 math internally but declare the output buffer as F32.","If an autotune config triggers this, restrict the autotune key/combinations to non-TF32 output types."],"exampleFix":"// before\nlet elem = ElemType::Float(FloatKind::TF32);\nlet dtype = elem_type_to_dtype(elem); // panics\n\n// after\nlet elem = ElemType::Float(FloatKind::F32);\nlet dtype = elem_type_to_dtype(elem);","handlingStrategy":"validation","validationCode":"// reject TF32 as a storage elem type before conversion\nif matches!(elem_type, cubecl::ir::ElemType::Float(cubecl::ir::FloatKind::TF32)) {\n    // use F32 storage; TF32 is compute-only\n}","typeGuard":"fn tensor_elem_type(e: &cubecl::ir::ElemType) -> Option<cubecl::ir::ElemType> {\n    match e {\n        cubecl::ir::ElemType::Float(cubecl::ir::FloatKind::TF32) => {\n            Some(cubecl::ir::ElemType::Float(cubecl::ir::FloatKind::F32))\n        }\n        _ => Some(e.clone()),\n    }\n}","tryCatchPattern":null,"preventionTips":["Treat TF32 as a compute mode only, never a tensor storage dtype.","In custom kernels, declare output buffers as F32 even when using TF32 math.","Restrict autotune configs to storable output dtypes."],"tags":["cubecl","dtype","tf32","gpu","burn"],"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"}