-
Notifications
You must be signed in to change notification settings - Fork 664
fix(bridge): gate batched-list position_ids on the target model #1627
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
base: dev-4.x
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -1734,7 +1734,11 @@ def forward( | |
| ).to(self.cfg.device) | ||
| finally: | ||
| self.tokenizer.padding_side = _prev_side | ||
| if "position_ids" not in kwargs: | ||
| # Gated on the target for the same reason the derivation below is: | ||
| # a fixed-signature forward raises TypeError on the kwarg, and a | ||
| # model that owns its own position derivation is overridden by it | ||
| # (#1626). | ||
| if "position_ids" not in kwargs and self._accepts_derived_position_ids(): | ||
| position_ids = attention_mask.long().cumsum(-1) - 1 | ||
| position_ids.masked_fill_(attention_mask == 0, 1) | ||
| kwargs["position_ids"] = position_ids | ||
|
|
@@ -2142,9 +2146,12 @@ def _generate_tokens( | |
| ).to(self.cfg.device) | ||
| self.tokenizer.padding_side = _prev_side | ||
| forward_kwargs["attention_mask"] = attn_mask | ||
| position_ids = attn_mask.long().cumsum(-1) - 1 | ||
| position_ids.masked_fill_(attn_mask == 0, 1) | ||
| forward_kwargs["position_ids"] = position_ids | ||
| # Same target gate as the forward() path: the mask is safe | ||
| # for every model, the derived positions are not (#1626). | ||
| if self._accepts_derived_position_ids(): | ||
|
Collaborator
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. For a |
||
| position_ids = attn_mask.long().cumsum(-1) - 1 | ||
| position_ids.masked_fill_(attn_mask == 0, 1) | ||
| forward_kwargs["position_ids"] = position_ids | ||
| if gen_step_idx == 0: | ||
| if pixel_values is not None: | ||
| forward_kwargs["pixel_values"] = pixel_values | ||
|
|
||
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.
The
_generate_tokensportion of this fix is untested here and neither fixed-signature architecture can reach that site. Can you add a cached-vs-uncached batched-generate parity test on agate=Falsemodel?