Apply max_length truncation on HF assistant-mask path#645
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughIn ChangesHF assistant-mask path truncation
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/integration/datagen/test_preprocessing.py (1)
672-688: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a
_supports_assistant_maskskip guard to avoid a spurious failure.This test selects the HF mask path (
assistant_pattern=None) but only guards onchat_template. If the processor has a chat template yet does not emit a functionalassistant_masks/assistant_mask,_get_input_ids_loss_maskraises and_preprocess_batchswallows it (continue), leavingresults["input_ids"]empty. The subsequentassert len(results["input_ids"]) == 1then fails rather than skipping. The existingtest_preprocess_batch_uses_hf_assistant_maskalready guards for this case; mirror it here.💚 Proposed guard
if not hasattr(processor, "apply_chat_template") or processor.chat_template is None: pytest.skip("Processor does not support chat templates") + + if not _supports_assistant_mask(processor): + pytest.skip("Processor does not support assistant token mask")As per path instructions: "Ensure PyTest tests are clear, comprehensive, and cover edge cases ... Check that new code paths introduced in the PR are covered."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/integration/datagen/test_preprocessing.py` around lines 672 - 688, The test currently only guards on the presence of a chat_template but does not verify that the processor supports assistant_mask functionality. When assistant_pattern is set to None to use the HF mask path, the processor must emit a functional assistant_mask, otherwise _get_input_ids_loss_mask will fail silently and leave results["input_ids"] empty, causing the assertion to fail instead of skipping. Add a second skip guard that checks _supports_assistant_mask (mirroring the existing guard pattern used in test_preprocess_batch_uses_hf_assistant_mask) to ensure the processor supports both chat_template and assistant_mask before proceeding with the test.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/integration/datagen/test_preprocessing.py`:
- Around line 672-688: The test currently only guards on the presence of a
chat_template but does not verify that the processor supports assistant_mask
functionality. When assistant_pattern is set to None to use the HF mask path,
the processor must emit a functional assistant_mask, otherwise
_get_input_ids_loss_mask will fail silently and leave results["input_ids"]
empty, causing the assertion to fail instead of skipping. Add a second skip
guard that checks _supports_assistant_mask (mirroring the existing guard pattern
used in test_preprocess_batch_uses_hf_assistant_mask) to ensure the processor
supports both chat_template and assistant_mask before proceeding with the test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a24dfaed-5c01-4564-98b8-0842de5d543a
📒 Files selected for processing (2)
src/speculators/data_generation/preprocessing.pytests/integration/datagen/test_preprocessing.py
| tools=tools, | ||
| add_generation_prompt=False, | ||
| return_dict=True, | ||
| processor_kwargs=processor_kwargs, |
There was a problem hiding this comment.
Multimodal inputs stay untruncated since vLLM re-tokenizes them from messages.
It seems like in the fallback case we are currently truncating the messages?
There was a problem hiding this comment.
Thanks for catching that. Yes, the fallback path truncates MM input_ids via processor_kwargs, which desyncs from vLLM's re-tokenization of full messages (the prompt_token_ids != token_ids check in extract_output would reject it).
I think that's a latent bug. Gate it the same way so only the text-only branch truncates is better. Should I fold this fix into the current PR, or keep it scoped and open a separate one?
|
I think these are related. Will double check the behavior consistency. |
a00f478 to
7956369
Compare
7956369 to
1349123
Compare
orestis-z
left a comment
There was a problem hiding this comment.
LGTM. Clean fix for a real bug — the HF assistant-mask path was silently ignoring max_length. Agree with @coderabbitai’s suggestion to add the _supports_assistant_mask skip guard to the new test. Recommend approving once that’s addressed.
🤖 Generated with Claude Code using the /pr-review skill
0cbf047 to
2883ef1
Compare
Signed-off-by: Guan-Ming (Wesley) Chiu <105915352+guan404ming@users.noreply.github.com>
2883ef1 to
061856a
Compare
WindChimeRan
left a comment
There was a problem hiding this comment.
This PR is on the legacy HF path, which will be superseded by #794 . We want single-source of the truth from vllm.
speculatorsbot
left a comment
There was a problem hiding this comment.
LGTM. Correct fix — the ProcessorMixin gate is consistent with the fallback path, and the regression test validates both input_ids and loss_mask truncation. Outstanding items from earlier reviews (the _supports_assistant_mask skip guard and the #794 supersession question) are the right things to resolve before merging. Recommend approving once addressed.
🤖 Generated with Claude Code using the /pr-review skill
|
Thanks for putting up this fix! We're deprecating this path way tho. Please take a look at #794 and let us know if you have other concerns/recommendations. |
Purpose
Truncate text-only inputs on the HF assistant-mask path to max_length, which it previously ignored, making
--seq-lengtha no-op for text models using HF masks. Multimodal inputs stay untruncated since vLLM re-tokenizes them from messages.Tests
test_preprocess_batch_truncation_hf_mask_path→ passed. Fails before the fix, passes after;test_preprocess_batch_multimodalstill passes.Checklist
I have filled in: