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
- Use `quantize` (if implemented elsewhere) or create a float tensor from data on tch instead of constructing a quantized tensor directly.
- Switch to a backend that implements q_from_data for quantized loading.
- Quantize at runtime via `quantize`/`quantize_dynamic` on a supported backend rather than passing pre-quantized data.
- 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
- Treat burn-tch as float-only: never load or build QuantizedTensor values on it.
- Serialize models as float records and quantize on a backend that supports it.
- Feature-gate quantization code paths behind non-tch backend features.
- Add CI tests that construct every tensor type your loader produces on every target backend.
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
- todo!("Quantization not supported yet")
- unimplemented!()
- Can't format yet
- Not yet implemented for iteration
- lookup quantization is not supported for iteration
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/e3c24ad0d5432712.
Report an issue: GitHub.