{"record":{"id":"21aeec014c672c3b","repo":"tracel-ai/burn","slug":"unsupported-dtype-for-float-from-data","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-cubecl/src/ops/tensor.rs","lineNumber":30,"sourceCode":"use burn_backend::tensor::{BoolTensor, Device, FloatTensor, IntTensor};\nuse burn_backend::{DType, ElementConversion, FloatDType, Slice};\nuse burn_backend::{Distribution, Shape, TensorData, ops::FloatTensorOps};\nuse burn_backend::{ExecutionError, Scalar, get_device_settings};\nuse burn_std::{BoolDType, IntDType};\nuse cubecl::prelude::*;\nuse cubek::reduce::components::instructions::ReduceOperationConfig;\nuse std::ops::Range;\n\nimpl FloatTensorOps<Self> for CubeBackend {\n    #[cfg_attr(feature = \"tracing\", tracing::instrument(\n        level=\"trace\",\n        skip(data),\n        fields(?data.shape, ?data.dtype)\n    ))]\n    fn float_from_data(data: TensorData, device: &Device<Self>) -> FloatTensor<Self> {\n        match data.dtype {\n            DType::F64 | DType::F32 | DType::F16 | DType::BF16 => super::from_data(data, device),\n            _ => unimplemented!(\"Unsupported dtype for `float_from_data`\"),\n        }\n    }\n\n    fn float_random(\n        shape: Shape,\n        distribution: Distribution,\n        device: &Device<Self>,\n        dtype: FloatDType,\n    ) -> FloatTensor<Self> {\n        let dtype = dtype.into();\n        match distribution {\n            Distribution::Default => random_uniform(shape, device, 0., 1., dtype),\n            Distribution::Uniform(low, high) => {\n                random_uniform(shape, device, low.elem(), high.elem(), dtype)\n            }\n            Distribution::Bernoulli(prob) => random_bernoulli(shape, device, prob as f32, dtype),\n            Distribution::Normal(mean, std) => {\n                random_normal(shape, device, mean.elem(), std.elem(), dtype)","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-cubecl/src/ops/tensor.rs#L12-L48","documentation":"float_from_data on the CubeCl backend only accepts float dtypes: F64, F32, F16, and BF16. Any other dtype (int, bool, or quantized QFloat) passed to float_from_data panics with this unimplemented! message. It guards against constructing a float tensor from non-float data.","triggerScenarios":"Calling float_from_data (or Tensor::<B,..>::from_data / TensorData conversion resolved to the float path) with TensorData whose dtype is not one of F64/F32/F16/BF16, e.g. I64 or QFloat data.","commonSituations":"Loading data from a file/serialization whose dtype metadata is integer but treating it as a float tensor; passing quantized TensorData to the float constructor; dtype mismatches after exporting from other frameworks.","solutions":["Convert the TensorData to a float dtype before calling from_data, e.g. data.convert::<f32>() or reinterpret/reshape the buffer correctly.","Ensure the data source (checkpoint, dataset loader) produces the expected F32/F16/BF16 dtype.","Use the int/bool tensor constructors (int_from_data etc.) if the data genuinely is an integer tensor.","Check TensorData::dtype before constructing and log/branch on mismatch."],"exampleFix":"// before\nlet t = Tensor::<Backend, 2>::from_data(int_data, &device); // dtype I32 -> panics\n// after\nlet f32_data = int_data.convert::<f32>();\nlet t = Tensor::<Backend, 2>::from_data(f32_data, &device);","handlingStrategy":"validation","validationCode":"use burn_tensor::DType;\nfn assert_float_dtype(data: &TensorData) {\n    assert!(\n        matches!(data.dtype, DType::F64 | DType::F32 | DType::F16 | DType::BF16),\n        \"float_from_data requires a float dtype, got {:?}\",\n        data.dtype\n    );\n}","typeGuard":"fn is_float_data(data: &TensorData) -> bool {\n    matches!(data.dtype, DType::F64 | DType::F32 | DType::F16 | DType::BF16)\n}","tryCatchPattern":null,"preventionTips":["Check TensorData::dtype before every from_data call","Convert integer/other data with data.convert::<f32>() before building float tensors","Normalize dtypes at load time (dataset/checkpoint loaders)","Use int_from_data/bool constructors for non-float data"],"tags":["rust","burn","cubecl","dtype","from-data"],"backgroundTag":"dtype-mismatch","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"}