-
Notifications
You must be signed in to change notification settings - Fork 2.8k
BUGfix: Fix image_grid_thw IndexError in GRPOTrainer with Multimodal Models (Qwen3-VL) due to None Values in Chat Content
#5364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1705,8 +1705,22 @@ def _generate_and_score_completions( | |
| ) -> dict[str, torch.Tensor | Any]: | ||
| device = self.accelerator.device | ||
| mode = "train" if self.model.training else "eval" | ||
|
|
||
| prompts = [x["prompt"] for x in inputs] | ||
|
|
||
| def remove_empty_fields(data): | ||
| if isinstance(data, dict): | ||
| return {k: remove_empty_fields(v) for k, v in data.items() if v is not None} | ||
| elif isinstance(data, list): | ||
| return [remove_empty_fields(item) for item in data if item is not None] | ||
| else: | ||
| return data | ||
|
|
||
| prompts = [] | ||
| cleaned_inputs = [] | ||
| for item in inputs: | ||
| cleaned_item = remove_empty_fields(item) | ||
| cleaned_inputs.append(cleaned_item) | ||
| prompts.append(cleaned_item["prompt"]) | ||
| inputs = cleaned_inputs | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix not propagated to RLOO trainer's duplicated codeMedium Severity The Triggered by project rule: BUGBOT.md
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if the subsequent execution flow and call stack of |
||
|
|
||
| if self.environments: | ||
| for prompt, environment, reset_kwargs in zip(prompts, self.environments, inputs, strict=True): | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Broad None stripping removes top-level image keys breaking detection
High Severity
remove_empty_fieldsis applied to the entire input dict, not just the prompt content blocks. This strips top-level keys withNonevalues, including"image". Wheninputs[0]has"image": None(a text-only sample in a mixed batch) but other inputs have actual images, the key is removed frominputs[0]. The subsequent check"image" in inputs[0]then fails, causingimages = Noneand silently losing all images in the batch. The fix should only clean the nested prompt content, not the entire input dict.Additional Locations (1)
trl/trainer/grpo_trainer.py#L1731-L1737There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inputs[0]["image"]should be PIL and will no be removed by my changes.