Repository navigation
Conversation
SFT tokenization can produce sequences longer than sequence_length, while the collator previously truncated only labels. Truncate all padded sequence fields before padding so inputs and labels remain aligned. Fixes alibaba#519 AI assistance (Cursor) was used for this change. Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Problem
The SFT pipeline can pass examples longer than
sequence_lengthtoDataCollatorForSFT. A mixed-length batch then fails during tensorization, while a uniformly overlong batch produces inputs and labels with different lengths.Fixes #519.
Cause
Hugging Face padding does not truncate sequence fields. The collator capped
labelsatmax_lengthbut passed overlonginput_idsandattention_maskthrough unchanged.Fix
Truncate every padded sequence field to
max_lengthbefore padding. The existing label truncation and shift then stay aligned with the model inputs.The regression test covers one overlong and one shorter example in the same batch.
Tests
env -u LD_LIBRARY_PATH ROLL_LOG_DIR=/tmp/t4-roll-logs PYTHONPATH=/tmp/t4-ROLL /tmp/t4-ROLL-venv/bin/python -m pytest -q tests/datasets/test_collator.py— 2 passedenv -u LD_LIBRARY_PATH /tmp/t4-ROLL-venv/bin/pre-commit run --files tests/datasets/test_collator.py— all hooks passedgit diff --check— passedThe changed production file was also passed to pre-commit. Its formatter hooks modify unrelated existing sections, and flake8 reports the existing
E266atroll/datasets/collator.py:471; those unrelated changes are not included.Not run
AI assistance (Cursor) was used for this change.