{"record":{"id":"e210ba9dd6c2841d","repo":"tracel-ai/burn","slug":"expected-float-dtype-got-dtype","errorCode":null,"errorMessage":"Expected float dtype, got {dtype:?}","messagePattern":"Expected float dtype, got (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-tensor/src/bridge/ops/float.rs","lineNumber":307,"sourceCode":"        let (kind, tensor) = tensor.into_parts();\n        match kind {\n            BridgeKind::Float => Dispatch::float_into_data(tensor).await,\n            BridgeKind::QFloat => Dispatch::q_into_data(tensor).await,\n            _ => panic!(\"Should be Float primitive kind\"),\n        }\n    }\n\n    fn from_data(data: TensorData, device: &Device, dtype: DType) -> BridgeTensor {\n        if matches!(data.dtype, DType::QFloat(_)) {\n            // When the source is QFloat, there is no conversion path possible.\n            BridgeTensor::qfloat(Dispatch::q_from_data(data, device.as_dispatch()))\n        } else if dtype.is_float() {\n            BridgeTensor::float(Dispatch::float_from_data(\n                data.convert_dtype(dtype),\n                device.as_dispatch(),\n            ))\n        } else {\n            panic!(\"Expected float dtype, got {dtype:?}\")\n        }\n    }\n\n    fn repeat_dim(tensor: BridgeTensor, dim: usize, times: usize) -> BridgeTensor {\n        let (kind, tensor) = tensor.into_parts();\n        match kind {\n            BridgeKind::Float => {\n                BridgeTensor::float(Dispatch::float_repeat_dim(tensor, dim, times))\n            }\n            BridgeKind::QFloat => BridgeTensor::qfloat(Dispatch::q_repeat_dim(tensor, dim, times)),\n            _ => panic!(\"Should be Float primitive kind\"),\n        }\n    }\n\n    fn cat(vectors: Vec<BridgeTensor>, dim: usize) -> BridgeTensor {\n        match vectors.first().unwrap().kind() {\n            BridgeKind::Float => BridgeTensor::float(Dispatch::float_cat(\n                BridgeTensor::into_dispatch_vec(vectors),","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-tensor/src/bridge/ops/float.rs#L289-L325","documentation":"This panic fires in Burn's tensor bridge when a tensor is created from raw data (from_data) with a dtype that is not a floating-point type. The bridge routes data to the float constructor only when `dtype.is_float()` is true; integer, bool, or other dtypes fall through to an unconditional panic. It is an internal API-contract violation: a non-float dtype reached the float-only construction path.","triggerScenarios":"Calling from_data (or an API that lowers to it, e.g. Tensor::from_data on a bridge backend) with data whose inferred dtype is an integer or bool while expecting a float tensor; passing a DType like I64/Bool into the float dispatch path; a backend adapter mislabeling the tensor kind so float_from_data receives int data.","commonSituations":"Loading a checkpoint or dataset of integer labels/indices and feeding it into a float tensor constructor; converting numpy/ndarray integer arrays without casting to f32/f64 first; recent dtype refactors (Burn's explicit DType migration) where code that previously inferred float now passes a concrete int dtype.","solutions":["Cast the data to a float dtype before constructing the tensor, e.g. data.convert_dtype(DType::F32) or convert the source array with .into_dtype()/astype(f32)","Check the DType you pass to the constructor; use Tensor::<B, D>::from_data for the numeric kind you actually have instead of the float path","If you are writing a backend/bridge adapter, ensure from_data dispatches on dtype.is_float() vs int/bool branches rather than always calling float_from_data","Verify the upstream data source (checkpoint, dataset) is being decoded with the intended dtype"],"exampleFix":"// before\nlet data = TensorData::from(vec![1i64, 2, 3]);\nlet t = BridgeTensor::from_data(data, dtype, &device); // dtype = F32 but data is I64 -> panic\n// after\nlet data = TensorData::from(vec![1i64, 2, 3]).convert_dtype(DType::F32);\nlet t = BridgeTensor::from_data(data, DType::F32, &device);","handlingStrategy":"validation","validationCode":"fn ensure_float(dtype: burn_tensor::DType) {\n    assert!(dtype.is_float(), \"from_data requires a float dtype, got {dtype:?}\");\n}","typeGuard":"fn is_float_dtype(dtype: burn_tensor::DType) -> bool {\n    dtype.is_float()\n}","tryCatchPattern":"// Panicking internal API; no catch pattern. Guard the dtype before the call:\nif !dtype.is_float() { let data = data.convert_dtype(burn_tensor::DType::F32); }","preventionTips":["Always cast source data (numpy, checkpoints, labels) to f32/f64 before float tensor construction","Match the DType argument to the actual data type instead of hardcoding F32","Use Tensor::from_data generic APIs that infer/convert dtype rather than dtype-specific bridge paths","When writing backend adapters, branch on dtype.is_float()/is_int()/is_bool()"],"tags":["dtype","tensor","panic","burn"],"backgroundTag":"invalid-tensor-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"}