Repository navigation
Conversation
…pointWriteTimeout
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Approve. With checkpoint.wait_timeout_sec set, a hung async write now fails every rank together within the timeout, with an error naming the checkpoint and no new collective, and latest never names an unfinished step; left unset, every wait behaves as on main. This held with FSDP and with two pipeline stages on four GPUs, on the save path, the final wait and the shutdown path, and the new tests fail when any line they cover is changed.
Three points that should not hold up the merge:
- After CheckpointWriteTimeout the process still does not exit, since Python joins the writer thread at exit, so outside a shutdown a write that never ends holds every rank until the job's time limit (in a 4 GPU run with a 60 s hung write, every rank raised after 5 s but exited only when the write ended). The body already names this; could the follow-up get its own issue?
- The rule that wait_timeout_sec stays below distributed.nccl_timeout_sec is only documented. A config that breaks it loads and then fails with gloo timeout errors instead of CheckpointWriteTimeout; JobConfig.post_init sees both values and could refuse it at load time.
- Without PP, when rank 0's wait ends well but another rank's timed out, rank 0 commits latest to that (complete) step while every rank reports "Checkpoint save failed on ranks [...]", which could mislead someone reading the logs.
The branch now conflicts with main in codebase-map.json (the test count), so it needs a main merge before it can go in.
amazloumi
left a comment
There was a problem hiding this comment.
Approve. The main merge resolves its one conflict, the test count in codebase-map.json, to the sum of both sides' classes (394), and nothing else differs from a clean merge. With main's resumed-step and gradient-clearing changes in, a hung write still fails every rank together within the timeout with FSDP and with two pipeline stages, and latest never names an unfinished step. The three not-blocking points of the earlier approval still apply as posted.
Summary
This is item 2 of #556; #723 did items 1 and 3. An async save's background write is waited for by the next
save(), a freeze stage'sflush_pending_save(), the loop's finalwait()and a shutdown'swait().AsyncCheckpointer.wait()calledfuture.result()with no timeout, so a write that hangs, as on a stalled filesystem, blocked the run with no error. During a shutdown only the forced-exit timer ended it, and itsGraceful shutdown timed outline could not say whether the write was slow or hung.checkpoint.wait_timeout_sec(float | None, defaultNone). Unset, every wait is as before. When set, it must be a finite number of seconds> 0, andasync_modemust be"async"or"async_with_pinned_mem".AsyncCheckpointer(mode, wait_timeout_sec=None)waits withfuture.result(timeout=...). A write still running when the wait runs out raises the newCheckpointWriteTimeout, aTimeoutErrorexported fromkempnerforge.checkpoint. Its message names the checkpoint being written (itsstep_Ndirectory, orstep_N/ppKunder PP) and the timeout, says the writer thread is still running and cannot be stopped, and says to exit rather than save again. The save stays pending under Fail a checkpoint save on every rank before any rank writes, and raise a failed async write once #737's_ended_withrule for an interrupted wait: the next wait or save waits for the same write, no second write starts beside it, andlatestnever names a step whose write did not finish (see decision 6). ATimeoutErrorthe write itself raised is still the write's own error, raised once._agree_to_writeinsave(), the barrier that endswait()andflush_pending_save(), and the stage agreement under PP. The rank that timed out raisesCheckpointWriteTimeout, and every other rank raisesRuntimeErrornaming it. That agreement runs on the manager's gloo group, whose collective timeout isgroup_timeout_sec(distributed.nccl_timeout_secin training). So the barrier after the flush already has a timeout of its own, and this PR adds no second mechanism for it.What a user notices: nothing unless the field is set. With it set, a hung write fails the run at the next wait with an error naming the checkpoint, instead of blocking; a write slower than the timeout fails the same way; and a config that sets it with
async_mode = "disabled"is refused when it loads.Docs: the
[checkpoint]table and the validation rules; a new "A bounded wait" section in the DCP model page; the failure semantics in auto-resume; and the forced-exit timer section of SLURM preemption. Alsocodebase-map.json.Decisions taken without waiting (each one you can reverse)
checkpoint.wait_timeout_sec, defaultNone, which keeps today's behavior exactly; validated as a finite number of seconds> 0.TimeoutErrorsubclass,CheckpointWriteTimeout, naming the checkpoint, the timeout and the running writer thread, and keep the save pending.async_mode = "disabled", where nothing would read it, as Refuse [data] fields the run never reads #714 does for unread[data]fields. The message says how to fix it, and--checkpoint.wait_timeout_sec=Noneunsets it on the command line. Reversing it means accepting the field there silently, or with a warning.latestcommit waiting on it. Asave()drops that commit on every rank, and so does every wait under PP, solatestnever names the step, even if the write ends later; a laterwait()drains the write without committing it. Inwait()andflush_pending_save()without PP, rank 0 commits on its own wait's outcome, as before this PR: if the ranks reach the wait far enough apart that the write ends after one rank's timeout but before rank 0's, rank 0 commits the step, whose write has then ended on every rank, since one DCP write spans them. Solatestnever names a step whose write did not finish. Dropping the commit there too would need one more all-reduce per wait. Keeping it for later would need the agreements to carry a third state per rank (still running, as opposed to failed), since a commit must stay dropped when any rank's write failed. The error tells the process to exit, and the training loop never waits again after it, so the loop loses nothing either way.<dir>/step_N, or<dir>/step_N/ppKunder PP) rather than a bare step number, sinceAsyncCheckpointeronly knows the checkpoint id.CheckpointWriteTimeoutis exported fromkempnerforge.checkpoint, and theAsyncCheckpointerconstructor validateswait_timeout_sectoo, since the class is public API.checkpoint.wait_timeout_secmust stay belowdistributed.nccl_timeout_sec, the collective timeout of the agreement that follows each wait. Above it, a rank whose wait has ended, such as one on a pipeline stage whose write did not hang, times out in that agreement first, and the ranks fail with gloo timeout errors instead ofCheckpointWriteTimeout. The docs and the field's docstring say so, but validation does not enforce it. Reversing this means refusing a larger value inJobConfig.__post_init__, where both sections are visible.Open question: exiting after the error
The writer thread cannot be stopped, and Python joins it when the process exits, so a hung writer thread keeps the process alive after
CheckpointWriteTimeout. During a shutdown, the forced-exit timer still ends it. Outside one, without PP every rank's write is the same DCP collective, so every rank sits at exit together, the launcher sees no task exit, and the job ends only at its time limit or a cancel. This PR makes the hang diagnosable and fails every rank together; it does not make the process exit by itself. Anos._exitin the entry point afterCheckpointWriteTimeoutmay deserve its own issue; it is not part of this PR.Testing
All on CPU with the CI replica venv (Python 3.14.2, torch 2.14.1), as batch jobs on the shared CPU node. The branch merges main at 3899909 (#772); every gate below ran again at that merge. The review round that followed (three commits, ending at afab6c3) changes wording, tests and
codebase-map.jsononly, so its gates are ruff, pyright, Sphinx-W, the map counts and the two touched test files; the fulltests/unitresult below is from 68f6cf6.uv run ruff check .passesuv run ruff format --check .passesuv run pyright kempnerforge/passes (0 errors)uv run pytest tests/unit/ -v --timeout=60passes, apart from known failures of the shared CPU node: 6650 passed, 14 skipped and 39 failed at the merge head (68f6cf6). 38 of the failures are intest_vlm_dataset.pyandtest_video_dataset.py, from the purgedgpt2Hugging Face cache (LocalEntryNotFoundErrorunder offline mode); they fail on main too. The 39th is atest_hooks.pycase that hitOSError: [Errno 39] Directory not emptyin a netscratch temp-directory cleanup; the file passes alone (43 passed). The head before the merge failed the same way (6640 passed).uv run torchrun --nproc_per_node=4 -m pytest tests/distributed/ -v. Not run: there are no GPUs on the batch node. No distributed code path changes beyond the manager's existing gloo agreements, which a two-rank gloo test below exercises on CPU.uv run pytest tests/e2e/ --e2e -v. Not run: none of them changed, and the e2e tests need GPUs.New tests:
tests/unit/test_checkpoint.py::TestWaitTimeout(13) and four tests (7 items) intests/unit/test_config.py::TestCheckpointConfig.Event,AsyncCheckpointer.wait()with a 0.5 s timeout raisesCheckpointWriteTimeout, imported fromkempnerforge.checkpoint, after about 0.5 s, naming the checkpoint, the timeout and the running writer thread. The save stays pending and flushing, and once the event is set, the nextwait()drains it.save()behind a write that ran out dispatches nothing.wait()passes no timeout and returns once the write ends (a pin of today's behavior, which passes on main too).TimeoutErrorthe write itself raised is the write's own error, raised once.save()raiseCheckpointWriteTimeoutinstead of blocking. It writes nothing of its own step, leaves nolatest, and never commits the hung step, even once its write ends; the next save commits as usual. The same holds forwait()andflush_pending_save()on one rank.save(step=2)raise together after about the 1 s timeout. Rank 1 raisesCheckpointWriteTimeoutand rank 0 raisesRuntimeError: Checkpoint save failed on ranks [1], with nolatest. Both ranks then stay in step for the nextwait()andsave().wait()raises on both ranks through the stage agreement. Rank 1's error namesstep_1/pp1, nothing is committed for step 1, even once its write ends, and the next save commits. Removing that stage agreement makes this test fail, as removing the package export makes the export import fail.async_mode = "disabled", from TOML too, while--checkpoint.wait_timeout_sec=Noneunsets it.Failing first, with these test files on main (3899909): 19 of the 20 new items fail, and the unset-timeout pin passes, as intended. The failures are
TypeError: AsyncCheckpointer.__init__() got an unexpected keyword argument 'wait_timeout_sec';ImportError: cannot import name 'CheckpointWriteTimeout';TypeError: CheckpointConfig.__init__() got an unexpected keyword argument 'wait_timeout_sec';AttributeError: 'CheckpointConfig' object has no attribute 'wait_timeout_sec';ValueError: Unknown config keys in CheckpointConfig: ['wait_timeout_sec']; and the two-rank tests'ProcessRaisedExceptionfrom the sameTypeError. All pass on this branch.The gap, shown with a probe in which the previous write hangs and
save(step=2)runs on a thread for 5 s:latestdid not exist after any of the three. A second probe backs the open question above. A process whoseThreadPoolExecutorworker hangs, which is how DCP runs an async write, does not exit after its main thread raises (killed bytimeoutat 15 s). With a daemon timer that callsos._exit(1), as the forced-exit timer does, it exits at 2.09 s with code 1.Also checked: at afab6c3, after the review round,
test_checkpoint.pyandtest_config.py(1014 passed), ruff, pyright and Sphinx-W; at the merge head,test_checkpoint.py,test_config.py,test_data_position.py,test_collective_timeouts.py,test_distributed_seed.pyandtest_train_entry.py(1495 passed); before it,tests/unit/test_checkpoint.py(450 passed), andtest_config.py,test_checkpoint_per_rank.py,test_pipeline_checkpoint.py,test_checkpoint_publish.py,test_collective_timeouts.pyandtest_shutdown_timeout.py(782 passed). Sphinx-Wbuilds clean, and the new#a-bounded-waitanchor resolves from the three pages that link to it. Thecodebase-map.jsoncounts show only main's known mismatches. TheTestCheckpointConfigcount goes from a stale 2 to the 40 items it collects.Main moved after the review round: #782 changed the same
tests/unit/test_checkpoint.pycount line incodebase-map.json, so this branch no longer merged.89d601c8merges main bdaf4a4 and resolves that line to 394 (374 + 13 + 7), the sum of the merged class list; nothing else conflicted. At89d601c8: ruff, ruff format and pyright (0 errors) pass,test_checkpoint.pyandtest_config.pypass (1021 passed), the two classes the merge brings together in that map entry, this branch'sTestWaitTimeout(13) and main'sTestResumedStep(7), match what pytest collects, Sphinx-Wbuilds clean, and the map counts show only main's known mismatches.Merging with the other open PRs, checked with
git merge-treeat89d601c8: #787 (c9833a33), #789 (db64875f) and #709 (991b0b6a) merge cleanly, each with a validcodebase-map.jsonand only main's known count mismatches. #648 (dce0ff8e) conflicts with main on its own, in a file this branch does not touch. #781 (506fb678) conflicts only on the same count line, as it does with main; resolve it to the sum of the merged class list (397 at that head: 374 + 13 + 7 + 3). #776 (d4e569bf) conflicts with main on its own, and with this branch in two more places: the_agree_to_writedocstring inkempnerforge/checkpoint/manager.py, where each PR adds a sentence about the failure it handles (keep both), and thetests/unit/test_checkpoint.pyentry ofcodebase-map.json(keep both classes' new counts and sum the list).Contribution terms
Closes #556