tracel-ai/burn · critical
Requires `autodiff` feature
Error message
Requires `autodiff` feature
What it means
The Dispatch backend (burn-dispatch) is compiled without the `autodiff` feature, so AutodiffBackend::backward is a stub that always panics with unimplemented!. The trait impl exists to satisfy the type system, but gradients are genuinely unavailable in this build.
Source
Thrown at crates/burn-dispatch/src/backend.rs:1027
true,
);
let output = Dispatch::float_mul(x.clone(), x.clone());
let gradients = <Dispatch as AutodiffBackend>::backward(output);
let gradient = <Dispatch as AutodiffBackend>::grad(&x, &gradients).unwrap();
assert_eq!(gradient.autodiff, DispatchAutodiffContext::Disabled);
assert!(!matches!(gradient.kind, DispatchTensorKind::Autodiff(_)));
}
}
// NOTE: placeholder for autodiff module requirements
#[cfg(not(feature = "autodiff"))]
impl AutodiffBackend for Dispatch {
type InnerBackend = Dispatch;
type Gradients = bool;
fn backward(_tensor: DispatchTensor) -> Self::Gradients {
unimplemented!("Requires `autodiff` feature")
}
fn grad(_tensor: &DispatchTensor, _grads: &Self::Gradients) -> Option<DispatchTensor> {
unimplemented!("Requires `autodiff` feature")
}
fn grad_remove(
_tensor: &DispatchTensor,
_grads: &mut Self::Gradients,
) -> Option<DispatchTensor> {
unimplemented!("Requires `autodiff` feature")
}
fn grad_replace(_tensor: &DispatchTensor, _grads: &mut Self::Gradients, _grad: DispatchTensor) {
unimplemented!("Requires `autodiff` feature")
}
fn inner(_tensor: DispatchTensor) -> DispatchTensor {View on GitHub (pinned to d16f7ba2ed)
Solutions
- Enable the feature: add `features = ["autodiff"]` to the burn-dispatch/burn dependency in Cargo.toml and rebuild.
- Use a backend that implements autodiff (e.g. Autodiff<Backend>) directly for training workloads.
- Restrict backward/grad calls to code paths compiled under cfg(feature = "autodiff").
- If only inference is needed, remove the training path so backward is never invoked.
Example fix
// before (Cargo.toml)
burn-dispatch = "0.x"
// after
burn-dispatch = { version = "0.x", features = ["autodiff"] } Defensive patterns
Strategy: validation
Validate before calling
#[cfg(not(feature = "autodiff"))]
compile_error!("training code requires the `autodiff` feature on burn-dispatch"); Prevention
- Enable `features = ["autodiff"]` whenever training code is compiled
- Never call backward in inference-only builds
- Add a compile_error!/cfg guard in binaries that need gradients
- Separate train and infer binaries with distinct feature sets
When it happens
Trigger: Calling t.backward() (or any training-loop code invoking AutodiffBackend::backward) on a DispatchTensor when the burn-dispatch crate was built without the autodiff feature.
Common situations: Running inference-oriented builds (default features trimmed) then executing training code; Cargo.toml missing `features = ["autodiff"]` on the burn/burn-dispatch dependency; release profiles that disable default features.
Related errors
- BURN_DEVICE=flex requested, but the 'flex' feature is not en
- BURN_DEVICE=ndarray requested, but the 'ndarray' feature is
- Operation not marked for autodiff.
- an autodiff float primitive must have an enabled autodiff co
- Cannot move between autodiff and non-autodiff instances.
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/3457c0db97d01ed3.
Report an issue: GitHub.