Repository navigation
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
|
@aiter-bot review |
|
aiter-bot — queued behind 1 review(s); expect to start in about 50 min. The box reviews one PR at a time. |
ROCm/aiter PR #7148 — [JIT] fix(jit): treat a zombie lock holder as dead in FileBatonFileBaton's stale-lock detection now parses /proc//stat on Linux and treats a zombie (killed-but-unreaped) lock holder as dead, so a crashed builder's lock gets broken instead of hanging every later Review (advisory):
|
WAITING ON AUTHORPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
|
Addressed in f7d659c — both sibling probes now subtract the zombie case.
Runtime validation on a gfx1151 Linux host (Python 3.12), with real killed-but-unreaped children:
The new jit_cache case also drives the end-to-end path: it writes an incomplete marker owned by the zombie pid, then asserts On the warm-path cost the review measured (+7.04 µs/call): unchanged in shape — |
f7d659c to
e1ecb53
Compare
|
The For the sibling-probe finding: both copies now share the zombie check, landed in f7d659c — |
A builder that is killed while holding the baton leaves its lock file behind. FileBaton promises waiters can detect and break such a lock instead of deadlocking forever, but `_pid_alive` only ran `os.kill(pid, 0)`, which keeps returning success for a zombie (exited but not yet reaped by its parent). The lock was therefore never considered stale and every later process that imports aiter spun in `wait()` indefinitely, with a single INFO line and no timeout -- a stale `jit/build/.../lock` (nested one level per module) bricked all subsequent startups until the file was removed by hand. Read the state field of /proc/<pid>/stat on Linux and treat Z/X as dead. Other platforms keep the kill probe, since they do not expose the state. Tests cover a real zombie child (killed and deliberately left unreaped): they fail on the old code and pass with this change; no AMD GPU is required.
The zombie check landed only in FileBaton, but jit_cache and mp_tuner keep their own kill(pid, 0) probes. A builder killed mid-codegen left an incomplete marker that still looked owned by a live process, so the next build failed with "blob code generation is already active"; a GPU-faulted tuning worker likewise kept its task waiting for the timeout. Mirror FileBaton's /proc state check in both copies and cover each with a real zombie.
e1ecb53 to
7a69096
Compare
|
Rebased onto the current
The change is semantically unchanged (same 6 files): @aiter-bot please re-run the PR Self-Review on this revision — the previous "WAITING ON AUTHOR" result was on the pre-rebase commit. |
Summary
FileBatontreats a lock holder that is a zombie (exited but not yet reaped) as dead, so a crashed builder's lock is broken instead of hanging every laterimport aiter. The same/proc/<pid>/statstate check is mirrored in the two siblingkill(pid, 0)probes: thejit_cachecodegen-owner probe and themp_tunerworker-exit probe.Motivation
FileBatonserialises the AOT module builds inaiter/jit. A builder killed mid-build (SIGKILL, OOM kill, container stop) never reachesrelease(), so it leaves<build_dir>/lockbehind. The class docstring states the intent explicitly:On Linux that detection is implemented as:
A zombie still answers
kill(pid, 0)with success, so_pid_alive()returnsTrue,_is_stale()returnsFalseforever, andwait()spins at 0.2 s intervals with no timeout and a single INFO line. From the outside the process simply hangs, with no diagnostics.Because these locks are per build module and nested (the outer lock is held by the very process blocked on the inner one), a single crashed build can leave several stale locks that block every subsequent startup of every process that imports
aiter, indefinitely, until the files are removed by hand.Observed in the wild: two nested locks (
aiter/jit/build/lock_module_custom_all_reduceandaiter/jit/build/module_custom_all_reduce/build/lock) both recording the pid of a process dead for ~24 h and still in stateZ. Selecting a different attention backend did not help — the hang happens at import time, before any device work.The same probe is copied into two other places, and the same hang/failure mode reaches them:
aiter/jit/utils/jit_cache.pykeeps a deliberately self-contained_pid_alive()("kept self-contained rather than shared withfile_baton"). A builder killed mid-codegen — after writing the incomplete marker but before flipping it to complete — still looks live, and every later build of that module fails withRuntimeError: blob code generation is already activefrom_marker_owner_is_active/stage_blob_sources.aiter/utility/mp_tuner.py:_task_worker_exited()uses the same probe, so a GPU-faulted tuning worker that is still unreaped keeps its task waiting for the full timeout instead of being reported gone.Reproduction (no GPU, no build, ~10 lines)
Run under
timeout 8 python3 repro.py: printsZ, thenTrue, then gets killed by the timeout (exit 124).Changes
Read the state field of
/proc/<pid>/staton Linux and treatZ(andX) as dead._pid_alive()keeps the existingkill(pid, 0)semantics and only subtracts the zombie case (also on thePermissionErrorpath, since/procreports the state of foreign processes too). Windows and non-Linux paths are unchanged.aiter/jit/utils/file_baton.py: new_is_zombie(), called from_pid_alive().aiter/jit/utils/jit_cache.py: local_is_zombie()called from_pid_alive(); the docstring now states that this handling must stay in sync withFileBaton.aiter/utility/mp_tuner.py: local_is_zombie();_task_worker_exited()returns it oncekill(pid, 0)succeeds (success only proves the pid is taken).core.pyputsaiter/jit/utilsonsys.path, andspec_from_file_locationin the tests) leave no import path that works everywhere without sys.path/path-loading machinery. Happy to revisit if you would rather have the shared module.Performance (if applicable)
Not applicable — pure Python JIT infrastructure, no kernel/op change, so no workload benchmark is relevant. The only hot-path effect is one extra
/procread per0.2 swait spin, taken only afterkill(pid, 0)succeeds and never on the uncontended acquire path; the automated review measured_pid_aliveon a live pid at 0.37 µs (basebca8bde1e) vs 7.41 µs (headf7d659c33), +7.04 µs ≈ 0.004% of one spin.Testing
New
tests/test_file_baton.py(unittest, module loaded straight from source — no ROCm needed):_pid_alive()isFalse,_is_stale()isTrue, and_try_break_stale()removes the lock;wait()in a daemon thread with a 5 s join, so a regression fails loudly instead of hanging the suite;On the platform where the bug bites (gfx1151 Linux host, Python 3.12, real killed-but-unreaped children):
bca8bde1e)f7d659c33)tests/test_file_baton.py(5)op_tests/test_jit_cache_transaction.py(TestJitCacheRecovery+TestJitCacheTransaction, 26)test_zombie_codegen_owner_is_recoveredfailed at_pid_alive(zombie) is Truetest_mp_tuner_logic.TestTaskWorkerExitzombie cases (2)_task_worker_exitedreturned FalseThe new
jit_cachecase also drives the end-to-end path: it writes an incomplete marker owned by the zombie pid, then assertsstage_blob_sourcesrestores and completes the tree instead of raising.Documentation
_is_zombie()docstrings, and thejit_cachecopy now states it must stay in sync withFileBaton._pid_alive()Dependencies
Breaking Changes
None. Lock file format, public API and non-Linux behaviour are unchanged; only the zombie case stops being reported as "alive".
PR Self-Review
Reviewed revision
e1ecb5346c3b(rebased ontoupstream/main45e71e04b)Behavior and intent
A lock/marker/worker owner that has exited but not been reaped (state
Z, orX) is now treated as dead, so its hold onFileBaton.wait(), on ajit_cachecodegen marker, and onmp_tuner's worker-exit check is released. The existing behaviour is insufficient becausekill(pid, 0)succeeds for a zombie:FileBaton.wait()spins forever on a stale lock, the next build of an affected module dies withRuntimeError: blob code generation is already active, and a GPU-faulted tuning worker is only noticed after its task timeout. Intended behaviour (from the class docstring) is that a crashed builder's lock is detected and broken instead of blocking every laterimport aiter; this PR makes the three probes match that intent. Everything else is unchanged: live pids, reaped pids, missing owner info, foreign hosts, Windows/non-Linux.Validation and unverified scope
Commands (run from the repo root):
python3 -m unittest tests.test_file_baton -vpython3 -m unittest op_tests.test_jit_cache_transaction.TestJitCacheRecovery op_tests.test_jit_cache_transaction.TestJitCacheTransactionpython3 -m unittest op_tests.tuning_tests.test_mp_tuner_logic.TestTaskWorkerExit -vpython3 -m ruff check aiter/jit/utils/file_baton.py aiter/jit/utils/jit_cache.py aiter/utility/mp_tuner.py tests/test_file_baton.py op_tests/test_jit_cache_transaction.py op_tests/tuning_tests/test_mp_tuner_logic.py→ cleanHardware/configuration: gfx1151 (Ryzen AI MAX 395, Strix Halo) Linux host, ROCm container, Python 3.12; results in the table above (base 2 failed / 1 of 26 failed / 2 failed → head 5 passed / 26 passed / 2 passed). No AMD GPU, no HIP build and no
aiterJIT build is involved — the tests load the modules from source and use real child processes, so the absence of MI250X/MI300X in this environment is not a coverage gap.Post-rebase re-check at
e1ecb534(macOS, no/proc, no ROCm):tests/test_file_baton.py→ 3 passed, 2 skipped;op_tests/test_jit_cache_transaction.py→ 26 tests, 1 skipped (/proc-only zombie case). Themp_tunersuite cannot be imported on macOS (needs a ROCm install). So the 3/proc-only tests skipped in those two suites, and themp_tunerzombie test, were not re-run on Linux ate1ecb534; the rebase was verified to be content-identical to the validated headf7d659c33(the two patch files differ only in theirindexblob hashes).Unverified: MI250X / MI300X / Windows runs (no access); behaviour with PID reuse (see below); a
wait()timeout.PR-specific question
What changes in dependency, cache or compilation behavior, and how did you verify both a clean build and an existing-cache path?
sys, existingos), no new requirement, no lock-file format change (stillpid\nhost\n).RuntimeError: blob code generation is already active. Nothing about what gets compiled, where artifacts are stored, or how they are published changed; a marker owned by a live pid still blocks a concurrent build exactly as before.tests/test_file_baton.py, andTestJitCacheTransaction:test_successful_codegen_is_published_only_after_explicit_commit,test_header_only_codegen_is_accepted,test_codegen_that_produces_no_build_input_is_rejected): no marker / no lock present, codegen stages, publishes only on explicit commit, and a failed generator raises instead of publishing.TestJitCacheTransaction:test_staging_path_and_unchanged_mtime_are_stable,test_failed_codegen_restores_last_complete_sources,test_snapshot_does_not_reuse_same_stat_file_with_changed_content;TestJitCacheRecovery:test_fresh_legacy_backup_formats_recover_without_age_delay,test_recovery_does_not_take_live_peer_or_remote_backups): a complete marker/published tree is reused without recompiling, a live peer's staging tree and backup are still left alone, and a failed run restores the last complete sources. The newtest_zombie_codegen_owner_is_recoveredadds the third case — an abandoned marker — and asserts the tree is restored, completed, and that the transaction artifacts are cleaned up.Changed op tests
op_tests/test_jit_cache_transaction.py— addsTestJitCacheRecovery.test_zombie_codegen_owner_is_recovered. It covers the incomplete-marker recovery path when the marker's recorded owner is an unreaped zombie: assertsjit_cache._pid_alive(zombie)isFalseand_marker_owner_is_active(marker)isFalse, then assertsstage_blob_sourcesrestores the sources, writes the complete marker and leaves no transaction artifacts, instead of failing with "blob code generation is already active". Not redundant: the existing recovery cases all use an owner that was reaped —test_dead_owner_is_reaped_without_waiting_for_legacy_gracecallschild.wait(),test_abrupt_restore_owner_exit_is_recovered_and_reclaimedusessubprocess.run, and the live-peer cases keep the owner alive — so none of them keeps the child unreaped, which is exactly the statekill(pid, 0)misreports and the only state this PR changes. Without the fix the new test fails at_pid_alive(zombie) is True.op_tests/tuning_tests/test_mp_tuner_logic.py— addsTestTaskWorkerExit.test_killed_unreaped_worker_is_detected. It SIGKILLs a child, waits until/proc/<pid>/statreportsZwithout reaping it, and assertsmp_tuner._task_worker_exited([pid], 0)isTrue, i.e. a GPU-faulted worker is reported gone immediately instead of holding the task until its timeout. Not redundant:test_exited_worker_is_detectedin the same class waits on its child first, so it passes even with the buggy probe;test_worker_pid_recorded_when_task_startsand the queued-slot cases do not exercise exit detection at all. Without the fix the new test fails because_task_worker_exitedreturnsFalsefor the zombie.op_tests/file is touched.Notes / scope
/proc/<pid>/stat) in the lock file and compares it on read. That changes the lock file format, so it deserves its own discussion.wait()has no timeout. Adding a bounded wait with an ERROR log (lock path + owner pid) would turn a silent hang into a diagnosable failure; left out to keep this PR behaviour-preserving apart from the bug.