{"record":{"id":"12d52533157584bc","repo":"tracel-ai/burn","slug":"autodiff-float-input-reached-concrete-dispatch","errorCode":null,"errorMessage":"autodiff float input reached concrete dispatch","messagePattern":"autodiff float input reached concrete dispatch","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-backend-extension/src/routing.rs","lineNumber":788,"sourceCode":"                        match tensor {\n                            #backend_tensor::Autodiff(tensor) => #backend_tensor::Float(tensor),\n                            _ => panic!(\"only float tensors may use an autodiff primitive\"),\n                        }\n                    }\n                    #dispatch_kind::#backend(tensor) => match tensor {\n                        #backend_tensor::Float(tensor) => {\n                            let #context::Disabled = __input_context else {\n                                panic!(\"an enabled float tensor must use an autodiff primitive\")\n                            };\n                            #backend_tensor::Float(\n                                <#backend_alias as #autodiff_trait>::from_inner(tensor)\n                            )\n                        }\n                        #backend_tensor::Int(tensor) => #backend_tensor::Int(tensor),\n                        #backend_tensor::Bool(tensor) => #backend_tensor::Bool(tensor),\n                        #backend_tensor::Quantized(tensor) => #backend_tensor::Quantized(tensor),\n                        #backend_tensor::Autodiff(_) => {\n                            panic!(\"autodiff float input reached concrete dispatch\")\n                        }\n                    },\n                    #[allow(unreachable_patterns)]\n                    _ => #mismatch,\n                }\n            });\n        }\n    } else {\n        let target = ir::with_backend(ty, quote!(#backend_root::#backend));\n        quote! {\n            let #name = <#target as #extension_trait<#backend_root::#backend>>::map_from_dispatch(\n                #name,\n                |__tensor| {\n                    match __tensor.kind {\n                        #dispatch_kind::#backend(tensor) => tensor,\n                        #[allow(unreachable_patterns)]\n                        _ => #mismatch,\n                    }","sourceCodeStart":770,"sourceCodeEnd":806,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-backend-extension/src/routing.rs#L770-L806","documentation":"Generated as the `invalid_autodiff_float` arm: when an operation is routed to the concrete (non-autodiff) backend, an input arriving under `DispatchTensorKind::Autodiff` for a float kind is rejected. An autodiff (gradient-tracking) float tensor cannot be consumed by a concrete backend primitive, so the codegen panics with this message to prevent silently dropping gradient tracking.","triggerScenarios":"Calling a routed op compiled for the concrete backend (no autodiff lifting) with a tensor wrapped in the Autodiff dispatch kind — e.g. mixing differentiating and non-differentiating paths, or calling a concrete-only extension op inside a backward pass.","commonSituations":"Calling inference-only routed ops with training tensors; routing signatures missing the autodiff parameter so the concrete variant was generated; handing tensors out of a `grad` closure into non-autodiff code paths.","solutions":["Detach/convert the autodiff tensor to its inner concrete float tensor before the call (e.g. via the non-autodiff repr)","Route the call to the autodiff variant of the op so Autodiff inputs are accepted","Restructure so differentiating tensors never leave the tracked region into concrete-only ops"],"exampleFix":"// before\nlet y = concrete_only_op::<B>(ad_tensor); // panics: autodiff float input reached concrete dispatch\n// after\nlet inner = ad_tensor.inner(); // strip autodiff wrapper\nlet y = concrete_only_op::<B>(inner);","handlingStrategy":"type-guard","validationCode":"if let DispatchTensorKind::Autodiff(_) = t.kind { /* not safe for concrete-only ops */ detach_or_reroute(); }","typeGuard":"fn is_concrete_dispatch(t: &DispatchTensor) -> bool { !matches!(&t.kind, DispatchTensorKind::Autodiff(_)) }","tryCatchPattern":null,"preventionTips":["Keep differentiating tensors inside grad-tracked call paths","Detach autodiff tensors before handing them to inference/concrete-only ops","Ensure routed signatures include autodiff variants when tensors may be tracking gradients"],"tags":["burn","autodiff","tensor-kind"],"backgroundTag":"autodiff-context-mismatch","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"}