Repository navigation
Per-thread grad mode and device-mode stack (#76, part 1) - #77
Conversation
…am's are (#76) Both were process-wide: torch.no_grad() in one thread stopped grad_fn recording in another, and torch.device('meta') on one thread moved another thread's factories to meta. Wrong with the GIL on, not only on 3.15t. tensor.rs GRAD_ENABLED is a thread_local Cell; the bootstrap's grad flag and _MODE_STACK sit on threading.local. tests/api/test_threadstate.py: 3 tests, green on upstream torch, red on the shim before, green after.
… out from under a live draw (#76) Streams were Box::leak'ed and reclaimed by Box::from_raw in stream_free, sound only while a kernel's guard and the generator's __del__ could not overlap under the GIL. stream() now returns a GenGuard that holds its own Arc clone; stream_free drops the table's reference. The new cargo test frees a locked stream and reuses its memory: SIGSEGV on the old code, green now.
|
Added: RNG streams are
|
Gate on CI (issue #24)Full gate: 124 suites = 116 run on at least one CI runner + 8 local-only. The local gate (
Local-only: verified by no CI runner (8)
Suites that verified nothing, or failed, on a runner
Every suite, every runner
A SKIP is unverified on that runner, never passed. UNVERIFIED means the suite ran and every one of its tests skipped by name. |
…; test_threadstate sets TORCH_USE_RTLD_GLOBAL CAPTURING was cleared by whichever thread ended its capture first, so a thread still mid-capture stopped recording and its later ops vanished from its trace. It is now an AtomicUsize of open regions (one per thread at most, since capture_begin refuses nesting); the door still pays one relaxed load. test_threadstate.py never ran in the gate before this commit: it died at import torch for want of TORCH_USE_RTLD_GLOBAL, which every other suite that imports torch sets. Now 4 ok in the gate (2010 -> 2014).
|
Correction. My two earlier gate summaries on this PR were wrong. They said 'FAIL=2, both build.py self-tests'. In fact Fixed in the latest commit, which also adds the capture-flag fix (#76 item 3):
|
|
CI evidence (run 37316717277, 992c69c): linux gate |
Refs #76 (the issue stays open: the RNG stream free race and the CAPTURING flag remain).
Defect fixed
thread_localintensor.rsand athreading.localin the bootstrap, as upstream'sGradModedoes.torch.device(...)) was process-wide. It is now a per-thread stack behind the same list-shaped API.Test added
tests/api/test_threadstate.py, 3 tests:Gate (worktree, local, 2026-10-05)
build.pyself-test suites that need the release machine's target CPythons under.caches/, which a worktree lacks. This branch does not touchbuild.py.