{"record":{"id":"49d6baa468a46099","repo":"tracel-ai/burn","slug":"unsupported-dtype-for-int-from-data-49d6ba","errorCode":null,"errorMessage":"Unsupported dtype for `int_from_data`: {:?}","messagePattern":"Unsupported dtype for `int_from_data`: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-tch/src/ops/int_tensor.rs","lineNumber":22,"sourceCode":"    BoolDType, Distribution, ExecutionError, FloatDType, IntDType, Scalar, Shape, TensorData,\n    TensorMetadata,\n    ops::{FloatTensorOps, IntTensorOps},\n    tensor::IntTensor,\n};\n\nuse crate::{IntoKind, LibTorch, LibTorchDevice, TchShape, TchTensor};\n\nuse super::TchOps;\n\nimpl IntTensorOps<Self> for LibTorch {\n    fn int_from_data(data: TensorData, device: &LibTorchDevice) -> TchTensor {\n        match data.dtype {\n            burn_backend::DType::I64 => TchTensor::from_data::<i64>(data, (*device).into()),\n            burn_backend::DType::I32 => TchTensor::from_data::<i32>(data, (*device).into()),\n            burn_backend::DType::I16 => TchTensor::from_data::<i16>(data, (*device).into()),\n            burn_backend::DType::I8 => TchTensor::from_data::<i8>(data, (*device).into()),\n            burn_backend::DType::U8 => TchTensor::from_data::<u8>(data, (*device).into()),\n            _ => unimplemented!(\"Unsupported dtype for `int_from_data`: {:?}\", data.dtype),\n        }\n    }\n\n    fn int_repeat_dim(tensor: TchTensor, dim: usize, times: usize) -> TchTensor {\n        TchOps::repeat_dim(tensor, dim, times)\n    }\n\n    async fn int_into_data(tensor: TchTensor) -> Result<TensorData, ExecutionError> {\n        let shape = tensor.shape();\n        let tensor = Self::int_reshape(tensor.clone(), Shape::new([shape.num_elements()]));\n        let values: Result<Vec<i64>, tch::TchError> = tensor.tensor.shallow_clone().try_into();\n        Ok(TensorData::new(values.unwrap(), shape))\n    }\n\n    fn int_to_device(tensor: TchTensor, device: &LibTorchDevice) -> TchTensor {\n        TchOps::to_device(tensor, device)\n    }\n","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-tch/src/ops/int_tensor.rs#L4-L40","documentation":"burn-tch's int_from_data supports only I64, I32, I16, I8, and U8 TensorData dtypes; anything else (floats, bool, unsigned 16/32/64, etc.) hits the unimplemented!() fallback and panics with the offending dtype in the message. Torch integer tensors simply cannot be built from those element types here.","triggerScenarios":"Creating an integer tensor on the LibTorch backend from TensorData whose dtype is not one of I64/I32/I16/I8/U8 — e.g. from_data::<i64> called with float data, or U64/F64 data routed to int_from_data.","commonSituations":"Loading integer tensors from serialized records saved with different unsigned/64-bit dtypes; interoperating with numpy or frameworks that use u64/f64 where the caller assumed automatic casting; Burn version upgrades adding dtypes (e.g. U64) that tch's conversion hasn't been extended to.","solutions":["Convert the TensorData to a supported dtype first: data.convert::<i64>() (or i32/i16/i8/u8)","Cast the tensor after creation: Tensor::from_data(float_data,...).int() / .to_dtype(DType::I64)","Check data.dtype against the supported set before calling","Upgrade or patch burn-tch if a newly added DType (e.g. U64) should be supported"],"exampleFix":"// before\nlet t = Tensor::<LibTorch, 1, Int>::from_data(u64_data, &device); // panics on U64\n\n// after\nlet t = Tensor::<LibTorch, 1, Int>::from_data(u64_data.convert::<i64>(), &device);","handlingStrategy":"validation","validationCode":"const SUPPORTED: [DType; 5] = [DType::I64, DType::I32, DType::I16, DType::I8, DType::U8];\nif !SUPPORTED.contains(&data.dtype) {\n    data = data.convert::<i64>();\n}\nlet t = Tensor::<LibTorch, D, Int>::from_data(data, &device);","typeGuard":"fn is_supported_int_dtype(dtype: burn_backend::DType) -> bool {\n    matches!(dtype, DType::I64 | DType::I32 | DType::I16 | DType::I8 | DType::U8)\n}","tryCatchPattern":null,"preventionTips":["Convert TensorData to i64 (or i32/i16/i8/u8) before int tensor creation on tch","Check dtypes when interoperating with numpy/other frameworks (u64/f64 are unsupported)","Re-check dtype assumptions after burn upgrades that add new DType variants"],"tags":["rust","burn","libtorch","tensor","dtype"],"backgroundTag":"unsupported-dtype-conversion","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"}