{"record":{"id":"f228419b8baabce3","repo":"tracel-ai/burn","slug":"unsupported-dtype-for-float-from-data-f22841","errorCode":null,"errorMessage":"Unsupported dtype for `float_from_data`","messagePattern":"Unsupported dtype for `float_from_data`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-tch/src/ops/tensor.rs","lineNumber":17,"sourceCode":"use super::TchOps;\nuse crate::{IntoKind, LibTorch, LibTorchDevice, TchShape, TchTensor};\nuse burn_backend::backend::ExecutionError;\nuse burn_backend::tensor::{BoolTensor, FloatTensor, IntTensor};\nuse burn_backend::{BoolDType, IntDType, Scalar, bf16, f16};\nuse burn_backend::{\n    DType, Distribution, FloatDType, Shape, TensorData, TensorMetadata, ops::FloatTensorOps,\n};\n\nimpl FloatTensorOps<Self> for LibTorch {\n    fn float_from_data(data: TensorData, device: &LibTorchDevice) -> TchTensor {\n        match data.dtype {\n            DType::F64 => TchTensor::from_data::<f64>(data, (*device).into()),\n            DType::F32 => TchTensor::from_data::<f32>(data, (*device).into()),\n            DType::F16 => TchTensor::from_data::<f16>(data, (*device).into()),\n            DType::BF16 => TchTensor::from_data::<bf16>(data, (*device).into()),\n            _ => unimplemented!(\"Unsupported dtype for `float_from_data`\"),\n        }\n    }\n\n    fn float_random(\n        shape: Shape,\n        distribution: Distribution,\n        device: &LibTorchDevice,\n        dtype: FloatDType,\n    ) -> TchTensor {\n        match distribution {\n            Distribution::Default => {\n                let mut tensor = TchTensor::empty(shape, *device, dtype.into());\n                tensor\n                    .mut_ops(|tensor| tensor.rand_like_out(tensor))\n                    .unwrap()\n            }\n            Distribution::Bernoulli(prob) => {\n                let mut tensor = TchTensor::empty(shape, *device, dtype.into());","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-tch/src/ops/tensor.rs#L1-L35","documentation":"burn-tch's `float_from_data` converts TensorData into a LibTorch float tensor, but only F64, F32, F16 and BF16 are handled. Any other dtype (integer, bool, quantized) falls into the `_` arm and panics with this message.","triggerScenarios":"Calling `Tensor::<TchBackend>::from_data(...)` (or from_data on a float tensor type) with TensorData whose dtype is I64, I32, U8, BOOL, QFloat, etc., instead of a float dtype.","commonSituations":"Loading data saved as int/uint arrays (e.g. from numpy or raw files) and passing it straight to from_data; dtype drift after changing how data is serialized; quantized data accidentally fed to a float tensor constructor.","solutions":["Convert the data to a float dtype before calling from_data (e.g. map the Vec to f32 and rebuild TensorData)","Fix the producer/exporter so the TensorData carries F32/F16/BF16/F64","Use the appropriate integer tensor constructor (int_from_data) instead of the float one","Add an explicit dtype check with a clear error before the call"],"exampleFix":"// before\nlet data = TensorData::new(vec![1i64, 2, 3]);\nlet t = Tensor::<B, 1>::from_data(data.convert::<f32>(), &device);\n// panics only if not converted; ensure conversion:\n// after\nlet t = Tensor::<B, 1>::from_data(data.convert::<f32>(), &device);","handlingStrategy":"validation","validationCode":"assert!(is_float_data(&data));","typeGuard":"fn is_float_data(d: &TensorData) -> bool {\n    matches!(d.dtype, DType::F32 | DType::F64 | DType::F16 | DType::BF16)\n}","tryCatchPattern":null,"preventionTips":["Check TensorData::dtype before tensor construction","Convert at the data boundary with data.convert::<f32>()","Route int data to integer tensor APIs"],"tags":["rust","libtorch","dtype","panic"],"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"}