[Model Refactoring] Migrate DeepSeek V4 to vllm/models/ [1/N] (#43004)
Signed-off-by: Woosuk Kwon <woosuk@inferact.ai>
This commit is contained in:
@@ -6,6 +6,7 @@ Whenever you add an architecture to this page, please also update
|
||||
"""
|
||||
|
||||
import importlib
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
import pickle
|
||||
@@ -97,7 +98,7 @@ _TEXT_GENERATION_MODELS = {
|
||||
"DeepseekV2ForCausalLM": ("deepseek_v2", "DeepseekV2ForCausalLM"),
|
||||
"DeepseekV3ForCausalLM": ("deepseek_v2", "DeepseekV3ForCausalLM"),
|
||||
"DeepseekV32ForCausalLM": ("deepseek_v2", "DeepseekV3ForCausalLM"),
|
||||
"DeepseekV4ForCausalLM": ("deepseek_v4", "DeepseekV4ForCausalLM"),
|
||||
"DeepseekV4ForCausalLM": ("vllm.models.deepseek_v4", "DeepseekV4ForCausalLM"),
|
||||
"Dots1ForCausalLM": ("dots1", "Dots1ForCausalLM"),
|
||||
"Ernie4_5ForCausalLM": ("ernie45", "Ernie4_5ForCausalLM"),
|
||||
"Ernie4_5_MoeForCausalLM": ("ernie45_moe", "Ernie4_5_MoeForCausalLM"),
|
||||
@@ -611,7 +612,7 @@ _SPECULATIVE_DECODING_MODELS = {
|
||||
"Eagle3DeepseekV3ForCausalLM": ("deepseek_eagle3", "Eagle3DeepseekV2ForCausalLM"),
|
||||
"EagleDeepSeekMTPModel": ("deepseek_eagle", "EagleDeepseekV3ForCausalLM"),
|
||||
"DeepSeekMTPModel": ("deepseek_mtp", "DeepSeekMTP"),
|
||||
"DeepSeekV4MTPModel": ("deepseek_v4_mtp", "DeepSeekV4MTP"),
|
||||
"DeepSeekV4MTPModel": ("vllm.models.deepseek_v4", "DeepSeekV4MTP"),
|
||||
"Gemma4MTPModel": ("gemma4_mtp", "Gemma4MTP"),
|
||||
"ErnieMTPModel": ("ernie_mtp", "ErnieMTP"),
|
||||
"ExaoneMoeMTP": ("exaone_moe_mtp", "ExaoneMoeMTP"),
|
||||
@@ -870,10 +871,21 @@ class _LazyRegisteredModel(_BaseRegisteredModel):
|
||||
|
||||
@logtime(logger=logger, msg="Registry inspect model class")
|
||||
def inspect_model_cls(self) -> _ModelInfo:
|
||||
model_path = Path(__file__).parent / f"{self.module_name.split('.')[-1]}.py"
|
||||
# Modules registered with a non-default location (e.g. the
|
||||
# hardware-isolated ``vllm.models.<name>`` layout) live outside
|
||||
# ``vllm/model_executor/models``. Resolve the module spec directly
|
||||
# so the file-hash cache stays warm for them.
|
||||
if self.module_name.startswith("vllm.model_executor.models."):
|
||||
model_path = Path(__file__).parent / f"{self.module_name.split('.')[-1]}.py"
|
||||
else:
|
||||
try:
|
||||
spec = importlib.util.find_spec(self.module_name)
|
||||
except (ImportError, ValueError):
|
||||
spec = None
|
||||
model_path = Path(spec.origin) if spec is not None and spec.origin else None
|
||||
module_hash = None
|
||||
|
||||
if model_path.exists():
|
||||
if model_path is not None and model_path.exists():
|
||||
with open(model_path, "rb") as f:
|
||||
module_hash = safe_hash(f.read(), usedforsecurity=False).hexdigest()
|
||||
|
||||
@@ -1328,10 +1340,19 @@ class _ModelRegistry:
|
||||
return model_cls.supports_transcription_only
|
||||
|
||||
|
||||
def _resolve_module_name(mod_relname: str) -> str:
|
||||
# Allow registry entries to point at fully-qualified module paths (e.g.
|
||||
# ``vllm.models.deepseek_v4``) for models that live outside the legacy
|
||||
# ``vllm.model_executor.models`` flat layout.
|
||||
if mod_relname.startswith("vllm."):
|
||||
return mod_relname
|
||||
return f"vllm.model_executor.models.{mod_relname}"
|
||||
|
||||
|
||||
ModelRegistry = _ModelRegistry(
|
||||
{
|
||||
model_arch: _LazyRegisteredModel(
|
||||
module_name=f"vllm.model_executor.models.{mod_relname}",
|
||||
module_name=_resolve_module_name(mod_relname),
|
||||
class_name=cls_name,
|
||||
)
|
||||
for model_arch, (mod_relname, cls_name) in _VLLM_MODELS.items()
|
||||
|
||||
Reference in New Issue
Block a user