-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix mm_token_type_ids silently dropped in DPO VLM training #5279
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 |
|---|---|---|
|
|
@@ -336,12 +336,23 @@ def torch_call(self, examples: list[dict[str, Any]]) -> dict[str, Any]: | |
| rejected_type_ids = processed_rejecteds["token_type_ids"] | ||
| completion_token_type_ids = torch.cat(tuple(pad([chosen_type_ids, rejected_type_ids], padding_value=0))) | ||
| token_type_ids = torch.cat((prompt_token_type_ids, completion_token_type_ids), dim=1) | ||
| if "mm_token_type_ids" in processed_prompts: # special case for Qwen2.5-VL | ||
| prompt_mm_token_type_ids = processed_prompts["mm_token_type_ids"] | ||
| mm_token_type_ids = torch.cat((prompt_mm_token_type_ids, torch.zeros_like(completion_ids)), dim=1) | ||
|
|
||
| # Flush left to reduce padding | ||
| if "token_type_ids" in processed_prompts: | ||
| if "token_type_ids" in processed_prompts and "mm_token_type_ids" in processed_prompts: | ||
| attention_mask, input_ids, completion_mask, token_type_ids, mm_token_type_ids = flush_left( | ||
| attention_mask, input_ids, completion_mask, token_type_ids, mm_token_type_ids | ||
| ) | ||
| elif "token_type_ids" in processed_prompts: | ||
| attention_mask, input_ids, completion_mask, token_type_ids = flush_left( | ||
| attention_mask, input_ids, completion_mask, token_type_ids | ||
| ) | ||
| elif "mm_token_type_ids" in processed_prompts: | ||
| attention_mask, input_ids, completion_mask, mm_token_type_ids = flush_left( | ||
| attention_mask, input_ids, completion_mask, mm_token_type_ids | ||
| ) | ||
| else: | ||
| attention_mask, input_ids, completion_mask = flush_left(attention_mask, input_ids, completion_mask) | ||
|
|
||
|
|
@@ -352,6 +363,8 @@ def torch_call(self, examples: list[dict[str, Any]]) -> dict[str, Any]: | |
| output["completion_mask"] = completion_mask | ||
| if "token_type_ids" in processed_prompts: | ||
| output["token_type_ids"] = token_type_ids | ||
| if "mm_token_type_ids" in processed_prompts: | ||
| output["mm_token_type_ids"] = mm_token_type_ids | ||
| return output | ||
|
|
||
|
|
||
|
|
@@ -992,7 +1005,14 @@ def compute_ref_log_probs(self, inputs): | |
| shift_completion_mask = completion_mask[..., 1:].contiguous() | ||
|
|
||
| model_kwargs = {"input_ids": input_ids, "attention_mask": attention_mask, "use_cache": False} | ||
| for key in ("pixel_values", "pixel_attention_mask", "image_grid_thw", "image_sizes", "token_type_ids"): | ||
| for key in ( | ||
| "pixel_values", | ||
| "pixel_attention_mask", | ||
| "image_grid_thw", | ||
| "image_sizes", | ||
| "token_type_ids", | ||
| "mm_token_type_ids", | ||
| ): | ||
| if key in inputs: | ||
| model_kwargs[key] = inputs[key] | ||
|
|
||
|
|
@@ -1113,7 +1133,14 @@ def _compute_loss(self, model, inputs, return_outputs): | |
| input_ids, attention_mask, completion_mask = self._truncate_inputs(input_ids, attention_mask, completion_mask) | ||
|
|
||
| model_kwargs = {"input_ids": input_ids, "attention_mask": attention_mask, "use_cache": False} | ||
| for key in ("pixel_values", "pixel_attention_mask", "image_grid_thw", "image_sizes", "token_type_ids"): | ||
| for key in ( | ||
| "pixel_values", | ||
| "pixel_attention_mask", | ||
| "image_grid_thw", | ||
| "image_sizes", | ||
| "token_type_ids", | ||
| "mm_token_type_ids", | ||
| ): | ||
|
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.
|
||
| if key in inputs: | ||
| model_kwargs[key] = inputs[key] | ||
|
|
||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.