class ModelExpressModelLoader(BaseModelLoader):
"""Thin vLLM loader wrapper for ModelExpress."""
def __init__(self, load_config: LoadConfig):
super().__init__(load_config)
self._loader = self._load_modelexpress_loader(load_config)
@staticmethod
def _load_modelexpress_loader(load_config: LoadConfig) -> BaseModelLoader:
try:
module = importlib.import_module(_MODELEXPRESS_LOADER_MODULE)
except ModuleNotFoundError as exc:
if exc.name not in _MISSING_MODELEXPRESS_MODULES:
raise
raise _missing_modelexpress_error() from exc
ModelExpressVllmLoader = module.MxModelLoader
return ModelExpressVllmLoader(load_config)
def download_model(self, model_config: ModelConfig) -> None:
self._loader.download_model(model_config)
def load_weights(self, model: nn.Module, model_config: ModelConfig) -> None:
self._loader.load_weights(model, model_config)
def on_sleep(self, level: int) -> None:
if hasattr(self._loader, "on_sleep"):
self._loader.on_sleep(level)
def on_wake_up(self, tags: list[str] | None) -> None:
if hasattr(self._loader, "on_wake_up"):
self._loader.on_wake_up(tags)
def reload_model(
self,
vllm_config: VllmConfig,
model_config: ModelConfig,
model: nn.Module,
*,
is_checkpoint_format: bool = True,
) -> None:
if not hasattr(self._loader, "reload_model"):
super().reload_model(
vllm_config,
model_config,
model,
is_checkpoint_format=is_checkpoint_format,
)
return
self._loader.reload_model(
vllm_config=vllm_config,
model_config=model_config,
model=model,
)
@instrument(span_name="Load model")
def load_model(
self,
vllm_config: VllmConfig,
model_config: ModelConfig,
prefix: str = "",
) -> nn.Module:
model = self._loader.load_model(
vllm_config=vllm_config,
model_config=model_config,
prefix=prefix,
)
model = model.eval()
bind_model_loader(model, self)
return model