{"record":{"id":"3457c0db97d01ed3","repo":"tracel-ai/burn","slug":"requires-autodiff-feature","errorCode":null,"errorMessage":"Requires `autodiff` feature","messagePattern":"Requires `autodiff` feature","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/burn-dispatch/src/backend.rs","lineNumber":1027,"sourceCode":"            true,\n        );\n        let output = Dispatch::float_mul(x.clone(), x.clone());\n        let gradients = <Dispatch as AutodiffBackend>::backward(output);\n        let gradient = <Dispatch as AutodiffBackend>::grad(&x, &gradients).unwrap();\n        assert_eq!(gradient.autodiff, DispatchAutodiffContext::Disabled);\n        assert!(!matches!(gradient.kind, DispatchTensorKind::Autodiff(_)));\n    }\n}\n\n// NOTE: placeholder for autodiff module requirements\n#[cfg(not(feature = \"autodiff\"))]\nimpl AutodiffBackend for Dispatch {\n    type InnerBackend = Dispatch;\n\n    type Gradients = bool;\n\n    fn backward(_tensor: DispatchTensor) -> Self::Gradients {\n        unimplemented!(\"Requires `autodiff` feature\")\n    }\n\n    fn grad(_tensor: &DispatchTensor, _grads: &Self::Gradients) -> Option<DispatchTensor> {\n        unimplemented!(\"Requires `autodiff` feature\")\n    }\n\n    fn grad_remove(\n        _tensor: &DispatchTensor,\n        _grads: &mut Self::Gradients,\n    ) -> Option<DispatchTensor> {\n        unimplemented!(\"Requires `autodiff` feature\")\n    }\n\n    fn grad_replace(_tensor: &DispatchTensor, _grads: &mut Self::Gradients, _grad: DispatchTensor) {\n        unimplemented!(\"Requires `autodiff` feature\")\n    }\n\n    fn inner(_tensor: DispatchTensor) -> DispatchTensor {","sourceCodeStart":1009,"sourceCodeEnd":1045,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-dispatch/src/backend.rs#L1009-L1045","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (Cargo.toml)\nburn-dispatch = \"0.x\"\n// after\nburn-dispatch = { version = \"0.x\", features = [\"autodiff\"] }","handlingStrategy":"validation","validationCode":"#[cfg(not(feature = \"autodiff\"))]\ncompile_error!(\"training code requires the `autodiff` feature on burn-dispatch\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["rust","burn","autodiff","feature-flag","gradients"],"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"}