"vscode:/vscode.git/clone" did not exist on "227e231b55901be4e050d5a8f033e90f45cfba85"
Unverified Commit ad041c79 authored by Harry Mellor's avatar Harry Mellor Committed by GitHub
Browse files

Fix text only inputs for MRoPE models with the Transformers modelling backend (#37055)


Signed-off-by: default avatarHarry Mellor <19981378+hmellor@users.noreply.github.com>
parent 747b0681
...@@ -448,20 +448,21 @@ class MultiModalMixin(SupportsMultiModal, SupportsMRoPE): ...@@ -448,20 +448,21 @@ class MultiModalMixin(SupportsMultiModal, SupportsMRoPE):
# In v4 `get_rope_index` doesn't have wildcard `kwargs`, and # In v4 `get_rope_index` doesn't have wildcard `kwargs`, and
# can't accept arbitrary args, even if its value is `None` # can't accept arbitrary args, even if its value is `None`
kwargs = {} kwargs = {}
if mm_token_type_ids: if not hasattr(self, "_get_rope_index_accepts_mm_token_type_ids"):
if not hasattr(self, "_get_rope_index_accepts_mm_token_type_ids"): import inspect
import inspect
sig = inspect.signature(self.model.get_rope_index)
sig = inspect.signature(self.model.get_rope_index) params = sig.parameters
params = sig.parameters self._get_rope_index_accepts_mm_token_type_ids = (
self._get_rope_index_accepts_mm_token_type_ids = ( "mm_token_type_ids" in params
"mm_token_type_ids" in params or any(p.kind == inspect.Parameter.VAR_KEYWORD for p in params.values())
or any( )
p.kind == inspect.Parameter.VAR_KEYWORD for p in params.values() if self._get_rope_index_accepts_mm_token_type_ids:
) if mm_token_type_ids:
)
if self._get_rope_index_accepts_mm_token_type_ids:
kwargs["mm_token_type_ids"] = torch.cat(mm_token_type_ids) kwargs["mm_token_type_ids"] = torch.cat(mm_token_type_ids)
else:
shape = (1, len(input_tokens))
kwargs["mm_token_type_ids"] = torch.zeros(*shape, dtype=torch.int)
mrope_positions, mrope_position_delta = self.model.get_rope_index( mrope_positions, mrope_position_delta = self.model.get_rope_index(
input_ids=torch.tensor(input_tokens).unsqueeze(0), input_ids=torch.tensor(input_tokens).unsqueeze(0),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment