fix(data): handle all-empty BFD packing - #6971
Open
YZJF wants to merge 1 commit into
Open
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.
What does this PR do?
Fixes #6970.
pack_dataset(..., strategy="bfd")and"bfd_split"filter empty input sequences before binning. If every typed input sequence is empty, this leaves no bins. The empty Python list passed topyarrow.compute.takeis inferred as anullindex array, which raisesArrowNotImplementedErrorinstead of producing an empty packed dataset.Construct the take indices as an explicit
int64Arrow array. This preserves the existing behavior for non-empty indices and lets both BFD strategies return an empty dataset withseq_lengthswhen all input sequences are empty.Tests
python -m pytest tests/test_data_utils.py -k 'all_empty_sequences' -vvfailed for bothbfdandbfd_splitwithArrowNotImplementedError: Function 'array_take' has no kernel matching input types (list<item: int64>, null).python -m pytest tests/test_data_utils.py -k 'TestPackDatasetBfd' -vvpassed (9 passed).pre-commit run --files trl/data_utils.py tests/test_data_utils.py,git diff --check, andpython -m compileall -q trl/data_utils.py tests/test_data_utils.pypassed.Before submitting
AI writing disclosure
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag members/contributors who may be interested in your PR.
Note
Low Risk
Narrow edge-case fix in dataset packing with explicit Arrow typing; behavior for non-empty inputs is unchanged and covered by existing BFD tests.
Overview
Fixes BFD packing (
pack_datasetwithstrategy="bfd"or"bfd_split") when every input sequence is empty after filtering: it no longer raisesArrowNotImplementedErrorand instead returns an empty packed dataset with emptyinput_idsandseq_lengths.The failure came from passing an empty Python list of row indices into
pyarrow.compute.take, which PyArrow treated as anullindex type._pack_bfdnow builds take indices as an explicitint64Arrow array viapa.array(..., type=pa.int64()).Tests add
test_with_all_empty_sequences, parametrized over both BFD strategies, using typedFeaturesfor all-emptyinput_idsrows.Reviewed by Cursor Bugbot for commit 49ebf23. Bugbot is set up for automated code reviews on this repo. Configure here.