fix(data): count Hugging Face samples after token packing - #387
Open
Linxiushen wants to merge 1 commit into
Open
Linxiushen wants to merge 1 commit into
Linxiushen wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
TextDatasetpacks Hugging Face text into 2048-token blocks but currently chooses the number of output samples from the number of original text rows. Two short rows can therefore raiseIndexErrorafter producing one block, while a single long row silently loses its additional blocks. Empty input also fails. Separately, the HF path returns an unbatched attention mask, so collating two samples produces a[4096]mask for[2, 2048]input IDs.Apply
num_samplesto the available packed blocks, return no samples for an empty token stream, and give each attention mask the same leading dimension as its input IDs and labels. The existing partial-block/tail behavior is preserved and documented in the dataset guide.The new CPU tests use real Hugging Face datasets, a local
PreTrainedTokenizerFast, PyTorch tensors, and the existing collator. Only the external dataset-loading boundary is patched to avoid network access. They cover short rows, long rows, positive/unlimited sample limits, empty text, tail handling, and two-sample batches.Validation (Python 3.12.14, PyTorch 2.10.0+cpu, Transformers 5.6.0):
python -m pytest tests/test_text_dataset_hf.py tests/test_text_dataset_messages.py tests/test_dataloader.py -q— 35 passed.[1, 4]sample, a 6144-token row produces three blocks, and two full rows form a[2, 2048]batch with aligned masks. A tiny randomly initialized GPT-2 model consumes the short batch and returns finite loss; no model weights are downloaded.git diff --checkpasses.Full GPU compression, model-quality evaluation, and the unrelated repository test suite were not run.