Test DataCollatorForChatML raises when completion fills window#6319
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 56fc039. Configure here.
| max_length = 256 # smaller than the completion, so no prompt tokens survive | ||
| collator = DataCollatorForChatML(tokenizer=llama_tokenizer, max_length=max_length) | ||
| with pytest.raises(ValueError, match="no prompt tokens left after truncation"): | ||
| collator(examples) |
There was a problem hiding this comment.
Raises test contradicts truncates test
Medium Severity
The new test reuses the same messages and max_length=256 as test_chatml_collator_truncates_keeping_completion_end, which calls DataCollatorForChatML without error. The collator only raises when the truncated window has zero prompt tokens, which requires the completion alone to span at least max_length tokens—something this shared fixture does not achieve for llama_tokenizer, so pytest.raises will not trigger.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 56fc039. Configure here.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |


This PR adds a test covering the edge case where a chat completion is long enough to fill the entire max_length window on its own, so no prompt tokens survive truncation. It verifies that DataCollatorForChatML raises a clear ValueError ("no prompt tokens left after truncation") instead of emitting an all-padding prompt row that would leave nothing to generate from.
Follow-up to:
Changes
Note
Low Risk
Test-only change with no runtime or training logic modifications.
Overview
Adds
test_chatml_collator_raises_when_completion_fills_windowin the GOLD trainer tests, placed next to the existing truncation tests forDataCollatorForChatML.The test uses a long user/assistant chat example with
max_length=256so the assistant completion alone exceeds the window and no prompt tokens survive end-keeping truncation. It asserts the collator raisesValueErrorwith messageno prompt tokens left after truncationinstead of returning a batch with an empty or all-padding prompt that would break generation-style training.This is test-only coverage for behavior already implemented in
DataCollatorForChatML; the PR diff does not change collator or trainer code.Reviewed by Cursor Bugbot for commit 6939017. Bugbot is set up for automated code reviews on this repo. Configure here.