tracel-ai/burn · error

Can't differentiate linear_bias_backward.

Error message

Can't differentiate linear_bias_backward.

What it means

Dead-code sentinel: `linear_bias_backward` exists only to satisfy the backward-op trait, but the bias gradient is computed as part of `linear_backward` (a reduction over x's gradient). Reaching this panic means the dispatcher attempted a per-parameter backward that the linear op never registers as runnable.

Source

Thrown at crates/burn-autodiff/src/ops/module.rs:194

        }
    }

    fn linear_x_backward(
        _weight: AutodiffTensor<B>,
        _output_grad: AutodiffTensor<B>,
    ) -> AutodiffTensor<B> {
        panic!("Can't differentiate linear_x_backward.");
    }

    fn linear_weight_backward(
        _x: AutodiffTensor<B>,
        _output_grad: AutodiffTensor<B>,
    ) -> AutodiffTensor<B> {
        panic!("Can't differentiate linear_weight_backward.");
    }

    fn linear_bias_backward(_output_grad: AutodiffTensor<B>) -> AutodiffTensor<B> {
        panic!("Can't differentiate linear_bias_backward.");
    }

    fn conv1d(
        x: AutodiffTensor<B>,
        weight: AutodiffTensor<B>,
        bias: Option<AutodiffTensor<B>>,
        options: ConvOptions<1>,
    ) -> AutodiffTensor<B> {
        #[derive(Debug)]
        struct Conv1DWithBias;
        #[derive(Debug)]
        struct Conv1DNoBias;

        impl<B: Backend> Backward<B, 3> for Conv1DWithBias {
            type State = (NodeId, NodeId, NodeId, ConvOptions<1>);

            fn backward(
                self,

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Dequantize on the concrete backend that produced the quantized tensor, before values re-enter routed code.
  2. Keep quantized tensors on a native quantization-capable backend end-to-end.
  3. Pre-convert weights to float and route only float ops.

Example fix

// before
let f = BackendRouter::<R>::dequantize(q_tensor, FloatDType::F32); // panics
// after
let f = ConcreteBackend::dequantize(q_tensor, FloatDType::F32);
Defensive patterns

Strategy: fallback

Validate before calling

fn ensure_dequant_backend<B: Backend>() -> Result<(), &'static str> {
    Err("dequantize is not implemented for BackendRouter; dequantize on the producing backend")
}

Type guard

fn is_quantized<B: Backend>(t: &QuantizedTensor<B>) -> bool { true } // all quantized tensors hit the stub on router

Try / catch

let f = std::panic::catch_unwind(|| q_tensor.clone().dequantize(FloatDType::F32))
    .map_err(|_| anyhow::anyhow!("router dequantize is a stub; use the concrete backend"))?;

Prevention

When it happens

Trigger: Calling dequantize (or Tensor::dequantize) on a QuantizedTensor whose backend is BackendRouter — e.g. materializing float output from a quantized computation under the router.

Common situations: End of a quantized inference pipeline needing float results; mixing quantized and float ops via the router; export paths that dequantize weights.

Related errors


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