| 482 | return grad |
| 483 | |
| 484 | def unregister(self, state): |
| 485 | with self._lock: |
| 486 | if not state.active: |
| 487 | return |
| 488 | for graph_task_id in state.graph_task_ids: |
| 489 | refcount = self._graph_task_refcounts[graph_task_id] - 1 |
| 490 | if refcount: |
| 491 | self._graph_task_refcounts[graph_task_id] = refcount |
| 492 | else: |
| 493 | del self._graph_task_refcounts[graph_task_id] |
| 494 | state.active = False |
| 495 | self._active_states.remove(state) |
| 496 | |
| 497 | def is_current_graph_registered(self): |
| 498 | graph_task_id = torch._C._current_graph_task_id() if self.supported() else -1 |