{"record":{"id":"2a97714cb7128eee","repo":"tracel-ai/burn","slug":"trying-to-consume-the-gradients-for-an-untracked-t","errorCode":null,"errorMessage":"Trying to consume the gradients for an untracked tensor","messagePattern":"Trying to consume the gradients for an untracked tensor","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-autodiff/src/grads.rs","lineNumber":108,"sourceCode":"    }\n\n    /// Consumes the gradients for a given tensor.\n    ///\n    /// Each tensor should be consumed exactly 1 time if its gradients are only required during the\n    /// backward pass, otherwise, it may be consume multiple times.\n    pub fn consume<B: Backend>(&mut self, node: &NodeRef) -> FloatTensor<B> {\n        match node.requirement {\n            Requirement::Grad => self\n                .container\n                .get::<TensorPrimitive<B>>(&node.id.value)\n                .map(|tensor| tensor.tensor())\n                .expect(\"Can't consume the gradients before they are registered at least once.\"),\n            Requirement::GradInBackward => self\n                .container\n                .remove::<TensorPrimitive<B>>(&node.id.value)\n                .map(|tensor| tensor.tensor())\n                .expect(\"Can't consume the gradients before they are registered at least once.\"),\n            Requirement::None => panic!(\"Trying to consume the gradients for an untracked tensor\"),\n        }\n    }\n\n    /// Removes a grad tensor from the container.\n    pub fn remove<B: Backend>(&mut self, tensor: &AutodiffTensor<B>) -> Option<FloatTensor<B>> {\n        self.container\n            .remove::<TensorPrimitive<B>>(&tensor.node.id.value)\n            .map(|tensor| tensor.tensor())\n    }\n\n    /// Gets a grad tensor from the container.\n    pub fn get<B: Backend>(&self, tensor: &AutodiffTensor<B>) -> Option<FloatTensor<B>> {\n        self.container\n            .get::<TensorPrimitive<B>>(&tensor.node.id.value)\n            .map(|tensor| tensor.tensor())\n    }\n\n    /// Register a grad tensor in the container.","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-autodiff/src/grads.rs#L90-L126","documentation":"Gradients container lookup failure: `consume` only retrieves gradients for nodes whose autodiff `Requirement` is `Grad`. Calling `consume` on a tensor whose gradients were never registered (created with grad tracking disabled, or already consumed/removed from the container) means the `.get()` returns None and the expect fires — a programming error in backward-pass bookkeeping, not a recoverable runtime condition.","triggerScenarios":"Executing a Select operation IR on a bool tensor whose desc.update is not IndexingUpdateOp::Add (e.g. a select/index assignment with a non-additive update op traced into the graph).","commonSituations":"Models using gather/select-and-update patterns on bool tensors routed through burn-router; code generated from frameworks where bool select defaults to a non-Add update op.","solutions":["Switch the update op to IndexingUpdateOp::Add so the bool_select_or path is used.","Do the select-update on an int tensor and cast to bool.","Extend burn-router's bool select match arm if a new op needs support upstream."],"exampleFix":"// before\nlet out = tensor_bool.select(dim, indices, value, IndexingUpdateOp::Set); // panics\n// after\nlet out = tensor_bool.select(dim, indices, value, IndexingUpdateOp::Add);","handlingStrategy":"validation","validationCode":"fn bool_select_supported(update: IndexingUpdateOp) -> bool {\n    matches!(update, IndexingUpdateOp::Add)\n}\n// assert!(bool_select_supported(desc.update)) before select on a bool tensor","typeGuard":"fn is_add_update(op: &IndexingUpdateOp) -> bool {\n    matches!(op, IndexingUpdateOp::Add)\n}","tryCatchPattern":"std::panic::catch_unwind(std::panic::AssertUnwindSafe(||\n    run_select_on_bool(...)\n)).map_err(|_| anyhow::anyhow!(\"bool select only supports Add update op\"))","preventionTips":["Use Add (OR) update semantics for bool select.","Compute selects on int tensors, convert to bool afterward.","Keep traced graphs limited to ops the router implements for bool.","Add graph linting to flag bool select ops with non-Add updates."],"tags":["rust","burn-router","select","bool-tensor","unimplemented"],"backgroundTag":"unsupported-dtype-for-op","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"}