You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cross-thread backward: forward on one thread, .backward() on another fails with a misnamed 'second time' error #78
Shim: RuntimeError: torch._C eager: Trying to backward through the graph a second time -- the saved intermediate values have already been freed ...
Cause. The eager tape (EAGER in torch_c/src/capture.rs:66-75) is a thread_local. The backward thread finds no tape and reports graph reuse. Upstream's graph lives on the tensors, so any thread can walk it.
This is wrong twice over:
the shim refuses something upstream does;
the refusal names the wrong cause (AGENTS.md §18).
Done when
A cross-thread forward/backward gives upstream's gradient. The likely fix is that the tape becomes reachable from the tensors' grad_fn rather than from the calling thread, or is process-wide under a lock.
Until that lands: if the tape is missing because the forward ran on another thread, the error says that, not "a second time".
A test runs the forward in a thread and the backward in another, compared against upstream.
Activity
Merge pull request #79 from thisisthepy/feat/xthread-backward
b-re-w commentedon Oct 16, 2026
Landed in develop via #79