[Refactor]Base class for dit pipelines with unified parameter declaration[1/N] (#4225)
Signed-off-by: princepride <wangzhipeng628@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
26 files changed
+1026
-1586
No files matched your search
@@ -423,6 +423,67 @@ class DiffusionCacheConfig:
|
||||
raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{item}'")
|
||||
|
||||
|
||||
def resolve_model_class_name(model: str | None, diffusion_load_format: str = "default") -> str | None:
|
||||
"""Resolve the diffusion pipeline class name from the model config.
|
||||
|
||||
Read-only counterpart of ``OmniDiffusionConfig.enrich_config``, safe to call
|
||||
client-side. Returns ``None`` if the pipeline can't be determined.
|
||||
"""
|
||||
from vllm.transformers_utils.config import get_hf_file_to_dict
|
||||
|
||||
if not model:
|
||||
return None
|
||||
|
||||
is_lance_subfolder = os.path.basename(str(model).rstrip("/")) in {"Lance_3B", "Lance_3B_Video"}
|
||||
|
||||
# Diffusers models: read _class_name from model_index.json.
|
||||
try:
|
||||
model_index = get_hf_file_to_dict("model_index.json", model)
|
||||
except Exception:
|
||||
model_index = None
|
||||
if model_index is not None:
|
||||
return model_index.get("_class_name")
|
||||
if diffusion_load_format == "diffusers":
|
||||
return "DiffusersAdapterPipeline"
|
||||
|
||||
# Other models: map model_type / architecture from config.json.
|
||||
try:
|
||||
cfg = get_hf_file_to_dict("config.json", model) or {}
|
||||
except Exception:
|
||||
cfg = {}
|
||||
model_type = cfg.get("model_type")
|
||||
architectures = cfg.get("architectures") or []
|
||||
|
||||
if model_type == "bagel" or "BagelForConditionalGeneration" in architectures:
|
||||
return "BagelPipeline"
|
||||
if (
|
||||
model_type == "lance"
|
||||
or "LancePipeline" in architectures
|
||||
or cfg.get("model_name") == "Lance"
|
||||
or is_lance_subfolder
|
||||
):
|
||||
return "LancePipeline"
|
||||
if model_type == "neo_chat":
|
||||
return "SenseNovaU1Pipeline"
|
||||
if "BailingMM2NativeForConditionalGeneration" in architectures or model_type in (
|
||||
"bailingmm_moe_v2_lite",
|
||||
"ming_flash_omni",
|
||||
"ming_flash_omni_thinker",
|
||||
):
|
||||
return "MingImagePipeline"
|
||||
if model_type == "nextstep":
|
||||
return "NextStep11Pipeline"
|
||||
if model_type == "s2v":
|
||||
return "WanS2VPipeline"
|
||||
if model_type == "vla":
|
||||
from vllm_omni.diffusion.utils.hf_utils import _looks_like_dreamzero
|
||||
|
||||
return "DreamZeroPipeline" if _looks_like_dreamzero(model) else None
|
||||
if len(architectures) == 1:
|
||||
return architectures[0]
|
||||
return None
|
||||
|
||||
|
||||
@dataclass
|
||||
class OmniDiffusionConfig:
|
||||
# Model and path configuration (for convenience)
|
||||
|
||||
@@ -27,8 +27,6 @@ from vllm_omni.diffusion.data import (
|
||||
from vllm_omni.diffusion.executor.abstract import DiffusionExecutor
|
||||
from vllm_omni.diffusion.io_support import (
|
||||
get_dummy_run_num_frames,
|
||||
get_extra_body_params,
|
||||
get_extra_output_params,
|
||||
image_color_format,
|
||||
supports_audio_output,
|
||||
supports_multimodal_input,
|
||||
@@ -61,8 +59,6 @@ __all__ = [
|
||||
"_RpcTask",
|
||||
"_move_tensor_tree_to_cpu",
|
||||
"get_dummy_run_num_frames",
|
||||
"get_extra_body_params",
|
||||
"get_extra_output_params",
|
||||
"image_color_format",
|
||||
"supports_audio_output",
|
||||
"supports_multimodal_input",
|
||||
|
||||
@@ -47,31 +47,3 @@ def get_dummy_run_num_frames(model_class_name: str, supports_audio_input: bool)
|
||||
if model_cls is not None and hasattr(model_cls, "dummy_run_num_frames"):
|
||||
return int(getattr(model_cls, "dummy_run_num_frames"))
|
||||
return 2 if supports_audio_input or supports_audio_output(model_class_name) else 1
|
||||
|
||||
|
||||
def get_extra_body_params(model_class_name: str) -> frozenset[str]:
|
||||
"""Return the set of extra_body keys accepted by a pipeline.
|
||||
|
||||
Each pipeline can declare ``EXTRA_BODY_PARAMS: ClassVar[frozenset[str]]``
|
||||
to advertise which request-level parameters should be forwarded from
|
||||
``extra_body`` to ``OmniDiffusionSamplingParams.extra_args``.
|
||||
Returns an empty frozenset when the pipeline does not declare any.
|
||||
"""
|
||||
model_cls = DiffusionModelRegistry._try_load_model_cls(model_class_name)
|
||||
if model_cls is None:
|
||||
return frozenset()
|
||||
return frozenset(getattr(model_cls, "EXTRA_BODY_PARAMS", frozenset()))
|
||||
|
||||
|
||||
def get_extra_output_params(model_class_name: str) -> frozenset[str]:
|
||||
"""Return the set of custom_output keys to expose in API response metrics.
|
||||
|
||||
Each pipeline can declare ``EXTRA_OUTPUT_PARAMS: ClassVar[frozenset[str]]``
|
||||
to advertise which ``DiffusionOutput.custom_output`` keys should be
|
||||
copied into the response ``metrics`` dict.
|
||||
Returns an empty frozenset when the pipeline does not declare any.
|
||||
"""
|
||||
model_cls = DiffusionModelRegistry._try_load_model_cls(model_class_name)
|
||||
if model_cls is None:
|
||||
return frozenset()
|
||||
return frozenset(getattr(model_cls, "EXTRA_OUTPUT_PARAMS", frozenset()))
|
||||
@@ -504,30 +504,6 @@ class SenseNovaU1Pipeline(nn.Module, SupportsComponentDiscovery, DiffusionPipeli
|
||||
|
||||
support_image_input = True
|
||||
|
||||
# Model-specific parameters accepted via ``extra_body`` in the online
|
||||
# serving API. The serving layer reads this set and forwards matching
|
||||
# keys from the request payload to ``OmniDiffusionSamplingParams.extra_args``.
|
||||
EXTRA_BODY_PARAMS: ClassVar[frozenset[str]] = frozenset(
|
||||
{
|
||||
"think",
|
||||
"cfg_scale",
|
||||
"cfg_norm",
|
||||
"timestep_shift",
|
||||
"t_eps",
|
||||
"img_cfg_scale",
|
||||
"max_tokens",
|
||||
}
|
||||
)
|
||||
|
||||
# Keys from ``DiffusionOutput.custom_output`` that should be surfaced in
|
||||
# the API response ``metrics`` dict. The serving layer reads this set and
|
||||
# copies matching entries from ``custom_output`` into the response.
|
||||
EXTRA_OUTPUT_PARAMS: ClassVar[frozenset[str]] = frozenset(
|
||||
{
|
||||
"think_text",
|
||||
}
|
||||
)
|
||||
|
||||
# CPU-offload protocol: language_model carries the denoising blocks; the
|
||||
# vision and FM modules are lightweight encoders pinned on GPU during the
|
||||
# diffusion loop. There is no separate VAE.
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from vllm_omni.inputs.data import OmniDiffusionSamplingParams
|
||||
|
||||
|
||||
def apply_declared_extra_args(
|
||||
sampling_params: OmniDiffusionSamplingParams,
|
||||
declared_params: frozenset[str],
|
||||
user_kwargs: dict[str, object],
|
||||
) -> None:
|
||||
"""Route pipeline-declared request params into ``sampling_params.extra_args``.
|
||||
|
||||
Both online serving and offline examples call this so that model-specific
|
||||
keys (e.g. ``cfg_text_scale`` for BAGEL) end up in ``extra_args`` instead
|
||||
of being silently dropped.
|
||||
|
||||
This is a no-op when no declared params are present in ``user_kwargs``, so
|
||||
it is safe to call on non-diffusion (e.g. AR) sampling params whose
|
||||
``extra_args`` defaults to ``None``.
|
||||
"""
|
||||
declared = {key: user_kwargs[key] for key in declared_params if user_kwargs.get(key) is not None}
|
||||
if not declared:
|
||||
return
|
||||
sampling_params.extra_args = {**(sampling_params.extra_args or {}), **declared}
|
||||
Reference in new issue
Block a user