tracel-ai/burn · error

lookup quantization does not travel as a QFloat tensor

Error message

lookup quantization does not travel as a QFloat tensor

What it means

Quantized tensors with a lookup-table QuantScheme (QuantMode::Lookup) cannot be constructed from raw TensorData because lookup quantization is not representable/travelable as a QFloat tensor in the CubeCl backend. q_from_data only supports the other quantization schemes (per-tensor/block data packed into u32 with quantization parameters appended). Hitting this means you tried to build a lookup-quantized tensor via from_data/q_from_data.

Source

Thrown at crates/burn-cubecl/src/ops/qtensor.rs:243

                        QuantValue::Q8F
                        | QuantValue::Q8S
                        | QuantValue::Q4F
                        | QuantValue::Q4S
                        | QuantValue::Q2F
                        | QuantValue::Q2S
                        | QuantValue::E4M3
                        | QuantValue::E5M2
                        | QuantValue::E2M1,
                    ..
                } => {
                    // TensorData quantized representation is the same, with multiple quantized values
                    // packed into u32 and quantization parameters appended to the bytes
                    new_qtensor_optimized(data.bytes, data.shape.clone(), scheme, device)
                }
                QuantScheme {
                    mode: QuantMode::Lookup,
                    ..
                } => unimplemented!("lookup quantization does not travel as a QFloat tensor"),
            },
            _ => panic!(
                "Invalid dtype (expected DType::QFloat, got {:?})",
                data.dtype
            ),
        }
    }

    // TODO: quantize_dynamic (we can compute min-max on the fly and scale, especially when not per-tensor)

    fn quantize(
        tensor: FloatTensor<Self>,
        scheme: &QuantScheme,
        qparams: QuantizationParametersPrimitive<Self>,
    ) -> QuantizedTensor<Self> {
        // The kernel reads this at the scheme's scale dtype, not the tensor's actual dtype.
        if let Some(global) = &qparams.global {
            assert_eq!(

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Use a supported QuantScheme mode (e.g. per-block affine/symmetric int8) when constructing quantized tensors from data.
  2. Keep lookup-quantized weights in a format that avoids the QFloat data path, or construct them via the dedicated lookup-quantization init API if available.
  3. Quantize on CPU or with a backend that supports lookup-mode construction, then transfer if the target backend supports it.
  4. File/check a burn issue for QuantMode::Lookup support in q_from_data on CubeCl.

Example fix

// before
let scheme = QuantScheme::default().with_mode(QuantMode::Lookup);
let q = QTensorPrimitive::from_data(data, scheme, &device); // panics
// after
let scheme = QuantScheme::default().with_mode(QuantMode::PerBlockAffine);
let q = QTensorPrimitive::from_data(data, scheme, &device);
Defensive patterns

Strategy: validation

Validate before calling

match scheme.mode() {
    QuantMode::Lookup => panic!("lookup quantization cannot be built via q_from_data; use another scheme"),
    _ => { /* safe to construct */ }
}

Type guard

fn is_data_constructible_scheme(scheme: &QuantScheme) -> bool {
    scheme.mode() != QuantMode::Lookup
}

Prevention

When it happens

Trigger: Calling q_from_data (directly or via QuantizedTensor::from_data / quantization APIs) on a CubeCl backend with TensorData whose dtype is DType::QFloat and whose QuantScheme has mode: QuantMode::Lookup.

Common situations: Loading lookup-quantized model weights from disk; configuring a quantization scheme to LookupTable and then instantiating tensors from data on GPU; version changes where lookup quantization support was added partially (inference only, no data-path construction).

Related errors


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