Skip to content

Fix the TRL-latest packing test failure blocking CI on every PR - #7713

Closed
danielhanchen wants to merge 1 commit into
mainfrom
ci-packing-trl
Closed

danielhanchen wants to merge 1 commit into
mainfrom
ci-packing-trl

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Core (HF=latest + TRL=latest) has been red on every open PR in the repo, including ones that touch nothing near packing. The failure is in the test, not in the library.

What breaks

tests/utils/test_packing.py::_DummyTrainer builds TRL's DataCollatorForLanguageModeling from a hardcoded kwarg set and then walks a ladder of try/except TypeError fallbacks for the optional flags. completion_only_loss was in the always-passed group, so when TRL removed that field from this collator the first constructor call raised TypeError and every rung of the ladder raised it too. The dummy trainer then has no data_collator at all, and the test fails with an AttributeError that names neither TRL nor the removed field.

Upstream removal: huggingface/trl commit f9aeb59 (huggingface/trl#6037), which moved completion-only label masking into dataset preparation. First released in TRL v1.7.0.

The fix

Build the collator from the installed TRL's live signature instead of guessing:

accepted = set(inspect.signature(DataCollatorForLanguageModeling).parameters)
collator = DataCollatorForLanguageModeling(
    **{k: v for k, v in wanted.items() if k in accepted}
)

This subsumes the fallback ladder: any field TRL adds or drops is handled by the same filter, rather than by another rung. The post-hoc hasattr defaults are kept so the dummy still presents the attributes the packing code checks for.

Also adds test_enable_sample_packing_only_requires_torch_call, which pins the contract the test was implicitly relying on: enable_sample_packing may require nothing of a collator beyond torch_call. That is what stops the next TRL field change from turning into a red CI run.

Scope

Test-only. Production is already defensive and was never affected:

  • unsloth/utils/packing.py reads the collator via getattr(trainer, "data_collator", None) and guards every optional field with hasattr before assigning.
  • unsloth/models/rl.py references the transformers DataCollatorForLanguageModeling, not TRL's, so the upstream removal does not reach it.

Verification

tests/utils/test_packing.py passes on TRL 0.22.2, 0.25.1, 0.29.1, 1.6.0, 1.7.1 and 1.9.2 (52 passed on the version installed here, 0.25.1). Both the pre-1.7 and post-1.7 field sets are covered, so this is not a fix that trades one pinned version for another.

TRL 1.7.0 removed completion_only_loss from
trl.trainer.sft_trainer.DataCollatorForLanguageModeling when label
construction moved from collation into dataset preparation
(huggingface/trl#6037). tests/utils/test_packing.py passed that kwarg on
every construction attempt, so on TRL 1.x every attempt raised TypeError,
_DummyTrainer.data_collator was never assigned, and
test_enable_sample_packing failed with AttributeError on the
HF=latest + TRL=latest matrix leg.

Filter the collator kwargs against the installed dataclass signature so
the dummy tracks whatever fields TRL currently exposes, and add a
regression test pinning the production contract that enable_sample_packing
only requires torch_call on the collator.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 5d8513bac7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member Author

Superseded by #7722, which combines this with the other two repo-wide CI fixes so a single merge unblocks the whole batch. The files there are byte-identical to this PR's head, and the commits are cherry-picked with provenance. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant