Skip to content

Agree on the data build across ranks and name a refused step-0 data phase - #776

Open
amazloumi wants to merge 11 commits into
mainfrom
fix/data-pipeline-startup-errors
Open

amazloumi wants to merge 11 commits into
mainfrom
fix/data-pipeline-startup-errors

Conversation

@amazloumi

@amazloumi amazloumi commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

Summary

  • A data pipeline that fails on one rank now fails the run on every rank. run_training built the pipeline (data_fn or build_data_pipeline) and checked its dp_rank/dp_size on each rank, with nothing agreeing the outcome, so the ranks whose build succeeded went on and waited in the training loop's first collective until the process-group timeout (distributed.nccl_timeout_sec, 1800 s by default) or the launcher's kill. The new _agreed_data_pipeline in kempnerforge/training/entry.py runs the build, the partition check and the data-phase weight check, then passes the outcome to the checkpoint manager's agree (agree_across_ranks on the manager's own gloo group, as the MoT warm start and claim_dir use it) before the saved data position is applied. The rank that failed raises its own error; every other rank raises RuntimeError: Data pipeline build failed on ranks [N]. It costs one all-reduce of a small CPU tensor at startup; without a process group the error is raised locally, as before.
  • A rank that failed keeps its own error when the agreement itself fails. agree_across_ranks in kempnerforge/distributed/utils.py, the helper behind the checkpoint manager's agree (which saves, loads, claim_dir, the MoT warm start and now the data build use), raised the all-reduce's error alone when the all-reduce itself failed. When a healthy rank's build ran past the group's timeout, the rank whose data_fn had raised printed only gloo's Timed out waiting ...ms for send operation to complete. That rank now raises its own error whatever the all-reduce raised, a timeout or an interrupt such as KeyboardInterrupt, with its cause left as it was and a note such as Data pipeline build could not be agreed across ranks: RuntimeError: ... Timed out waiting 5000ms for send operation to complete; a rank whose part succeeded raises the all-reduce's failure with the note Data pipeline build succeeded on this rank but could not be agreed across ranks. The success path and the path without a process group are unchanged.
  • The checkpoint manager's own agreements keep a failed rank's error too. Four steps of CheckpointManager run a collective of their own on the manager's gloo group: the agreement before a save's write (_agree_to_write), the save's gather of every rank's loader and RNG state (_gather_rank_states), a load's agreement on whether any rank's DCP index holds optimizer state (_optimizer_saved_on_any_rank), and the load's model check (_check_model_fits). When that collective itself failed, as when another rank reached it only after the group's timeout (distributed.nccl_timeout_sec), a rank whose part had failed, such as one that could not create the step directory on a full disk, printed only gloo's Timed out waiting ...ms for recv operation to complete. Each step now runs its collective through run_keeping_own_error in kempnerforge/distributed/utils.py, which agree_across_ranks now uses too: that rank raises its own error, its cause left as it was, with a note such as Checkpoint save could not be agreed across ranks: RuntimeError: ... Timed out waiting 5000ms for recv operation to complete. Rank 0 keeps its refusal of a checkpoint that does not fit the model the same way, and a save keeps an error its write raised before the gather. A rank whose part succeeded raises the collective's failure with the note Checkpoint save succeeded on this rank but could not be agreed across ranks (Checkpoint load on a load). The success paths and the paths without a process group are unchanged.
  • The data-phase weight check is part of that agreement. A builder that splits sources per rank can leave a source too small on some ranks only, so a later phase's weights can be refused there and nowhere else. check_phase_weights in kempnerforge/training/data_pipeline.py, the check build_phase_state ran first, is now public and runs with the build, so that refusal fails every rank too. build_phase_state still runs it.
  • A data phase at step 0 whose weights the mixture sampler refuses is now named. _build_mixture_pipeline builds MixtureSampler with the weights a data phase at step 0 sets, and the constructor's refusal (weights that sum to 0, or a positive weight on a source with fewer samples than data-parallel ranks) reached the user without the Data phase at step N: prefix a later phase's refusal carries. The builder now re-raises it with Data phase at step 0: , through the helper the phase check uses. Without a step-0 phase the sampler's own error is unchanged. A data_fn that constructs its own MixtureSampler with the phase's weights still gets the sampler's error from its own code, which run_training cannot attribute to the phase; that error now fails every rank through the agreement.
  • The assembled-run example agrees on the data build as run_training does. build_data in examples/assembled_run/train.py mirrors run_training's data phase and built with no agreement either. It now runs build_data_pipeline and check_phase_weights, then the checkpoint manager's agree, before it applies a saved data position, with public pieces only. The partition check stays out: the example builds with build_data_pipeline, which shards by get_dp_info, and build_data's docstring already states that contract for a builder of your own. build_data's docstring and the README's ordering constraints gain the step.
  • Docs: docs/training/training-loop.md (the startup order), docs/architecture/data-flow.md (the startup list) and docs/data/sampler.md say the same, and the excerpt of save() in docs/checkpointing/train-state.md passes _gather_rank_states its new argument. The DataFn docstring says its promise holds for a builder that runs no collective of its own that a failing rank never enters. codebase-map.json lists check_phase_weights, _agreed_data_pipeline and agree_across_ranks and their new test classes, adds run_keeping_own_error, says what the manager's four agreement steps do when their collective fails, and counts the new tests.

Testing

Every tier below ran at the head, 7d61eb9e, which merges main at d4e9b7ce into the branch.

  • ruff check .: clean; ruff format --check .: 353 files formatted; pyright kempnerforge/: 0 errors
  • Docs: sphinx-build -W --keep-going -b html docs ...: build succeeded
  • Unit, Python 3.12, under coverage as CI runs it (pytest tests/unit --timeout=60 --cov --cov-branch): 6780 passed, 14 skipped (13 need CUDA, 1 needs the network), and the cluster-only timeout of test_pipeline_checkpoint_layouts.py::TestAcrossRanks::test_the_stages_continue_a_run_saved_without_pp[muon-pp3], which runs past the 60 s limit on a busy cluster CPU node and passed alone here in 91 s with a longer limit.
  • Unit, Python 3.14: 6780 passed, 14 skipped (13 need CUDA, 1 needs the network), and the cluster-only timeout of test_pipeline_checkpoint_layouts.py::TestAcrossRanks::test_the_stages_continue_a_run_saved_without_pp[muon-pp3], which alone passed here in 84 s with a longer limit.
  • Unit at the dependency floors (Python 3.12.16, torch 2.12.0, numpy 1.26.1, pandas 2.1.2, pyarrow 15.0.0, installed as CI's floors job installs them; scripts/check_dependency_floors.py --group video passes): 6779 passed, 15 skipped (13 need CUDA, 1 needs the network, 1 needs mlflow.telemetry, which the mlflow floor lacks), and the same cluster-only timeout of test_pipeline_checkpoint_layouts.py::TestAcrossRanks::test_the_stages_continue_a_run_saved_without_pp[muon-pp3], which alone passed here in 96 s with a longer limit.
  • Examples, as ci-example.yml runs them, on Python 3.14 and 3.12: examples/vlm/tests (without eval/integration) 407 passed, examples/image_understanding/tests 1587 passed and examples/assembled_run/tests 12 passed, on each
  • Integration (1 H200): pytest tests/integration: 157 passed
  • E2E (4 H200): pytest tests/e2e --e2e --slow: 54 passed
  • Distributed (4 H200): torchrun --nproc_per_node=4 -m pytest tests/distributed --slow: 213 passed on every rank
  • Smoke on 4 H200: the image-understanding example's VLM (frozen SigLIP2 encoder, 28-layer decoder) under FSDP2 over 4 ranks: train 200 steps and save, auto-resume ("Resumed from step 200, 13,107,200 tokens seen", the DataLoader position kept) to step 400 and save, with no logged step repeated; step 400 evaluated on 4 ranks and on 1 rank gives byte-identical predictions on all 765 rows. Training windows RealUtil 48.6%.
  • The new and changed tests of the first two commits fail on 648d9e20 with the test file of the second commit, b39ecc27, and pass here:
    • TestADataPipelineErrorFailsEveryRank (two gloo ranks, a 30 s process-group timeout, only the last rank's data failing: its data_fn raises, or its sampler refuses a later data phase): there rank 0 is still inside 15 s after both ranks entered the data build; here rank 0 raises RuntimeError: Data pipeline build failed on ranks [1] and rank 1 its own error within that time.
    • TestBuildDataPipeline::test_a_step_zero_phase_whose_weights_the_sampler_refuses_is_named (3 cases): there the error is the sampler's own, naming no phase.
    • TestRunTraining's partition test (2 cases), test_the_ranks_agree_on_the_data_build_before_its_loader_state_is_applied and test_a_data_phase_the_built_sampler_refuses_fails_through_the_agreement, and test_check_phase_weights_checks_every_phase_against_the_built_mixture: no agreement, and no check_phase_weights, there.
  • The three new tests in examples/assembled_run/tests fail at b39ecc27 with the third commit's test file and pass here: at b39ecc27 the agreement never sees the failed build or the refused data phase, and apply_dataloader_state runs with no agreement before it.
  • The tests added after a675888e, up to d3cfab3d, fail at a675888e with d3cfab3d's test files and pass here:
    • TestAgreeAcrossRanks in tests/unit/test_distributed.py (an all-reduce that raises: on a rank with an error, on a rank without one, with an error that already has a cause, with a KeyboardInterrupt, and with a failure Python prints on several lines): at a675888e the all-reduce's error replaces the rank's own, and no note names the agreement or the rank's error.
    • TestADataPipelineErrorFailsEveryRank::test_the_failed_rank_raises_its_own_error_when_the_agreement_times_out (two gloo ranks, a 5 s timeout on the checkpoint manager's group; the last rank's data_fn raises at once, and the other rank enters the agreement only after the last rank's wait in it has timed out): at a675888e the last rank raises only gloo's Timed out waiting 5000ms for send operation to complete; here it raises RuntimeError: data_fn failed on rank 1, with the agreement's failure in a note.
    • The step-0 case added to test_check_phase_weights_checks_every_phase_against_the_built_mixture holds at a675888e too, and fails once check_phase_weights skips a phase at step 0, a change that every other test in tests/unit/test_train_entry.py and examples/assembled_run/tests passes.
  • The 13 test cases added in d4e569bf fail at f0b5d717 with d4e569bf's test files and pass here:
    • TestAFailedSaveFailsEveryRank::test_the_failed_rank_raises_its_own_error_when_the_agreement_times_out in tests/unit/test_pipeline_checkpoint.py, When a checkpoint save's pre-write agreement fails, the rank whose save failed raises only the collective's error, not its own #780's reproduction as a test (two gloo ranks under FSDP2, a 5 s timeout on the checkpoint manager's group; the last rank cannot create the step directory, and rank 0 starts its save only once the last rank's wait in the agreement before the write has timed out): at f0b5d717 the last rank raises only gloo's Timed out waiting 5000ms for recv operation to complete; here it raises OSError: [Errno 28] No space left on device, with the agreement's failure in a note.
    • Each step with its collective made to raise, as on a rank that waited in it past the group's timeout: TestAFailedSaveCommitsNothing (the agreement before a save's write: a rank whose step directory or previous flush failed, and one whose part succeeded), TestAFailedCaptureFailsEveryRank in tests/unit/test_checkpoint_per_rank.py (the save's gather: a rank whose loader state or shard write failed, and one whose part succeeded), TestWeightDecayScopeOnResume (the agreement on the DCP index: a rank whose read failed, and one whose read succeeded) and TestACollectiveOfTheModelCheckThatFails in tests/unit/test_checkpoint_load_checks.py (the model check's gather and broadcast: a rank that could not list its entries, rank 0's failed comparison and its refusal, and a check that found nothing amiss): at f0b5d717 the collective's error replaces the rank's own, and no note names the step.
    • The same timing with real gloo collectives, by a script outside the repository, for the save's gather, the agreement on the DCP index and the model check: at f0b5d717 the rank whose part failed raises only gloo's timeout; here it raises its own error, with the timeout in a note.
  • The issues' own reproductions, run as their bodies show them: A data pipeline error on one rank leaves run_training's other ranks waiting in the training loop's first collective #749's rank 0 now exits about 0 s after rank 1 raises, under the two-process launch and under torchrun (60 s and 30 s on 648d9e20), with RuntimeError: Data pipeline build failed on ranks [1]; A data phase at step 0 whose weights the mixture sampler refuses stops the run without naming the phase #765's step-0 cases now start with Data phase at step 0: ; in When a checkpoint save's pre-write agreement fails, the rank whose save failed raises only the collective's error, not its own #780's late case rank 1 now raises OSError: [Errno 28] No space left on device with the agreement's timeout in a note, where f0b5d717 printed the timeout alone.
  • Every added line and branch in kempnerforge/ is covered in one process, by tests/unit/test_train_entry.py, tests/unit/test_distributed.py, tests/unit/test_checkpoint.py, tests/unit/test_checkpoint_per_rank.py and tests/unit/test_checkpoint_load_checks.py.

Closes #749
Closes #765
Closes #780

…hase

run_training passes each rank's data pipeline build and partition check to
the checkpoint manager's rank agreement before it applies a saved data
position. A build that raises on one rank now raises on every rank, the
others with an error naming it, instead of leaving them in the training
loop's first collective until the process-group timeout.

The mixture builder re-raises the sampler's refusal of the weights a data
phase at step 0 sets with the "Data phase at step 0: " prefix a later
phase's refusal carries.
A builder that splits sources per rank can leave a source too small on
some ranks only, so a later data phase's weights could be refused there
and nowhere else, after the ranks had agreed on the build.
check_phase_weights, the check build_phase_state ran first, is now
public, and run_training runs it inside the ranks' agreement on the data
build, so that refusal fails every rank too. build_phase_state still
runs it.
build_data mirrors run_training's data phase, which passes each rank's
data build and data-phase weight check to the checkpoint manager's rank
agreement before it applies a saved data position. build_data now does
the same with build_data_pipeline, check_phase_weights and
CheckpointManager.agree, so a build that fails on one rank fails the run
on every rank instead of leaving the others in a later collective. The
partition check run_training applies to a data_fn stays out: the example
calls build_data_pipeline, which shards by get_dp_info, and its
docstring already states that contract for a builder of your own.

build_data's docstring and the README's ordering constraints gain the
step, and three tests cover a build error and a refused data phase
reaching the agreement, and the agreement coming before
apply_dataloader_state.
@amazloumi amazloumi added the core Affecting core label Dec 5, 2026
@codecov

codecov Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
kempnerforge/checkpoint/manager.py 99.18% <100.00%> (+<0.01%) ⬆️
kempnerforge/distributed/utils.py 100.00% <100.00%> (ø)
kempnerforge/training/data_pipeline.py 94.04% <100.00%> (+0.17%) ⬆️
kempnerforge/training/entry.py 98.08% <100.00%> (+0.08%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

agree_across_ranks raised the all-reduce's error alone when the
all-reduce itself failed, for example with a gloo timeout because a
healthy rank's work ran past the group's timeout, so a rank whose own
part had failed reported only the timeout. Such a rank now re-raises its
own error with the all-reduce's failure in a note, its cause left as it
was, and a rank whose part succeeded raises the all-reduce's error with a
note naming what the ranks were agreeing on. Every caller gets it, such
as the checkpoint manager's agree, which saves, loads, the directory
claim, the MoT warm start and the data build use. The success path and
the path without a process group are unchanged.

The check_phase_weights test gains a refused data phase at step 0, the
data-flow startup list gains the data-build agreement, and the DataFn
docstring says its promise holds for a builder that runs no collective of
its own that a failing rank never enters.
…rror

agree_across_ranks caught only an Exception from its all-reduce, so a
KeyboardInterrupt, or any other failure that is not an Exception, still
dropped the error of a rank whose own part had failed. It now catches
every failure. An Exception still gives way to the rank's own error,
which notes it, while an interrupt propagates as itself, so it still
stops the run as an interrupt, with the rank's error in a note.
A rank whose own part failed now raises that error whatever the
all-reduce raised, an interrupt such as KeyboardInterrupt included, with
the failure in a note and the error's cause left as it was, instead of
letting the interrupt replace it. The note gives the failure as Python
prints it, so an interrupt with no message reads "KeyboardInterrupt". A
rank without an error still raises the all-reduce's failure, noting what
the ranks were agreeing on.
The note on a failed rank's error took only the first line Python prints
for the all-reduce's failure, which for a failure printed on several
lines, such as a SyntaxError, is a location line without the type or the
message. It now keeps every line.
…ve fails

Four steps of the checkpoint manager run a collective of their own on its
gloo group: the agreement before a save's write, the save's gather of
every rank's loader and RNG state, a load's agreement on whether any
rank's DCP index holds optimizer state, and the load's model check. When
that collective itself failed, for example with a gloo timeout because
another rank reached it only after the group's timeout, a rank whose own
part had failed raised the collective's error alone. Each step now runs
its collective through run_keeping_own_error, which agree_across_ranks
now uses too: such a rank re-raises its own error with the collective's
failure in a note, its cause left as it was, and a rank whose part
succeeded raises the collective's error with a note naming the step.
Rank 0 keeps its refusal of a checkpoint that does not fit the model the
same way, and a save keeps an error its write raised before the gather.
The success paths and the paths without a process group are unchanged.

Tests make each step's collective fail, and a two-rank gloo test lets the
agreement before the write time out on a rank that cannot create the
step directory. The wait for another rank's outcome moves into
tests/gloo_ranks.py, and the save() excerpt in the train-state page
passes the gather its new argument.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Affecting core

Projects

None yet

1 participant