tracel-ai/burn · error

todo!("Quantization not supported yet")

Error message

todo!("Quantization not supported yet")

What it means

In burn-dispatch's transaction unwrapping macro, when a transaction containing quantized tensors (`read_qfloats`) is dispatched to a backend, the quantized tensors are not converted — each element is mapped to `todo!("Quantization not supported yet")`, panicking. Transactions (batched read/write ops) currently support floats, ints, and bools only.

Source

Thrown at crates/burn-dispatch/src/macros.rs:443

macro_rules! transaction_op_arms {
    ($tx:ident, $first:expr; $([$Backend:ident, $cfg:meta]),*) => {{
        match &$first.kind {
            // Autodiff arm first
            #[cfg(feature = "autodiff")]
            $crate::DispatchTensorKind::Autodiff(inner) => {
                // Recursively dispatch on inner
                match **inner {
                    $(
                    #[cfg($cfg)]
                    $crate::DispatchTensorKind::$Backend(_) => {
                        type B = $crate::backends::$Backend;

                        // Unwrap vec
                        let floats = unwrap_vec!(@autodiff $Backend, $tx.read_floats, autodiff_inner);
                        let ints = unwrap_vec!($Backend, $tx.read_ints, int);
                        let bools = unwrap_vec!($Backend, $tx.read_bools, bool);
                        // Not supported
                        let qfloats = $tx.read_qfloats.into_iter().map(|_t| todo!("Quantization not supported yet")).collect();

                        B::tr_execute(TransactionPrimitive::new(floats, qfloats, ints, bools)).await
                    }
                )*
                    $crate::DispatchTensorKind::Autodiff(..) => unreachable!("Autodiff should not wrap an autodiff tensor.")
                }
            },

            $(
                #[cfg($cfg)]
                $crate::DispatchTensorKind::$Backend(_) => {
                    type B = $crate::backends::$Backend;

                    // Unwrap vec
                    let floats = unwrap_vec!($Backend, $tx.read_floats, float);
                    let ints = unwrap_vec!($Backend, $tx.read_ints, int);
                    let bools = unwrap_vec!($Backend, $tx.read_bools, bool);
                    // Not supported

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Avoid transactions for quantized tensors: execute the quantized op standalone instead of within a batched transaction.
  2. Dequantize to float before the ops that get transactionalized, and quantize afterwards.
  3. Use a backend/feature path with quantization support so quantized primitives are unwrapped correctly.
  4. Upgrade burn — this is a known gap that may be implemented in newer versions.

Example fix

// before
let out = TransactionPrimitive::new(floats, vec![q_tensor], ints, bools); // panics in dispatch
// after
let f = q_tensor.dequantize();
let out = TransactionPrimitive::new(floats_with_f, vec![], ints, bools); // floats only
Defensive patterns

Strategy: validation

Validate before calling

fn transaction_supported(tx: &Transaction) -> bool {
    tx.read_qfloats.is_empty() && tx.write_qfloats.is_empty()
}

Type guard

fn has_qfloats(tx: &Transaction) -> bool { !tx.read_qfloats.is_empty() || !tx.write_qfloats.is_empty() }

Prevention

When it happens

Trigger: Executing a transaction (e.g. `tr_execute` / `execute_async` through the dispatch layer, as in the autodiff transaction op at crates/burn-autodiff/src/ops/transaction.rs:18) where the transaction's `read_qfloats` vec contains at least one quantized tensor.

Common situations: Running quantized inference through the autodiff/dispatch stack where ops get batched into a transaction; mixing quantized and float ops so the quantized tensor ends up in a multi-op transaction; calling backends that route through dispatch macros without quantization support.

Related errors


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