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

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
Harry Mellor
2026-03-16 10:31:16 +00:00
committed by GitHub
parent 747b068136
commit ad041c79db

View File

@@ -448,20 +448,21 @@ class MultiModalMixin(SupportsMultiModal, SupportsMRoPE):
# In v4 `get_rope_index` doesn't have wildcard `kwargs`, and
# can't accept arbitrary args, even if its value is `None`
kwargs = {}
if mm_token_type_ids:
if not hasattr(self, "_get_rope_index_accepts_mm_token_type_ids"):
import inspect
if not hasattr(self, "_get_rope_index_accepts_mm_token_type_ids"):
import inspect
sig = inspect.signature(self.model.get_rope_index)
params = sig.parameters
self._get_rope_index_accepts_mm_token_type_ids = (
"mm_token_type_ids" in params
or any(
p.kind == inspect.Parameter.VAR_KEYWORD for p in params.values()
)
)
if self._get_rope_index_accepts_mm_token_type_ids:
sig = inspect.signature(self.model.get_rope_index)
params = sig.parameters
self._get_rope_index_accepts_mm_token_type_ids = (
"mm_token_type_ids" in params
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:
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(
input_ids=torch.tensor(input_tokens).unsqueeze(0),