Exact one-epoch training from local data (padding-free distributed sampler)#72
Open
ksd3 wants to merge 1 commit into
Open
Exact one-epoch training from local data (padding-free distributed sampler)#72ksd3 wants to merge 1 commit into
ksd3 wants to merge 1 commit into
Conversation
Add an exact one-epoch training path (gated by the new `data_dir` config),
for scaling studies that must train every config on the IDENTICAL data,
each example exactly once.
New `astropt.exact_epoch`:
* `ExactDistributedSampler` -- partitions range(N) across ranks with NO
padding and NO dropping (strided slice of one seeded shuffle). Exact
coverage, reproducible (depends only on `data_seed`), and independent of
num_workers. Unlike DistributedSampler it never duplicates/drops the tail.
* `one_epoch_loop` -- consumes the loader exactly once; an optimizer step
every `grad_accum_per_rank` micro-batches with a short final step. Because
the exact partition gives every rank the same micro-batch count, the final
step is short by the same amount on every rank, so the per-step all-reduce
count stays balanced and DDP needs no Join.
* Self-tests (`python -m astropt.exact_epoch`) prove exact partition for
many sizes (incl. a prime) and that the loop consumes exactly N with the
expected step count; for the galaxies set (N=8,474,566) all of W in
{1,2,4,8} balance to 13,242 steps.
`scripts/train.py`: when `data_dir` is set, load the galaxies map-style from
local parquet, shard with `ExactDistributedSampler`, run `one_epoch_loop`,
and assert the all-reduced example count equals the dataset size (so a run
self-proves exact coverage or fails loudly). The streaming path is
unchanged; `data_seed` is also added (overlaps with the data-order PR).
Note: the DDP path is arithmetically balanced + self-asserting but has not
been run multi-GPU here -- needs a smoke test on a real 4-GPU node.
e8ac051 to
0a6b7f3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For scaling studies that must train every config on the identical data, every example exactly once. Streaming +
split_dataset_by_node+ buffered shuffle can't do that — the order depends on GPU/worker count, and the standard distributed samplers either drop the tail or pad it with duplicates whenlen % world_size != 0.src/astropt/exact_epoch.py(new, unit-tested)ExactDistributedSampler— partitionsrange(N)across ranks with no padding, no dropping: a single seeded shuffle, sliced strided (idx[rank::world_size]). Exact coverage, reproducible (depends only ondata_seed), and independent ofnum_workers(the sampler fixes the order; workers only fetch).one_epoch_loop— consumes the loader exactly once; an optimizer step everygrad_accum_per_rankmicro-batches with a short final step. The exact partition gives every rank the same micro-batch count, so the short final step is identical across ranks → the per-step all-reduce count stays balanced and DDP needs noJoin. Gradients sync every backward (all-reduce is linear ⇒ identical to accumulate-then-sync).python -m astropt.exact_epoch): exact partition for many sizes incl. a prime; the loop consumes exactly N with the expected step count. For the galaxies set (N=8,474,566), W∈{1,2,4,8} all balance to 13,242 steps.scripts/train.pyWhen
data_diris set: load the galaxies map-style from local parquet, shard withExactDistributedSampler, runone_epoch_loop, and assert the all-reduced example count == dataset size — a run self-proves exact coverage or fails loudly. Streaming path unchanged.Notes
data_seed(also introduced by the data-order PR Reproducible streaming data order across runs (fixed data_seed + pinned num_workers) #70 — trivial overlap to resolve on merge; the streaming-shuffle block is also restructured intoif exact / elif use_hf / else).