Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions codebase-map.json
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@
"_check_model_fits(dcp_state, every_rank, dcp_dir, restaged, saved_keys, planner) (before any tensor is read: every rank sends rank 0 its index and its model entries' global shapes, keyed as DCP's load planner reads the state the load's _NeverSteppedStatePlanner leaves it from that index, with every EP rank's expert names; rank 0 reads each index once and refuses, for every rank alike, model tensors no rank loads, of another size, or that a rank loads and the index lacks; a rank that cannot list its entries sends why, as rank 0 does when comparing fails, and every rank raises; if the gather or the broadcast itself fails, a rank with an error, rank 0's refusal included, still raises it, with that failure in a note; checkpoint.ignore_extra_model_tensors leaves the extra ones unread with a warning, and a refusal names it only when the indexes hold every tensor the ranks load at its size)",
"_model_misfit_error(gathered, known, lone_stage) -> Exception | None (rank 0's verdict for _check_model_fits)",
"apply_dataloader_state(dataloader) (every rank checks the position and the ranks share their verdicts before any rank applies it; a position some rank cannot place raises DataPositionError on every rank on a resume and starts the data fresh on every rank, with a warning, on a warm start or a carried position; a carried position goes only to a StatefulDataLoader or StreamingDataLoader)",
"_position_refusals(dataloader, state) -> (refusals, world) (each rank's check_state verdict, gathered on every rank on the gloo group; a check that fails another way raises on every rank)",
"_position_refusals(dataloader, state, *, refusal_raises) -> (refusals, world) (each rank's check_state verdict, gathered on every rank on the gloo group; a check that fails another way raises on every rank; if the gather itself fails, a rank whose check failed, or refused where refusal_raises (a resume, not a warm start or a carried position), still raises that error, with that failure in a note; after a warm start or on a carried position, a rank whose check refused logs why as a warning in its own log (every_rank), then raises that failure)",
"claim_dir() (rank 0 claims <dir>/.owner through claim_checkpoint_dir, then removes the temp files of saves killed mid-write (_remove_stale_temp_files); every rank agrees on the outcome)",
"release_dir() (marks the <dir>/.owner record this rank's claim_dir wrote released, at a clean exit)",
"restored_optimizer (property: whether the last load restored this rank's optimizer state; the loop starts any other optimizer on its schedule)",
Expand Down Expand Up @@ -2666,8 +2666,8 @@
"count": 7
},
"tests/unit/test_data_position.py": {
"note": "Module-level pytest functions (no Test* classes): the data position across data-parallel and batch size changes, the in-step clamp, mixture and legacy refusals, seed and dataset-length warnings, load_path warm starts through restore_checkpoint and load(dataloader=...), gloo CheckpointManager resume on another world size; a load that restores no position (weights only, a step without train_state.pt, a train state without one) after one that kept a position leaves none pending, and a loader applied after it starts at its first sample; a resume through run_training_loop and a real CheckpointManager: without apply_dataloader_state it raises before its hooks and its first step, with it the data continues, and a run without a loader starts with the position pending; gloo CheckpointManager auto-resume (exact_resume) saved on 4 ranks: on 2 ranks with ignore_rank_state_mismatch at the exact global position with fresh RNG, refused on every rank without it, a mixture restarting with a warning, and the saved layout restoring each rank's own state; check_state's verdicts",
"count": 28
"note": "Module-level pytest functions (no Test* classes): the data position across data-parallel and batch size changes, the in-step clamp, mixture and legacy refusals, seed and dataset-length warnings, load_path warm starts through restore_checkpoint and load(dataloader=...), gloo CheckpointManager resume on another world size; a load that restores no position (weights only, a step without train_state.pt, a train state without one) after one that kept a position leaves none pending, and a loader applied after it starts at its first sample; a resume through run_training_loop and a real CheckpointManager: without apply_dataloader_state it raises before its hooks and its first step, with it the data continues, and a run without a loader starts with the position pending; gloo CheckpointManager auto-resume (exact_resume) saved on 4 ranks: on 2 ranks with ignore_rank_state_mismatch at the exact global position with fresh RNG, refused on every rank without it, a mixture restarting with a warning, and the saved layout restoring each rank's own state; check_state's verdicts; a gather of the checks that fails: on 2 gloo ranks with rank 0 late past the group timeout, rank 1's failed or refused check raised as its own error with the gather's failure in a note, and in one process after a resume, a warm start and a carried position (ignore_rank_state_mismatch on a changed world size): a failed check kept after each, a refusal kept on the resume, and after the other two a refusal logged as a warning that the rank-0 log filter passes on rank 1, then the gather's failure raised",
"count": 30
},
"tests/unit/test_mixture_phase_change.py": {
"note": "Module-level pytest functions (no Test* classes): a data phase that changes the mixture weights inside an epoch draws the rest of the epoch from the undrawn samples, with no repeat for a dataset no weighting oversamples (pipeline, loop-style reset); resumes before, at and after two changes in one epoch and in the next epoch match the uninterrupted run; resume at another batch size; weights that differ at a resume (an added anneal or phase, an edited base weight or temperature) apply from the saved position; a run without a change records only the epoch's starting weights; fixed-weight lists against a reference of the sampler's draw; undrawn-first order, caps and overflow, several changes, a dataset entering mid-epoch split the same way on every rank, also beside a one-sample dataset padded across three ranks; the epoch_weights record (pending, applied, restarted in the next epoch), its replay with and without a temperature, a state without it, and one for another dataset count; the change and a resume with dataloader workers; a change at the largest seed",
Expand Down
46 changes: 42 additions & 4 deletions kempnerforge/checkpoint/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3491,6 +3491,13 @@ def apply_dataloader_state(self, dataloader: Any) -> None:
that holds no data position, such as a streaming checkpoint saved before
streaming positions were recorded, leaves a stateful loader at its first
sample, with a warning.

If sharing the verdicts itself fails, as on a rank that waited in it past
the group's timeout, a rank whose check failed, or refused where a refusal
raises, still raises its own error, with that failure in a note (see
``run_keeping_own_error``). After a ``warm_start`` load, or on a carried
position, a rank whose check refused logs why as a warning in its own log,
then raises that failure, as a rank whose check passed does.
"""
missing, self._pending_dataloader_missing = self._pending_dataloader_missing, False
if self._pending_dataloader_state is None:
Expand Down Expand Up @@ -3527,7 +3534,9 @@ def apply_dataloader_state(self, dataloader: Any) -> None:
return
logger.info("Applied stashed dataloader state")
return
refusals, world = self._position_refusals(dataloader, state)
refusals, world = self._position_refusals(
dataloader, state, refusal_raises=not (warm_start or carried)
)
if refusals:
mine = refusals.get(self._rank)
first = min(refusals)
Expand All @@ -3553,7 +3562,7 @@ def apply_dataloader_state(self, dataloader: Any) -> None:
logger.info("Applied stashed dataloader state")

def _position_refusals(
self, dataloader: Any, state: dict[str, Any]
self, dataloader: Any, state: dict[str, Any], *, refusal_raises: bool
) -> tuple[dict[int, str], int]:
"""Why each rank's loader cannot place ``state``, gathered on every rank.

Expand All @@ -3564,7 +3573,14 @@ def _position_refusals(
too, so every rank raises together. Collective on the dedicated gloo group;
``apply_dataloader_state`` calls it whenever a position is pending for one of
the loaders that check it, which the broadcast train state and the
configured loader decide alike on every rank.
configured loader decide alike on every rank. ``refusal_raises`` says whether
a refusal raises ``DataPositionError``, as on a resume, rather than restarting
the data. If the gather itself raises, as on a rank that waited in it past the
group's timeout, a rank whose check failed, or refused where ``refusal_raises``,
still raises that error, with the gather's failure in a note, and any other
rank raises the gather's failure, with a note naming the check (see
``run_keeping_own_error``). A rank whose check refused where ``refusal_raises``
is false logs why as a warning in its own log first.

Returns:
Global rank -> why its loader cannot place the position (empty when
Expand All @@ -3573,20 +3589,42 @@ def _position_refusals(
Raises:
Exception: On a rank whose check failed other than with
``DataPositionError``, that error; ``RuntimeError`` on every other rank.
DataPositionError: If the gather itself raises, on a rank whose check
refused where ``refusal_raises``.
BaseException: If the gather itself raises, on a rank whose check passed, or
refused where ``refusal_raises`` is false, what the gather raised, with a
note naming the check.
"""
failure: Exception | None = None
refusal: DataPositionError | None = None
verdict: tuple[str, str] | None = None
try:
dataloader.check_state(state)
except DataPositionError as e:
verdict = ("refused", str(e))
if refusal_raises:
refusal = DataPositionError(str(e))
except Exception as e:
failure = e
verdict = ("failed", f"{type(e).__name__}: {_error_text(e)}")
verdicts: dict[int, tuple[str, str] | None] = {self._rank: verdict}
if dist.is_initialized():
gathered: list[Any] = [None] * dist.get_world_size(self._sync_group)
dist.all_gather_object(gathered, verdict, group=self._sync_group)
try:
run_keeping_own_error(
lambda: dist.all_gather_object(gathered, verdict, group=self._sync_group),
failure if failure is not None else refusal,
"Checking the saved data position",
)
except BaseException:
if not refusal_raises and verdict is not None and verdict[0] == "refused":
logger.warning(
f"The saved data position does not carry over to this run on rank "
f"{self._rank}, and sharing the ranks' checks of it failed, so the run "
f"stops: {verdict[1]}",
extra={"every_rank": True},
)
raise
verdicts = dict(enumerate(gathered))
if failure is not None:
raise failure
Expand Down
Loading