[Model][Feat] Support Minimax-H3 quality grading requests through dynamic loading/unloading with Cache-DiT (#5853)

Signed-off-by: mglyn <1203789601@qq.com>
This commit is contained in:
Mu GuanLin authored and GitHub committed 2026-08-07 09:07:23 +00:00
1 parent e906f41dc8
commit d8c35663b4
28 files changed
+1183 -18

No files matched your search

+29
View File
@@ -17,6 +17,7 @@ if TYPE_CHECKING:
import torch
from vllm_omni.diffusion.cache.cachedit import CacheDiTBackend
from vllm_omni.diffusion.data import DiffusionOutput
from vllm_omni.diffusion.worker.input_batch import InputBatch
from vllm_omni.diffusion.worker.utils import StepRequestState
@@ -131,3 +132,31 @@ def supports_prompt_update(pipeline: object) -> bool:
"""Return whether ``pipeline`` implements :class:`SupportsPromptUpdate`."""
return isinstance(pipeline, SupportsPromptUpdate)
@runtime_checkable
class SupportsRequestScopedCacheDiT(Protocol):
"""Optional protocol for pipelines that own Cache-DiT hook transitions."""
def adopt_cache_dit_backend(self, backend: CacheDiTBackend) -> None:
"""Assume ownership of an enabled Cache-DiT backend."""
...
def is_cache_dit_enabled(self) -> bool:
"""Return whether this pipeline currently has Cache-DiT installed."""
...
def adopt_request_scoped_cache_dit(pipeline: object, backend: CacheDiTBackend) -> bool:
"""Transfer an enabled Cache-DiT backend to an opted-in pipeline."""
if not isinstance(pipeline, SupportsRequestScopedCacheDiT):
return False
pipeline.adopt_cache_dit_backend(backend)
return True
def is_request_scoped_cache_dit_enabled(pipeline: object) -> bool:
"""Read Cache-DiT state from a pipeline that owns its lifecycle."""
return isinstance(pipeline, SupportsRequestScopedCacheDiT) and pipeline.is_cache_dit_enabled()
@@ -22,6 +22,10 @@ from transformers import Qwen2TokenizerFast, Qwen3VLProcessor
from vllm.logger import init_logger
from vllm_omni.diffusion import envs
from vllm_omni.diffusion.cache.cachedit import (
CacheDiTBackend,
RequestScopedCacheDiTRuntime,
)
from vllm_omni.diffusion.data import DiffusionOutput, OmniDiffusionConfig
from vllm_omni.diffusion.distributed.parallel_state import (
get_dit_group,
@@ -73,6 +77,7 @@ from .presentation import (
minimax_h3_ref2va_video_presentation,
minimax_h3_text_only_ids,
)
from .quality_policy import MINIMAX_H3_GENERIC_CACHE_KEY, MiniMaxH3QualityPolicy
from .reference_video import (
load_audio_file,
load_video_audio,
@@ -538,6 +543,19 @@ class MiniMaxH3Pipeline(
]
dummy_run_num_frames: ClassVar[int] = 0
def adopt_cache_dit_backend(self, backend: CacheDiTBackend) -> None:
"""Adopt runner-installed generic Cache-DiT for request transitions."""
self._cache_dit_runtime.adopt(
backend,
installation_key=MINIMAX_H3_GENERIC_CACHE_KEY,
)
def is_cache_dit_enabled(self) -> bool:
"""Return the request-scoped Cache-DiT installation state."""
return self._cache_dit_runtime.is_enabled
def __init__(
self,
*,
@@ -676,6 +694,9 @@ class MiniMaxH3Pipeline(
# Registry-side VAE patch-parallel discovery uses ``pipeline.vae``.
self.vae = self.video_vae
self._quality_policy = MiniMaxH3QualityPolicy(od_config)
self._cache_dit_runtime = RequestScopedCacheDiTRuntime(self)
self.setup_diffusion_pipeline_profiler(
enable_diffusion_pipeline_profiler=(od_config.enable_diffusion_pipeline_profiler)
)
@@ -1551,6 +1572,8 @@ class MiniMaxH3Pipeline(
raise OmniClientError("MiniMax H3 requires a non-empty prompt")
sampling = request.sampling_params
quality = sampling.quality
logger.debug("MiniMax H3 request quality=%s", quality)
extra = sampling.extra_args or {}
task = self._resolve_task(extra.get("task"), multi_modal_data)
@@ -1732,6 +1755,12 @@ class MiniMaxH3Pipeline(
num_steps = int(sampling.num_inference_steps or 50)
video_shift = float(extra.get("flow_shift", self.default_video_shift))
audio_shift = float(extra.get("audio_flow_shift", self.default_audio_shift))
quality_plan = self._quality_policy.resolve(
quality=quality,
num_inference_steps=num_steps,
extra_args=extra,
)
self._cache_dit_runtime.prepare(quality_plan.cache_dit)
num_outputs = _resolve_minimax_h3_num_outputs(sampling.num_outputs_per_prompt)
videos = []
audios = []
@@ -0,0 +1,178 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Model-owned request quality policy for MiniMax H3."""
from __future__ import annotations
from collections.abc import Mapping
from dataclasses import dataclass, replace
from numbers import Integral
from typing import Any
from vllm_omni.diffusion.cache.cachedit import CacheDiTRequestSpec
from vllm_omni.diffusion.data import DiffusionCacheConfig
from vllm_omni.errors import OmniClientError
MINIMAX_H3_GENERIC_CACHE_KEY = "minimax_h3.generic"
MINIMAX_H3_HIGH_CACHE_KEY = "minimax_h3.high"
MINIMAX_H3_FORCE_REFRESH_STEP_HINT_ARG = "force_refresh_step_hint"
MINIMAX_H3_FORCE_REFRESH_STEP_POLICY_ARG = "force_refresh_step_policy"
MINIMAX_H3_FORCE_REFRESH_POLICIES = ("once", "repeat")
def _high_quality_cache_config() -> DiffusionCacheConfig:
return DiffusionCacheConfig(
Fn_compute_blocks=1,
Bn_compute_blocks=0,
max_warmup_steps=4,
residual_diff_threshold=0.04,
max_continuous_cached_steps=1,
enable_taylorseer=False,
scm_steps_mask_policy=None,
)
def _resolve_force_refresh(
extra_args: Mapping[str, Any] | None,
*,
num_inference_steps: int,
) -> tuple[int, str] | None:
"""Resolve H3's request-scoped Cache-DiT refresh hint.
These are model-specific ``extra_args`` rather than global sampling fields,
keeping other diffusion models unchanged.
"""
if not extra_args:
return None
raw_hint = extra_args.get(MINIMAX_H3_FORCE_REFRESH_STEP_HINT_ARG)
raw_policy = extra_args.get(MINIMAX_H3_FORCE_REFRESH_STEP_POLICY_ARG)
if raw_hint is None:
if raw_policy is not None:
raise OmniClientError("MiniMax H3 force_refresh_step_policy requires force_refresh_step_hint")
return None
if isinstance(raw_hint, bool) or not isinstance(raw_hint, Integral):
raise OmniClientError("MiniMax H3 force_refresh_step_hint must be a positive integer")
hint = int(raw_hint)
if not 1 <= hint <= num_inference_steps:
raise OmniClientError(
"MiniMax H3 force_refresh_step_hint must be between 1 and "
f"num_inference_steps ({num_inference_steps}), got {hint}"
)
policy = "once" if raw_policy is None else raw_policy
if not isinstance(policy, str) or policy not in MINIMAX_H3_FORCE_REFRESH_POLICIES:
raise OmniClientError(
"MiniMax H3 force_refresh_step_policy must be one of "
f"{list(MINIMAX_H3_FORCE_REFRESH_POLICIES)}, got {policy!r}"
)
return hint, policy
def _has_force_refresh_args(extra_args: Mapping[str, Any] | None) -> bool:
if not extra_args:
return False
return any(
extra_args.get(name) is not None
for name in (
MINIMAX_H3_FORCE_REFRESH_STEP_HINT_ARG,
MINIMAX_H3_FORCE_REFRESH_STEP_POLICY_ARG,
)
)
def _with_force_refresh(
cache_config: DiffusionCacheConfig,
force_refresh: tuple[int, str] | None,
) -> DiffusionCacheConfig:
if force_refresh is None:
return cache_config
hint, policy = force_refresh
return replace(
cache_config,
force_refresh_step_hint=hint,
force_refresh_step_policy=policy,
)
def _cache_installation_key(base_key: str, force_refresh: tuple[int, str] | None) -> str:
"""Make refresh-policy transitions explicit to the request runtime.
Cache-DiT cannot clear an existing ``force_refresh_step_hint`` through its
incremental context update API because ``None`` is treated as "keep the
old value". Including the request hint in the installation key therefore
makes a hint change perform a safe hook reinstall, while repeated requests
with the same hint still only refresh the context.
"""
if force_refresh is None:
return base_key
hint, policy = force_refresh
return f"{base_key}:force_refresh={hint}:{policy}"
@dataclass(frozen=True)
class MiniMaxH3QualityPlan:
"""Resolved execution choices for one MiniMax H3 request."""
cache_dit: CacheDiTRequestSpec | None
class MiniMaxH3QualityPolicy:
"""Resolve H3 request quality into a declarative Cache-DiT target.
When the server starts with Cache-DiT, omitted quality selects the
server-configured profile. Otherwise, omitted quality selects no cache.
In either case, ``lossless`` selects no cache and ``high`` selects H3's
high-quality profile. The policy therefore owns whether a request installs
Cache-DiT; the startup backend only controls the omitted-quality default.
H3-specific Cache-DiT refresh hints are read from request ``extra_args``;
they do not change the global diffusion request contract.
The pipeline owns applying the resulting target at the request boundary.
"""
def __init__(self, od_config: Any) -> None:
self._od_config = od_config
self._configured_backend = str(getattr(od_config, "cache_backend", "none") or "none").lower()
def resolve(
self,
*,
quality: str | None,
num_inference_steps: int,
extra_args: Mapping[str, Any] | None = None,
) -> MiniMaxH3QualityPlan:
if quality == "high":
base_key = MINIMAX_H3_HIGH_CACHE_KEY
base_config = _high_quality_cache_config()
elif self._configured_backend == "cache_dit" and quality is None:
base_key = MINIMAX_H3_GENERIC_CACHE_KEY
base_config = self._od_config.cache_config
else:
if _has_force_refresh_args(extra_args):
raise OmniClientError("MiniMax H3 force-refresh arguments require an active Cache-DiT request target")
return MiniMaxH3QualityPlan(cache_dit=None)
force_refresh = _resolve_force_refresh(
extra_args,
num_inference_steps=num_inference_steps,
)
return MiniMaxH3QualityPlan(
cache_dit=CacheDiTRequestSpec(
installation_key=_cache_installation_key(base_key, force_refresh),
cache_config=_with_force_refresh(base_config, force_refresh),
num_inference_steps=num_inference_steps,
),
)
__all__ = [
"MINIMAX_H3_GENERIC_CACHE_KEY",
"MINIMAX_H3_HIGH_CACHE_KEY",
"MiniMaxH3QualityPlan",
"MiniMaxH3QualityPolicy",
]