{"record":{"id":"b7966a1e18b0bd41","repo":"tracel-ai/burn","slug":"can-t-differentiate-linear-x-backward","errorCode":null,"errorMessage":"Can't differentiate linear_x_backward.","messagePattern":"Can't differentiate linear_x_backward\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-autodiff/src/ops/module.rs","lineNumber":183,"sourceCode":"                    let x_state = weight_tracked.then(|| prep.checkpoint(&x));\n                    let weight_state = x_tracked.then(|| prep.checkpoint(&weight));\n                    prep.finish(\n                        (x_state, weight_state),\n                        B::linear(x.primitive, weight.primitive, None),\n                    )\n                }\n                OpsKind::UnTracked(prep) => {\n                    prep.finish(B::linear(x.primitive, weight.primitive, None))\n                }\n            },\n        }\n    }\n\n    fn linear_x_backward(\n        _weight: AutodiffTensor<B>,\n        _output_grad: AutodiffTensor<B>,\n    ) -> AutodiffTensor<B> {\n        panic!(\"Can't differentiate linear_x_backward.\");\n    }\n\n    fn linear_weight_backward(\n        _x: AutodiffTensor<B>,\n        _output_grad: AutodiffTensor<B>,\n    ) -> AutodiffTensor<B> {\n        panic!(\"Can't differentiate linear_weight_backward.\");\n    }\n\n    fn linear_bias_backward(_output_grad: AutodiffTensor<B>) -> AutodiffTensor<B> {\n        panic!(\"Can't differentiate linear_bias_backward.\");\n    }\n\n    fn conv1d(\n        x: AutodiffTensor<B>,\n        weight: AutodiffTensor<B>,\n        bias: Option<AutodiffTensor<B>>,\n        options: ConvOptions<1>,","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-autodiff/src/ops/module.rs#L165-L201","documentation":"Dead-code sentinel: `linear_x_backward` is an intentionally unreachable backward op. Burn's linear layer never computes the gradient of its input via this backward-only helper because x's gradient is fused into `linear_backward`; reaching this panic indicates the autodiff graph dispatched a backward step that the module op registry declares impossible.","triggerScenarios":"Calling Tensor::quantize / quantize() on a tensor whose backend is BackendRouter — e.g. quantizing a model on a routed backend.","commonSituations":"Post-training quantization of models running through burn-router; generic Backend code where the router is selected; version mismatches where quantization isn't yet routed.","solutions":["Quantize on the concrete inner backend before routing (quantize weights at build time, route only inference ops that are supported).","Use a backend that implements QTensorOps directly (e.g. the target compute backend) for the quantization step.","Check burn's issue tracker/CHANGELOG for router quantization routing support."],"exampleFix":"// before\nlet q = tensor_quantize_scheme(&router_backend_tensor, &scheme); // panics\n// after\nlet q = tensor_quantize_scheme(&concrete_backend_tensor, &scheme);","handlingStrategy":"fallback","validationCode":"fn ensure_quantize_target<B: Backend>(b: &B) -> Result<(), &'static str> {\n    // BackendRouter::quantize is unimplemented\n    Err(\"quantize() is not implemented for BackendRouter; use a concrete backend\")\n}","typeGuard":"fn is_router_backend_marker<B: Backend>() -> bool {\n    std::any::TypeName::<B>().contains(\"BackendRouter\")\n}","tryCatchPattern":"let q = std::panic::catch_unwind(|| tensor.clone().quantize(&scheme, qparams))\n    .map_err(|_| anyhow::anyhow!(\"router quantize is a stub; switch backends\"))?;","preventionTips":["Quantize weights on the concrete backend before routing inference.","Avoid generic quantization code paths that can resolve to BackendRouter.","Check burn CHANGELOG for router quantization support before upgrading.","Gate quantization features behind a concrete-backend constraint."],"tags":["rust","burn-router","quantization","unimplemented"],"backgroundTag":"unimplemented-api-stub","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"}