tracel-ai/burn · critical

autodiff context requires the `autodiff` feature

Error message

autodiff context requires the `autodiff` feature

What it means

Generated routing code matches on whether the `autodiff` feature is compiled in. When an autodiff-enabled execution branch is requested but the crate was built without the `autodiff` feature, the `false` arm of the feature check panics with this message. It is a compile-time configuration error surfacing as a runtime panic.

Source

Thrown at crates/burn-backend-extension/src/routing.rs:1068

                #concrete_enabled
            }
        }
    };
    let enabled = match float_inputs {
        FloatInputPresence::Always => autodiff_enabled,
        FloatInputPresence::Never => concrete_enabled_route,
        FloatInputPresence::Runtime(expression) => {
            let concrete_runtime = if operation.output.contains_float() {
                quote! {
                    #autodiff_attr
                    false => {
                        type #backend_alias = #backend_root::#backend;
                        #concrete_inputs
                        #concrete_invoke
                        #concrete_enabled_output
                    }
                    #no_autodiff_attr
                    false => panic!("autodiff context requires the `autodiff` feature"),
                }
            } else {
                quote! {
                    false => {
                        type #backend_alias = #backend_root::#backend;
                        #concrete_inputs
                        #concrete_invoke
                        #concrete_enabled
                    }
                }
            };
            quote! {
                #context::Enabled(__strategy) => match #expression {
                    #autodiff_attr
                    true => #autodiff_call,
                    #no_autodiff_attr
                    true => panic!("autodiff context requires the `autodiff` feature"),
                    #concrete_runtime

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Add the `autodiff` feature to the dependency: `burn-backend-extension = { version = "...", features = ["autodiff"] }` (or enable it on the umbrella `burn` crate).
  2. Verify with `cargo tree -e features` that the feature is unified into the final build.
  3. If autodiff is genuinely unneeded, stop selecting the autodiff branch (use the inference path) instead of enabling the feature.

Example fix

// before (Cargo.toml)
[dependencies]
burn = { version = "0.18", features = ["wgpu"] }

// after
[dependencies]
burn = { version = "0.18", features = ["wgpu", "autodiff"] }
Defensive patterns

Strategy: validation

Validate before calling

// build.rs or CI check
// fail fast if the feature is missing when autodiff code is compiled:
#[cfg(not(feature = "autodiff"))]
compile_error!("autodiff feature required");

Prevention

When it happens

Trigger: Enabling autodiff context at runtime (Enabled arm) while the workspace crate `burn-backend-extension` (or the consuming crate) was built without `features = ["autodiff"]` — the `#no_autodiff_attr` arm's `true => panic!(...)` fires.

Common situations: Dependency declared without feature: `burn = { version, features = ["wgpu"] }` missing `"autodiff"`; feature unification surprises in a workspace; enabling autodiff via config file that the build ignores; CI building with `--no-default-features`.

Related errors


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