tracel-ai/burn · error
Unsupported dtype for `int_from_data`
Error message
Unsupported dtype for `int_from_data`
What it means
int_from_data converts host integer TensorData into a backend integer tensor. The supported set is I64/I32/I16/I8/U64/U32/U16/U8; any other dtype (floats, bool, quantized) cannot be loaded as an int tensor, so it panics with this unimplemented!.
Source
Thrown at crates/burn-cubecl/src/ops/int_tensor.rs:47
let dtype = dtype.into();
super::empty(shape, device, dtype)
}
async fn int_into_data(tensor: IntTensor<Self>) -> Result<TensorData, ExecutionError> {
super::into_data(tensor).await
}
fn int_from_data(data: TensorData, device: &Device<Self>) -> IntTensor<Self> {
match data.dtype {
DType::I64
| DType::I32
| DType::I16
| DType::I8
| DType::U64
| DType::U32
| DType::U16
| DType::U8 => super::from_data(data, device),
_ => unimplemented!("Unsupported dtype for `int_from_data`"),
}
}
fn int_to_device(tensor: IntTensor<Self>, device: &Device<Self>) -> IntTensor<Self> {
super::to_device(tensor, device)
}
fn int_reshape(tensor: IntTensor<Self>, shape: Shape) -> IntTensor<Self> {
super::reshape(tensor, shape)
}
fn int_slice(tensor: IntTensor<Self>, slices: &[Slice]) -> IntTensor<Self> {
// Check if all steps are 1
let all_steps_one = slices.iter().all(|info| info.step == 1);
if all_steps_one {
// Use optimized slice for step=1
let simple_ranges: Vec<Range<usize>> = slicesView on GitHub (pinned to d16f7ba2ed)
Solutions
- Cast the data to a supported integer dtype (e.g. i32/u32) before constructing the tensor
- Convert floats explicitly: build the float tensor then .int() / cast to the int dtype
- Verify TensorData.dtype matches the tensor type you construct (Tensor<.., Int>)
- Fix data-loading code so integer arrays are stored with integer dtypes
Example fix
// before let data = TensorData::from([1.0f32, 2.0]); let idx = Tensor::<Backend, 1>::from_data(data, &device); // int tensor from float data -> panic // after let idx = Tensor::<Backend, 1>::from_data(TensorData::from([1i32, 2]), &device);
Defensive patterns
Strategy: type-guard
Validate before calling
fn int_data_supported(data: &TensorData) -> bool {
matches!(data.dtype,
DType::I64 | DType::I32 | DType::I16 | DType::I8 |
DType::U64 | DType::U32 | DType::U16 | DType::U8)
} Type guard
fn is_int_dtype(dtype: DType) -> bool {
matches!(dtype, DType::I64 | DType::I32 | DType::I16 | DType::I8 |
DType::U64 | DType::U32 | DType::U16 | DType::U8)
} Try / catch
// Guard before creating int tensor:
if int_data_supported(&data) { Tensor::<B, D, Int>::from_data(data, &device) } else { /* cast data or build float tensor then .int() */ } Prevention
- Match TensorData.dtype to the tensor kind (Int vs Float)
- Cast floats to ints explicitly before building index tensors
- Validate dtypes at data-loading boundaries
When it happens
Trigger: Calling int_from_data with TensorData whose dtype is not one of the eight integer dtypes — e.g. passing float data into an int tensor constructor, or bool/quantized dtype data.
Common situations: Type confusion when building TensorData manually; passing float tensors where index/int tensors are expected; data loaded from files with a mislabeled dtype.
Related errors
- Unsupported dtype for `bool_from_data` {:?}
- ctc_loss_backward: 2 * max_target_len + 1 = {} exceeds the k
- Unsupported dtype for `bool_from_data` {other:?}
- Scalar not supported for {dtype:?}
- ctc_loss: 2 * max_target_len + 1 = {} exceeds the kernel's s
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/8bc1c2b63025c310.
Report an issue: GitHub.