[BugFix] Allow model_loader_extra_config with remote_instance + modelexpress backend (#34639)

Signed-off-by: joeltg <joel@reflection.ai>
Co-authored-by: mmangkad <176301910+mmangkad@users.noreply.github.com>
This commit is contained in:
Joel Gustafson
2026-08-29 00:43:10 -07:00
committed by GitHub
co-authored by mmangkad
parent 78eef34356
commit 0a585d5bb1
2 changed files with 124 additions and 22 deletions
+47 -22
View File
@@ -333,6 +333,28 @@ class BaseModelLoader(ABC):
raise NotImplementedError
def _validate_default_loader_extra_config(
*, extra_config: dict, load_format: LoadFormat
) -> None:
allowed_keys = {"enable_multithread_load", "num_threads"}
if load_format == LoadFormat.FASTSAFETENSORS:
allowed_keys.add("enable_gds")
if "enable_gds" in extra_config and not isinstance(
extra_config["enable_gds"], bool
):
raise ValueError(
"enable_gds in --model-loader-extra-config must be a boolean"
)
unexpected_keys = set(extra_config.keys()) - allowed_keys
if unexpected_keys:
raise ValueError(
f"Unexpected extra config keys for load format "
f"{load_format}: "
f"{unexpected_keys}"
)
class DefaultModelLoader(BaseModelLoader):
"""Model loader that can load different file types from disk."""
@@ -384,24 +406,10 @@ class DefaultModelLoader(BaseModelLoader):
def __init__(self, load_config: LoadConfig):
super().__init__(load_config)
extra_config = load_config.model_loader_extra_config
allowed_keys = {"enable_multithread_load", "num_threads"}
if load_config.load_format == LoadFormat.FASTSAFETENSORS:
allowed_keys.add("enable_gds")
if "enable_gds" in extra_config and not isinstance(
extra_config["enable_gds"], bool
):
raise ValueError(
"enable_gds in --model-loader-extra-config must be a boolean"
)
unexpected_keys = set(extra_config.keys()) - allowed_keys
if unexpected_keys:
raise ValueError(
f"Unexpected extra config keys for load format "
f"{load_config.load_format}: "
f"{unexpected_keys}"
)
_validate_default_loader_extra_config(
extra_config=load_config.model_loader_extra_config,
load_format=load_config.load_format,
)
def _maybe_download_from_modelscope(
self, model: str, revision: Optional[str]
@@ -3230,10 +3238,27 @@ class RemoteInstanceModelLoader(BaseModelLoader):
def __init__(self, load_config: LoadConfig):
super().__init__(load_config)
if load_config.model_loader_extra_config:
raise ValueError(
f"Model loader extra config is not supported for "
f"load format {load_config.load_format}"
)
if (
load_config.remote_instance_weight_loader_backend
== RemoteInstanceWeightLoaderBackend.MODELEXPRESS
):
# ModelExpress falls back to a DefaultModelLoader whenever no
# peer holds the weights, so it consumes this config; validate
# the keys here so a bad one fails on every rank instead of only
# on the ranks that end up taking the fallback.
_validate_default_loader_extra_config(
extra_config=load_config.model_loader_extra_config,
load_format=load_config.load_format,
)
else:
# nccl and transfer_engine replace the native loader outright,
# so nothing would ever read the config.
raise ValueError(
f"Model loader extra config is not supported for "
f"load format {load_config.load_format} with "
f"remote instance weight loader backend "
f"{load_config.remote_instance_weight_loader_backend}"
)
self.remote_instance_transfer_engine_weight_info = None
def download_model(self, model_config: ModelConfig) -> None: