tracel-ai/burn · error

Unsupported dtype for `float_from_data`

Error message

Unsupported dtype for `float_from_data`

What it means

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.

Source

Thrown at crates/burn-cubecl/src/ops/tensor.rs:30

use burn_backend::tensor::{BoolTensor, Device, FloatTensor, IntTensor};
use burn_backend::{DType, ElementConversion, FloatDType, Slice};
use burn_backend::{Distribution, Shape, TensorData, ops::FloatTensorOps};
use burn_backend::{ExecutionError, Scalar, get_device_settings};
use burn_std::{BoolDType, IntDType};
use cubecl::prelude::*;
use cubek::reduce::components::instructions::ReduceOperationConfig;
use std::ops::Range;

impl FloatTensorOps<Self> for CubeBackend {
    #[cfg_attr(feature = "tracing", tracing::instrument(
        level="trace",
        skip(data),
        fields(?data.shape, ?data.dtype)
    ))]
    fn float_from_data(data: TensorData, device: &Device<Self>) -> FloatTensor<Self> {
        match data.dtype {
            DType::F64 | DType::F32 | DType::F16 | DType::BF16 => super::from_data(data, device),
            _ => unimplemented!("Unsupported dtype for `float_from_data`"),
        }
    }

    fn float_random(
        shape: Shape,
        distribution: Distribution,
        device: &Device<Self>,
        dtype: FloatDType,
    ) -> FloatTensor<Self> {
        let dtype = dtype.into();
        match distribution {
            Distribution::Default => random_uniform(shape, device, 0., 1., dtype),
            Distribution::Uniform(low, high) => {
                random_uniform(shape, device, low.elem(), high.elem(), dtype)
            }
            Distribution::Bernoulli(prob) => random_bernoulli(shape, device, prob as f32, dtype),
            Distribution::Normal(mean, std) => {
                random_normal(shape, device, mean.elem(), std.elem(), dtype)

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Convert the TensorData to a float dtype before calling from_data, e.g. data.convert::<f32>() or reinterpret/reshape the buffer correctly.
  2. Ensure the data source (checkpoint, dataset loader) produces the expected F32/F16/BF16 dtype.
  3. Use the int/bool tensor constructors (int_from_data etc.) if the data genuinely is an integer tensor.
  4. Check TensorData::dtype before constructing and log/branch on mismatch.

Example fix

// before
let t = Tensor::<Backend, 2>::from_data(int_data, &device); // dtype I32 -> panics
// after
let f32_data = int_data.convert::<f32>();
let t = Tensor::<Backend, 2>::from_data(f32_data, &device);
Defensive patterns

Strategy: validation

Validate before calling

use burn_tensor::DType;
fn assert_float_dtype(data: &TensorData) {
    assert!(
        matches!(data.dtype, DType::F64 | DType::F32 | DType::F16 | DType::BF16),
        "float_from_data requires a float dtype, got {:?}",
        data.dtype
    );
}

Type guard

fn is_float_data(data: &TensorData) -> bool {
    matches!(data.dtype, DType::F64 | DType::F32 | DType::F16 | DType::BF16)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05). Data as JSON: /api/errors/21aeec014c672c3b. Report an issue: GitHub.