{"record":{"id":"65ba1f68aeddaba9","repo":"tracel-ai/burn","slug":"autodiff-context-requires-the-autodiff-feature-65ba1f","errorCode":null,"errorMessage":"autodiff context requires the `autodiff` feature","messagePattern":"autodiff context requires the `autodiff` feature","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-dispatch/src/ops/qtensor.rs","lineNumber":41,"sourceCode":"                    kind: DispatchTensorKind::$Backend(BackendTensor::Float(output)),\n                    autodiff: DispatchAutodiffContext::Disabled,\n                }),\n                #[cfg(feature = \"autodiff\")]\n                DispatchAutodiffContext::Enabled(strategy) => {\n                    with_autodiff_backend!($Backend, strategy, |AD| {\n                        TensorPrimitive::Float(DispatchTensor {\n                            kind: DispatchTensorKind::Autodiff(alloc::boxed::Box::new(\n                                DispatchTensorKind::$Backend(BackendTensor::Autodiff(\n                                    <AD as burn_backend::AutodiffBackend>::from_inner(output),\n                                )),\n                            )),\n                            autodiff: DispatchAutodiffContext::Enabled(strategy),\n                        })\n                    })\n                }\n                #[cfg(not(feature = \"autodiff\"))]\n                DispatchAutodiffContext::Enabled(_) => {\n                    panic!(\"autodiff context requires the `autodiff` feature\")\n                }\n            },\n        }\n    }};\n}\n\n#[cfg(feature = \"autodiff\")]\nmacro_rules! wrap_q_matmul_autodiff {\n    ($Backend:ident, $output:expr, $strategy:expr) => {{\n        match $output {\n            TensorPrimitive::QFloat(output) => TensorPrimitive::QFloat(DispatchTensor {\n                kind: DispatchTensorKind::$Backend(BackendTensor::Quantized(output)),\n                autodiff: DispatchAutodiffContext::Enabled($strategy),\n            }),\n            TensorPrimitive::Float(output) => TensorPrimitive::Float(DispatchTensor {\n                kind: DispatchTensorKind::Autodiff(alloc::boxed::Box::new(\n                    DispatchTensorKind::$Backend(BackendTensor::Autodiff(output)),\n                )),","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-dispatch/src/ops/qtensor.rs#L23-L59","documentation":"In the Qtensor dispatch macro, a `DispatchAutodiffContext::Enabled` was provided while the `autodiff` cargo feature is disabled. Since the compiled code cannot handle autodiff contexts without the feature, it panics that the autodiff context requires the `autodiff` feature.","triggerScenarios":"Calling a quantized tensor dispatch API with an Enabled autodiff context in a build without `--features autodiff` (the `#[cfg(not(feature = \"autodiff\")]` arm).","commonSituations":"Library consumers enabling quantization features but not `autodiff`; calling through a generic wrapper that always constructs an Enabled context.","solutions":["Rebuild with the `autodiff` feature enabled (e.g. `cargo build --features autodiff`)","Or pass `DispatchAutodiffContext::Disabled` when autodiff is not needed","Avoid routing autodiff contexts into quantized-tensor code paths in inference-only builds"],"exampleFix":"// before\ncargo build --features qtensor\nDispatchAutodiffContext::Enabled(strategy) // panics\n// after\ncargo build --features qtensor,autodiff\n// or pass DispatchAutodiffContext::Disabled","handlingStrategy":"validation","validationCode":"#[cfg(not(feature = \"autodiff\"))]\ncompile_error!(\"this crate requires the `autodiff` feature when autodiff contexts are used\");\n// or at runtime: only construct Enabled contexts when cfg(feature = \"autodiff\")","typeGuard":"fn allows_ad_ctx() -> bool { cfg!(feature = \"autodiff\") }","tryCatchPattern":null,"preventionTips":["Enable the `autodiff` feature when training with quantized tensors","Gate context construction on cfg!(feature = \"autodiff\")","Keep feature sets consistent across workspace crates (workspace dependency features)"],"tags":["rust","autodiff","feature-flags","qtensor","panic","burn"],"backgroundTag":"missing-feature-flag","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}