tracel-ai/burn · error

not implemented

Error message

not implemented

What it means

`q_from_data` in the `QTensorOps` trait implementation for the LibTorch backend is a stub that calls `unimplemented!()`. The tch backend does not implement creating a quantized tensor directly from raw data. Any attempt to build a `QuantizedTensor` from `TensorData` on this backend panics with 'not implemented'.

Source

Thrown at crates/burn-tch/src/ops/qtensor.rs:12

use burn_backend::{
    ExecutionError, FloatDType, IntDType, Shape, TensorData,
    ops::QTensorOps,
    quantization::{QuantScheme, QuantizationParametersPrimitive},
    tensor::{Device, FloatTensor, IntTensor, QuantizedTensor},
};

use crate::{LibTorch, LibTorchDevice};

impl QTensorOps<Self> for LibTorch {
    fn q_from_data(_data: TensorData, _device: &LibTorchDevice) -> QuantizedTensor<Self> {
        unimplemented!()
    }

    fn quantize(
        _tensor: FloatTensor<Self>,
        _scheme: &QuantScheme,
        _qparams: QuantizationParametersPrimitive<Self>,
    ) -> QuantizedTensor<Self> {
        unimplemented!()
    }

    fn quantize_dynamic(
        _tensor: FloatTensor<Self>,
        _scheme: &QuantScheme,
    ) -> QuantizedTensor<Self> {
        unimplemented!()
    }

    fn dequantize(_tensor: QuantizedTensor<Self>, _dtype: FloatDType) -> FloatTensor<Self> {

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Use `quantize` (if implemented elsewhere) or create a float tensor from data on tch instead of constructing a quantized tensor directly.
  2. Switch to a backend that implements q_from_data for quantized loading.
  3. Quantize at runtime via `quantize`/`quantize_dynamic` on a supported backend rather than passing pre-quantized data.
  4. Contribute an implementation: build a `at::Tensor` with `torch::quantize_per_tensor` from the data inside burn-tch.

Example fix

// before
let q = QTensorOps::q_from_data(data, &device); // panics on tch

// after
let f = Tensor::<LibTorch, 4>::from_data(data.convert::<f32>(), &device);
let q = QTensorOps::quantize(f.into_primitive(), &scheme, qparams);
Defensive patterns

Strategy: validation

Validate before calling

// Ensure you never construct quantized tensors on the tch backend:
fn ensure_not_tch_quantized<B: burn::tensor::backend::Backend>() {
    // Only call q_from_data on backends advertising QTensorOps support
    let _ = std::any::TypeId::of::<B>();
    // Prefer: cfg-gate quantized loading per backend feature
    #[cfg(feature = "tch")]
    compile_error!("q_from_data is unimplemented for tch; use float loading");
}

Try / catch

let q = std::panic::catch_unwind(|| QTensorOps::<B>::q_from_data(data.clone(), &device))
    .map_err(|_| "q_from_data unsupported on this backend")
    .ok()
    .unwrap_or_else(|| load_float_and_keep_float(data));

Prevention

When it happens

Trigger: Calling `QTensorOps::q_from_data` on the burn-tch backend, e.g. loading a pre-quantized checkpoint with `TensorData` and materializing it as a quantized tensor, or any burn API that internally constructs quantized tensors from raw bytes.

Common situations: Loading quantized model weights from file into a tch-backed burn model; deserializing a quantized record whose backend differs from the runtime backend; implementing quantization-aware deployment that expects q_from_data support.

Related errors


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