diffusion: fix loading with local model_path (#13445)

This commit is contained in:
Mick
2025-11-18 00:56:30 +08:00
committed by GitHub
parent 7b44526038
commit ff00b6adbe
2 changed files with 81 additions and 81 deletions
@@ -354,12 +354,13 @@ class PipelineConfig:
# 2. Instantiate PipelineConfig # 2. Instantiate PipelineConfig
if model_info is None: if model_info is None:
logger.warning( # The error is already logged in get_model_info.
"Couldn't find model info for %s. Using the default pipeline config.", # We raise an exception here to stop the execution.
model_path, raise ValueError(
f"Failed to get model info for '{model_path}'. "
"Please check the model path and ensure it is registered correctly."
) )
pipeline_config = cls()
else:
pipeline_config = model_info.pipeline_config_cls() pipeline_config = model_info.pipeline_config_cls()
# 3. Load PipelineConfig from a json file or a PipelineConfig object if provided # 3. Load PipelineConfig from a json file or a PipelineConfig object if provided
+74 -75
View File
@@ -11,6 +11,8 @@ import dataclasses
import importlib import importlib
import os import os
import pkgutil import pkgutil
import re
from functools import lru_cache
from typing import Any, Callable, Dict, List, Optional, Tuple, Type from typing import Any, Callable, Dict, List, Optional, Tuple, Type
from sglang.multimodal_gen.configs.pipelines import ( from sglang.multimodal_gen.configs.pipelines import (
@@ -141,8 +143,8 @@ def register_configs(
model_name: str, model_name: str,
sampling_param_cls: Any, sampling_param_cls: Any,
pipeline_config_cls: Type[PipelineConfig], pipeline_config_cls: Type[PipelineConfig],
model_path_to_name_mappings: Optional[Dict[str, str]] = None, model_paths: Optional[List[str]] = None,
model_name_detectors: Optional[List[Tuple[str, Callable[[str], bool]]]] = None, model_detectors: Optional[List[Callable[[str], bool]]] = None,
): ):
""" """
Registers configuration classes for a new model family. Registers configuration classes for a new model family.
@@ -156,16 +158,17 @@ def register_configs(
sampling_param_cls=sampling_param_cls, sampling_param_cls=sampling_param_cls,
pipeline_config_cls=pipeline_config_cls, pipeline_config_cls=pipeline_config_cls,
) )
if model_path_to_name_mappings: if model_paths:
for path, name in model_path_to_name_mappings.items(): for path in model_paths:
if path in _MODEL_PATH_TO_NAME: if path in _MODEL_PATH_TO_NAME:
logger.warning( logger.warning(
f"Model path '{path}' is already mapped to '{_MODEL_PATH_TO_NAME[path]}' and will be overwritten by '{name}'." f"Model path '{path}' is already mapped to '{_MODEL_PATH_TO_NAME[path]}' and will be overwritten by '{model_name}'."
) )
_MODEL_PATH_TO_NAME[path] = name _MODEL_PATH_TO_NAME[path] = model_name
if model_name_detectors: if model_detectors:
_MODEL_NAME_DETECTORS.extend(model_name_detectors) for detector in model_detectors:
_MODEL_NAME_DETECTORS.append((model_name, detector))
def _get_config_info(model_path: str) -> Optional[ConfigInfo]: def _get_config_info(model_path: str) -> Optional[ConfigInfo]:
@@ -175,11 +178,15 @@ def _get_config_info(model_path: str) -> Optional[ConfigInfo]:
# 1. Exact match # 1. Exact match
if model_path in _MODEL_PATH_TO_NAME: if model_path in _MODEL_PATH_TO_NAME:
model_name = _MODEL_PATH_TO_NAME[model_path] model_name = _MODEL_PATH_TO_NAME[model_path]
logger.debug(f"Resolved model name '{model_name}' from exact path match.")
return _CONFIG_REGISTRY.get(model_name) return _CONFIG_REGISTRY.get(model_name)
# 2. Partial match # 2. Partial match: find the best (longest) match against all registered model names.
for registered_id, model_name in _MODEL_PATH_TO_NAME.items(): cleaned_model_path = re.sub(r"--", "/", model_path.lower())
if registered_id in model_path: all_model_names = sorted(_CONFIG_REGISTRY.keys(), key=len, reverse=True)
for model_name in all_model_names:
if model_name in cleaned_model_path:
logger.debug(f"Resolved model name '{model_name}' from partial path match.")
return _CONFIG_REGISTRY.get(model_name) return _CONFIG_REGISTRY.get(model_name)
# 3. Use detectors # 3. Use detectors
@@ -192,6 +199,9 @@ def _get_config_info(model_path: str) -> Optional[ConfigInfo]:
for model_name, detector in _MODEL_NAME_DETECTORS: for model_name, detector in _MODEL_NAME_DETECTORS:
if detector(model_path.lower()) or detector(pipeline_name): if detector(model_path.lower()) or detector(pipeline_name):
logger.debug(
f"Resolved model name '{model_name}' using a registered detector."
)
return _CONFIG_REGISTRY.get(model_name) return _CONFIG_REGISTRY.get(model_name)
return None return None
@@ -212,6 +222,7 @@ class ModelInfo:
pipeline_config_cls: Type[PipelineConfig] pipeline_config_cls: Type[PipelineConfig]
@lru_cache(maxsize=1)
def get_model_info(model_path: str) -> Optional[ModelInfo]: def get_model_info(model_path: str) -> Optional[ModelInfo]:
""" """
Resolves all necessary classes (pipeline, sampling, config) for a given model path. Resolves all necessary classes (pipeline, sampling, config) for a given model path.
@@ -251,16 +262,12 @@ def get_model_info(model_path: str) -> Optional[ModelInfo]:
# 3. Get configuration classes (sampling, pipeline config) # 3. Get configuration classes (sampling, pipeline config)
config_info = _get_config_info(model_path) config_info = _get_config_info(model_path)
if not config_info: if not config_info:
logger.warning( logger.error(
f"No specific configuration registered for '{model_path}'. " f"Could not resolve configuration for model '{model_path}'. "
f"Falling back to default SamplingParams and PipelineConfig." "It is not a registered model path or detected by any registered model family detectors. "
) f"Known model paths: {list(_MODEL_PATH_TO_NAME.keys())}"
# Fallback to defaults if no specific config is found
from sglang.multimodal_gen.configs.sample.base import SamplingParams
config_info = ConfigInfo(
sampling_param_cls=SamplingParams, pipeline_config_cls=PipelineConfig
) )
return None
# 4. Combine and return the complete model info # 4. Combine and return the complete model info
return ModelInfo( return ModelInfo(
@@ -277,18 +284,18 @@ def _register_configs():
model_name="hunyuan", model_name="hunyuan",
sampling_param_cls=HunyuanSamplingParams, sampling_param_cls=HunyuanSamplingParams,
pipeline_config_cls=HunyuanConfig, pipeline_config_cls=HunyuanConfig,
model_path_to_name_mappings={ model_paths=[
"hunyuanvideo-community/HunyuanVideo": "hunyuan", "hunyuanvideo-community/HunyuanVideo",
}, ],
model_name_detectors=[("hunyuan", lambda id: "hunyuan" in id.lower())], model_detectors=[lambda id: "hunyuan" in id.lower()],
) )
register_configs( register_configs(
model_name="fasthunyuan", model_name="fasthunyuan",
sampling_param_cls=FastHunyuanSamplingParam, sampling_param_cls=FastHunyuanSamplingParam,
pipeline_config_cls=FastHunyuanConfig, pipeline_config_cls=FastHunyuanConfig,
model_path_to_name_mappings={ model_paths=[
"FastVideo/FastHunyuan-diffusers": "fasthunyuan", "FastVideo/FastHunyuan-diffusers",
}, ],
) )
# StepVideo # StepVideo
@@ -296,10 +303,10 @@ def _register_configs():
model_name="stepvideo", model_name="stepvideo",
sampling_param_cls=StepVideoT2VSamplingParams, sampling_param_cls=StepVideoT2VSamplingParams,
pipeline_config_cls=StepVideoT2VConfig, pipeline_config_cls=StepVideoT2VConfig,
model_path_to_name_mappings={ model_paths=[
"FastVideo/stepvideo-t2v-diffusers": "stepvideo", "FastVideo/stepvideo-t2v-diffusers",
}, ],
model_name_detectors=[("stepvideo", lambda id: "stepvideo" in id.lower())], model_detectors=[lambda id: "stepvideo" in id.lower()],
) )
# Wan # Wan
@@ -307,88 +314,86 @@ def _register_configs():
model_name="wan-t2v-1.3b", model_name="wan-t2v-1.3b",
sampling_param_cls=WanT2V_1_3B_SamplingParams, sampling_param_cls=WanT2V_1_3B_SamplingParams,
pipeline_config_cls=WanT2V480PConfig, pipeline_config_cls=WanT2V480PConfig,
model_path_to_name_mappings={ model_paths=[
"Wan-AI/Wan2.1-T2V-1.3B-Diffusers": "wan-t2v-1.3b", "Wan-AI/Wan2.1-T2V-1.3B-Diffusers",
}, ],
model_name_detectors=[("wanpipeline", lambda id: "wanpipeline" in id.lower())], model_detectors=[lambda id: "wanpipeline" in id.lower()],
) )
register_configs( register_configs(
model_name="wan-t2v-14b", model_name="wan-t2v-14b",
sampling_param_cls=WanT2V_14B_SamplingParams, sampling_param_cls=WanT2V_14B_SamplingParams,
pipeline_config_cls=WanT2V720PConfig, pipeline_config_cls=WanT2V720PConfig,
model_path_to_name_mappings={ model_paths=[
"Wan-AI/Wan2.1-T2V-14B-Diffusers": "wan-t2v-14b", "Wan-AI/Wan2.1-T2V-14B-Diffusers",
}, ],
) )
register_configs( register_configs(
model_name="wan-i2v-14b-480p", model_name="wan-i2v-14b-480p",
sampling_param_cls=WanI2V_14B_480P_SamplingParam, sampling_param_cls=WanI2V_14B_480P_SamplingParam,
pipeline_config_cls=WanI2V480PConfig, pipeline_config_cls=WanI2V480PConfig,
model_path_to_name_mappings={ model_paths=[
"Wan-AI/Wan2.1-I2V-14B-480P-Diffusers": "wan-i2v-14b-480p", "Wan-AI/Wan2.1-I2V-14B-480P-Diffusers",
},
model_name_detectors=[
("wanimagetovideo", lambda id: "wanimagetovideo" in id.lower())
], ],
model_detectors=[lambda id: "wanimagetovideo" in id.lower()],
) )
register_configs( register_configs(
model_name="wan-i2v-14b-720p", model_name="wan-i2v-14b-720p",
sampling_param_cls=WanI2V_14B_720P_SamplingParam, sampling_param_cls=WanI2V_14B_720P_SamplingParam,
pipeline_config_cls=WanI2V720PConfig, pipeline_config_cls=WanI2V720PConfig,
model_path_to_name_mappings={ model_paths=[
"Wan-AI/Wan2.1-I2V-14B-720P-Diffusers": "wan-i2v-14b-720p", "Wan-AI/Wan2.1-I2V-14B-720P-Diffusers",
}, ],
) )
register_configs( register_configs(
model_name="wan-fun-1.3b-inp", model_name="wan-fun-1.3b-inp",
sampling_param_cls=Wan2_1_Fun_1_3B_InP_SamplingParams, sampling_param_cls=Wan2_1_Fun_1_3B_InP_SamplingParams,
pipeline_config_cls=WanI2V480PConfig, pipeline_config_cls=WanI2V480PConfig,
model_path_to_name_mappings={ model_paths=[
"weizhou03/Wan2.1-Fun-1.3B-InP-Diffusers": "wan-fun-1.3b-inp", "weizhou03/Wan2.1-Fun-1.3B-InP-Diffusers",
}, ],
) )
register_configs( register_configs(
model_name="wan-ti2v-5b", model_name="wan-ti2v-5b",
sampling_param_cls=Wan2_2_TI2V_5B_SamplingParam, sampling_param_cls=Wan2_2_TI2V_5B_SamplingParam,
pipeline_config_cls=Wan2_2_TI2V_5B_Config, pipeline_config_cls=Wan2_2_TI2V_5B_Config,
model_path_to_name_mappings={ model_paths=[
"Wan-AI/Wan2.2-TI2V-5B-Diffusers": "wan-ti2v-5b", "Wan-AI/Wan2.2-TI2V-5B-Diffusers",
}, ],
) )
register_configs( register_configs(
model_name="fastwan-ti2v-5b", model_name="fastwan-ti2v-5b",
sampling_param_cls=Wan2_2_TI2V_5B_SamplingParam, sampling_param_cls=Wan2_2_TI2V_5B_SamplingParam,
pipeline_config_cls=FastWan2_2_TI2V_5B_Config, pipeline_config_cls=FastWan2_2_TI2V_5B_Config,
model_path_to_name_mappings={ model_paths=[
"FastVideo/FastWan2.2-TI2V-5B-FullAttn-Diffusers": "fastwan-ti2v-5b", "FastVideo/FastWan2.2-TI2V-5B-FullAttn-Diffusers",
"FastVideo/FastWan2.2-TI2V-5B-Diffusers": "fastwan-ti2v-5b", "FastVideo/FastWan2.2-TI2V-5B-Diffusers",
}, ],
) )
register_configs( register_configs(
model_name="wan-t2v-a14b", model_name="wan-t2v-a14b",
sampling_param_cls=Wan2_2_T2V_A14B_SamplingParam, sampling_param_cls=Wan2_2_T2V_A14B_SamplingParam,
pipeline_config_cls=Wan2_2_T2V_A14B_Config, pipeline_config_cls=Wan2_2_T2V_A14B_Config,
model_path_to_name_mappings={ model_paths=[
"Wan-AI/Wan2.2-T2V-A14B-Diffusers": "wan-t2v-a14b", "Wan-AI/Wan2.2-T2V-A14B-Diffusers",
}, ],
) )
register_configs( register_configs(
model_name="wan-i2v-a14b", model_name="wan-i2v-a14b",
sampling_param_cls=Wan2_2_I2V_A14B_SamplingParam, sampling_param_cls=Wan2_2_I2V_A14B_SamplingParam,
pipeline_config_cls=Wan2_2_I2V_A14B_Config, pipeline_config_cls=Wan2_2_I2V_A14B_Config,
model_path_to_name_mappings={ model_paths=[
"Wan-AI/Wan2.2-I2V-A14B-Diffusers": "wan-i2v-a14b", "Wan-AI/Wan2.2-I2V-A14B-Diffusers",
}, ],
) )
register_configs( register_configs(
model_name="fast-wan-t2v-1.3b", model_name="fast-wan-t2v-1.3b",
sampling_param_cls=FastWanT2V480PConfig, sampling_param_cls=FastWanT2V480PConfig,
pipeline_config_cls=FastWan2_1_T2V_480P_Config, pipeline_config_cls=FastWan2_1_T2V_480P_Config,
model_path_to_name_mappings={ model_paths=[
"FastVideo/FastWan2.1-T2V-1.3B-Diffusers": "fast-wan-t2v-1.3b", "FastVideo/FastWan2.1-T2V-1.3B-Diffusers",
}, ],
) )
# FLUX # FLUX
@@ -396,10 +401,10 @@ def _register_configs():
model_name="flux", model_name="flux",
sampling_param_cls=FluxSamplingParams, sampling_param_cls=FluxSamplingParams,
pipeline_config_cls=FluxPipelineConfig, pipeline_config_cls=FluxPipelineConfig,
model_path_to_name_mappings={ model_paths=[
"black-forest-labs/FLUX.1-dev": "flux", "black-forest-labs/FLUX.1-dev",
}, ],
model_name_detectors=[("flux", lambda id: "flux" in id.lower())], model_detectors=[lambda id: "flux" in id.lower()],
) )
# Qwen-Image # Qwen-Image
@@ -407,17 +412,11 @@ def _register_configs():
model_name="qwen-image", model_name="qwen-image",
sampling_param_cls=QwenImageSamplingParams, sampling_param_cls=QwenImageSamplingParams,
pipeline_config_cls=QwenImagePipelineConfig, pipeline_config_cls=QwenImagePipelineConfig,
model_path_to_name_mappings={
"Qwen/Qwen-Image": "qwen-image",
},
) )
register_configs( register_configs(
model_name="qwen-image-edit", model_name="qwen-image-edit",
sampling_param_cls=QwenImageSamplingParams, sampling_param_cls=QwenImageSamplingParams,
pipeline_config_cls=QwenImageEditPipelineConfig, pipeline_config_cls=QwenImageEditPipelineConfig,
model_path_to_name_mappings={
"Qwen/Qwen-Image-Edit": "qwen-image-edit",
},
) )