fix: resume SFT dataset iteration at the exact batch - #908
Open
RaycarlLei wants to merge 1 commit into
Open
RaycarlLei wants to merge 1 commit into
RaycarlLei wants to merge 1 commit into
Conversation
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.
initial_stepis a global batch offset, butcreate_sft_dataset_iteratorconverts it to a global chunk offset. This replays completed batches when an epoch ends with a short chunk, or when resuming inside a chunk.For example, with 5 trajectories,
batch_size=2,chunk_size=2, and two epochs, the chunk steps are[0, 2, 3, 5]. Resuming at step 3 currently yields[2, 3, 5]; resuming at step 6 still yields step 5 even though training is complete.Trim each chunk's start using the batch offset within its epoch, preserving the original chunk endpoint. The existing learning-rate slicing and step metadata then start at the same batch as the remaining trajectories.
The regression test compares resumed batches against the uninterrupted stream's suffix, including trajectories, learning rates, global steps, epoch, and epoch steps. It covers mid-chunk and epoch boundaries, completion, full/partial final batches, and deterministic shuffling. On the original implementation, 24 of the 32 new cases fail.
Validation:
uv run pytest tests/unit/test_sft.py -q --tb=short: 47 passed on Windows and Linux (Python 3.12).uv run prek run --all-files: Ruff, formatting, fullsrc/teststype checking, and lock validation all passed on Linux.6f11634280192dd4664f634b61a681cfe30c77ac.This validates the dataset iterator; GPU training and the backend integration suite were not run.