[Feature][Model Loader] Apply model-owned MTP shard selection to RunAI ModelStreamer (#60759)

Signed-off-by: 浩韵 <zuohaiyu.zhy@alibaba-inc.com>
Co-authored-by: Kevin H. Luu <khluu000@gmail.com>
This commit is contained in:
Haiyu Zuo
2026-10-15 12:23:11 +08:00
committed by GitHub
co-authored by Kevin H. Luu
parent 833665cded
commit ff5a91a456
6 changed files with 724 additions and 13 deletions
+9 -2
View File
@@ -141,6 +141,13 @@ _language_model_by_module: "weakref.WeakKeyDictionary[nn.Module, VllmModel]" = (
)
def _is_language_model(model: object) -> TypeIs[VllmModel]:
# Text towers can use config/position_ids signatures and omit loader hooks.
return callable(getattr(model, "embed_input_ids", None)) and callable(
getattr(model, "forward", None)
)
@runtime_checkable
class SupportsMultiModalEmbeddings(Protocol):
"""The interface for models that can merge external multimodal embeddings."""
@@ -284,14 +291,14 @@ class SupportsMultiModal(SupportsMultiModalEmbeddings, Protocol):
mod = getattr(mod, attr)
candidate: object = mod
if candidate is not self_module and isinstance(candidate, VllmModel):
if candidate is not self_module and _is_language_model(candidate):
_language_model_by_module[self_module] = candidate
return candidate
# Fallback
for mod in self_module.children():
candidate = mod
if isinstance(candidate, VllmModel):
if _is_language_model(candidate):
_language_model_by_module[self_module] = candidate
return candidate
+11 -4
View File
@@ -51,6 +51,15 @@ class VllmModel(Protocol):
self, input_ids: torch.Tensor, positions: torch.Tensor
) -> torch.Tensor: ...
def is_unused_checkpoint_weight(self, name: str) -> bool:
"""Return True for checkpoint weights this model does not load.
Defining this method is optional for satisfying this interface.
Override with the same rule used in ``load_weights``. Models without
a selection rule keep every checkpoint weight by default.
"""
return False
def _check_vllm_model_init(model: type[object] | object) -> bool:
model_init = getattr(model, "__init__") # noqa: B009
@@ -134,10 +143,8 @@ def is_text_generation_model(
if not is_vllm_model(model):
return False
if isinstance(model, type):
return isinstance(model, VllmModelForTextGeneration)
return isinstance(model, VllmModelForTextGeneration)
# Optional protocol defaults are not inherited by structural models.
return callable(getattr(model, "compute_logits", None))
@runtime_checkable