[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:
1 parent
e906f41dc8
commit
d8c35663b4
28 files changed
+1183
-18
No files matched your search
@@ -20,6 +20,10 @@ from vllm_omni.diffusion.cache.cachedit.model_specific import (
|
||||
from vllm_omni.diffusion.cache.cachedit.model_specific import (
|
||||
register_custom_dit_enablers as _register_custom_dit_enablers,
|
||||
)
|
||||
from vllm_omni.diffusion.cache.cachedit.runtime import (
|
||||
CacheDiTRequestSpec,
|
||||
RequestScopedCacheDiTRuntime,
|
||||
)
|
||||
|
||||
_register_custom_dit_enablers()
|
||||
|
||||
@@ -29,6 +33,8 @@ __all__ = [
|
||||
"CacheDiTAdapterConfig",
|
||||
"CacheDiTBackend",
|
||||
"CacheDiTConfig",
|
||||
"CacheDiTRequestSpec",
|
||||
"RequestScopedCacheDiTRuntime",
|
||||
"SensenovaCachedAdapter",
|
||||
"cache_summary",
|
||||
"enable_cache_for_dit",
|
||||
|
||||
+51
-9
@@ -99,19 +99,37 @@ def _build_cache_context_refresh(
|
||||
# Cache-DiT has no predefined SCM mask for these small step counts.
|
||||
scm_supported_steps = num_inference_steps >= 8 or num_inference_steps in (4, 6)
|
||||
if projected_config.scm_steps_mask_policy is None or not scm_supported_steps:
|
||||
if projected_config.force_refresh_step_hint is not None:
|
||||
# Cache-DiT's ``once`` policy clears the hint after it fires.
|
||||
# Reapply it at every request boundary so a repeated request
|
||||
# with the same configured policy receives the same behavior.
|
||||
cache_dit.refresh_context(
|
||||
transformer,
|
||||
cache_config=DBCacheConfig().reset(
|
||||
num_inference_steps=num_inference_steps,
|
||||
force_refresh_step_hint=projected_config.force_refresh_step_hint,
|
||||
force_refresh_step_policy=projected_config.force_refresh_step_policy,
|
||||
),
|
||||
verbose=verbose,
|
||||
)
|
||||
return
|
||||
cache_dit.refresh_context(transformer, num_inference_steps=num_inference_steps, verbose=verbose)
|
||||
return
|
||||
|
||||
refresh_config = DBCacheConfig().reset(
|
||||
num_inference_steps=num_inference_steps,
|
||||
steps_computation_mask=cache_dit.steps_mask(
|
||||
mask_policy=projected_config.scm_steps_mask_policy,
|
||||
total_steps=num_inference_steps,
|
||||
),
|
||||
steps_computation_policy=projected_config.scm_steps_policy,
|
||||
)
|
||||
if projected_config.force_refresh_step_hint is not None:
|
||||
refresh_config.force_refresh_step_hint = projected_config.force_refresh_step_hint
|
||||
refresh_config.force_refresh_step_policy = projected_config.force_refresh_step_policy
|
||||
cache_dit.refresh_context(
|
||||
transformer,
|
||||
cache_config=DBCacheConfig().reset(
|
||||
num_inference_steps=num_inference_steps,
|
||||
steps_computation_mask=cache_dit.steps_mask(
|
||||
mask_policy=projected_config.scm_steps_mask_policy,
|
||||
total_steps=num_inference_steps,
|
||||
),
|
||||
steps_computation_policy=projected_config.scm_steps_policy,
|
||||
),
|
||||
cache_config=refresh_config,
|
||||
verbose=verbose,
|
||||
)
|
||||
|
||||
@@ -227,19 +245,23 @@ class CacheDiTBackend(CacheBackend):
|
||||
|
||||
super().__init__(config)
|
||||
self._refresh_funcs: list[RefreshCacheContextFunc] = []
|
||||
self._cache_targets: list[Any] = []
|
||||
|
||||
def enable(self, pipeline: SupportsComponentDiscovery) -> None:
|
||||
pipeline_name = type(pipeline).__name__
|
||||
custom_enabler = CUSTOM_DIT_ENABLERS.get(pipeline_name)
|
||||
self._refresh_funcs = []
|
||||
self._cache_targets = []
|
||||
if custom_enabler is not None:
|
||||
logger.info("Using custom cache-dit enabler for model: %s", pipeline_name)
|
||||
self._refresh_funcs = [custom_enabler(pipeline, self.config)]
|
||||
self._cache_targets = [_default_get_pipeline_transformer(pipeline)]
|
||||
else:
|
||||
self._refresh_funcs = []
|
||||
for name in _dit_module_names(pipeline):
|
||||
get_transformer = _make_pipeline_transformer_getter(name)
|
||||
block_adapter = _maybe_build_block_adapter(pipeline, get_transformer)
|
||||
adapter_cls = _maybe_get_cached_adapter_cls(pipeline, get_transformer)
|
||||
cache_target = get_transformer(pipeline) if block_adapter is None else block_adapter
|
||||
self._refresh_funcs.append(
|
||||
enable_cache_for_dit(
|
||||
pipeline,
|
||||
@@ -249,12 +271,32 @@ class CacheDiTBackend(CacheBackend):
|
||||
get_transformer,
|
||||
)
|
||||
)
|
||||
self._cache_targets.append(cache_target)
|
||||
if not self._refresh_funcs:
|
||||
raise ValueError(f"Pipeline {pipeline_name} has no declared DiT modules for Cache-DiT")
|
||||
|
||||
self.enabled = True
|
||||
logger.info("Cache-dit enabled successfully on %s", pipeline_name)
|
||||
|
||||
def disable(self, pipeline: SupportsComponentDiscovery) -> None:
|
||||
"""Remove Cache-DiT hooks so later requests use native forwards."""
|
||||
|
||||
if not self.enabled:
|
||||
return
|
||||
|
||||
logger.info(
|
||||
"Disabling cache-dit on %d DiT target(s) for %s",
|
||||
len(self._cache_targets),
|
||||
type(pipeline).__name__,
|
||||
)
|
||||
try:
|
||||
for target in self._cache_targets:
|
||||
cache_dit.disable_cache(target)
|
||||
finally:
|
||||
self._refresh_funcs = []
|
||||
self._cache_targets = []
|
||||
self.enabled = False
|
||||
|
||||
def refresh(self, pipeline: SupportsComponentDiscovery, num_inference_steps: int, verbose: bool = True) -> None:
|
||||
if not self.enabled or not self._refresh_funcs:
|
||||
logger.warning("Cache-dit is not enabled. Cannot refresh cache context.")
|
||||
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
"""Declarative request-scoped Cache-DiT lifecycle."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from vllm_omni.diffusion.cache.cachedit.backend import CacheDiTBackend
|
||||
from vllm_omni.diffusion.data import DiffusionCacheConfig
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class CacheDiTRequestSpec:
|
||||
"""Desired Cache-DiT state for one request.
|
||||
|
||||
``installation_key`` identifies configurations that require reinstalling
|
||||
hooks when switching between them. Step-count changes only require a
|
||||
context refresh.
|
||||
"""
|
||||
|
||||
installation_key: str
|
||||
cache_config: DiffusionCacheConfig
|
||||
num_inference_steps: int
|
||||
|
||||
|
||||
class RequestScopedCacheDiTRuntime:
|
||||
"""Reconcile declarative request state with installed Cache-DiT hooks."""
|
||||
|
||||
def __init__(self, pipeline: Any) -> None:
|
||||
self._pipeline = pipeline
|
||||
self._backend: CacheDiTBackend | None = None
|
||||
self._installation_key: str | None = None
|
||||
|
||||
@property
|
||||
def is_enabled(self) -> bool:
|
||||
return self._backend is not None and self._backend.is_enabled()
|
||||
|
||||
def adopt(self, backend: CacheDiTBackend, *, installation_key: str) -> None:
|
||||
"""Assume ownership of an already-enabled startup backend."""
|
||||
|
||||
if self._backend is not None:
|
||||
if self._backend is backend and self._installation_key == installation_key:
|
||||
return
|
||||
raise RuntimeError(
|
||||
f"Cache-DiT is already installed with key {self._installation_key!r}; cannot adopt {installation_key!r}"
|
||||
)
|
||||
if not backend.is_enabled():
|
||||
raise ValueError("Cannot adopt a Cache-DiT backend before it is enabled")
|
||||
|
||||
self._backend = backend
|
||||
self._installation_key = installation_key
|
||||
|
||||
def prepare(self, spec: CacheDiTRequestSpec | None) -> None:
|
||||
"""Apply the minimal transition needed before the request denoise.
|
||||
|
||||
``None`` disables installed hooks. An unchanged installation key only
|
||||
refreshes request context; a changed key disables the previous hooks
|
||||
before installing the requested profile.
|
||||
"""
|
||||
|
||||
desired_key = None if spec is None else spec.installation_key
|
||||
if self._installation_key != desired_key:
|
||||
self.disable()
|
||||
|
||||
if spec is None:
|
||||
return
|
||||
|
||||
if self._backend is None:
|
||||
backend = CacheDiTBackend(spec.cache_config)
|
||||
backend.enable(self._pipeline)
|
||||
self.adopt(backend, installation_key=spec.installation_key)
|
||||
|
||||
assert self._backend is not None
|
||||
self._backend.refresh(
|
||||
self._pipeline,
|
||||
num_inference_steps=spec.num_inference_steps,
|
||||
)
|
||||
|
||||
def disable(self) -> None:
|
||||
try:
|
||||
if self._backend is not None:
|
||||
self._backend.disable(self._pipeline)
|
||||
finally:
|
||||
self._backend = None
|
||||
self._installation_key = None
|
||||
|
||||
|
||||
__all__ = [
|
||||
"CacheDiTRequestSpec",
|
||||
"RequestScopedCacheDiTRuntime",
|
||||
]
|
||||
@@ -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",
|
||||
]
|
||||
@@ -55,6 +55,10 @@ class StepBatchSamplingParamsKey:
|
||||
true_cfg_scale: float | None = None
|
||||
cfg_normalize: bool = False
|
||||
|
||||
# Request-scoped execution policy. A batch must use one quality mode
|
||||
# because model acceleration hooks are shared by the whole worker batch.
|
||||
quality: str | None = None
|
||||
|
||||
# Output count. Requests with different num_outputs_per_prompt produce
|
||||
# differently shaped outputs and cannot share a batch.
|
||||
num_outputs_per_prompt: int = 1
|
||||
@@ -108,6 +112,11 @@ class RequestBatchSamplingParamsKey:
|
||||
layers: int = 4
|
||||
use_en_prompt: bool = False
|
||||
|
||||
# Request-scoped execution policy. Keep accelerated and reference-path
|
||||
# requests in separate worker batches. ``None`` delegates the default to
|
||||
# the model and must remain distinct from explicit ``lossless``.
|
||||
quality: str | None = None
|
||||
|
||||
# LoRA identity.
|
||||
lora_int_id: int | None = None
|
||||
lora_scale: float = 1.0
|
||||
|
||||
@@ -32,7 +32,13 @@ from vllm_omni.diffusion.compile import regionally_compile
|
||||
from vllm_omni.diffusion.data import DiffusionOutput, OmniDiffusionConfig
|
||||
from vllm_omni.diffusion.forward_context import set_forward_context
|
||||
from vllm_omni.diffusion.model_loader.diffusers_loader import DiffusersPipelineLoader
|
||||
from vllm_omni.diffusion.models.interface import SupportsPromptUpdate, supports_prompt_update, supports_step_execution
|
||||
from vllm_omni.diffusion.models.interface import (
|
||||
SupportsPromptUpdate,
|
||||
adopt_request_scoped_cache_dit,
|
||||
is_request_scoped_cache_dit_enabled,
|
||||
supports_prompt_update,
|
||||
supports_step_execution,
|
||||
)
|
||||
from vllm_omni.diffusion.offloader import get_offload_backend
|
||||
from vllm_omni.diffusion.registry import _NO_CACHE_ACCELERATION
|
||||
from vllm_omni.diffusion.request import OmniDiffusionRequest
|
||||
@@ -304,7 +310,19 @@ class DiffusionModelRunner(OmniConnectorModelRunnerMixin):
|
||||
self.cache_backend = None
|
||||
self.od_config.cache_backend = None
|
||||
else:
|
||||
# Install configured cache capability once at startup. A model
|
||||
# may explicitly adopt the enabled Cache-DiT backend and then
|
||||
# own all later request-boundary enable/disable transitions.
|
||||
self.cache_backend.enable(self.pipeline)
|
||||
if str(self.od_config.cache_backend).lower() == "cache_dit" and adopt_request_scoped_cache_dit(
|
||||
self.pipeline,
|
||||
self.cache_backend,
|
||||
):
|
||||
logger.info(
|
||||
"Pipeline %s owns request-scoped Cache-DiT transitions.",
|
||||
type(self.pipeline).__name__,
|
||||
)
|
||||
self.cache_backend = None
|
||||
|
||||
# Install prompt-embedding cache (transparent wrapper around
|
||||
# ``pipeline.encode_prompt``). Enabled via config or env var; a no-op
|
||||
@@ -523,11 +541,11 @@ class DiffusionModelRunner(OmniConnectorModelRunnerMixin):
|
||||
if is_primary and prompt_embed_cache is not None:
|
||||
logger.debug("prompt-embed cache: %s", prompt_embed_cache.stats())
|
||||
|
||||
runner_cache_dit_enabled = self.cache_backend is not None and self.cache_backend.is_enabled()
|
||||
if (
|
||||
self.cache_backend is not None
|
||||
and self.cache_backend.is_enabled()
|
||||
and od_config.cache_backend == "cache_dit"
|
||||
od_config.cache_backend == "cache_dit"
|
||||
and od_config.enable_cache_dit_summary
|
||||
and (runner_cache_dit_enabled or is_request_scoped_cache_dit_enabled(self.pipeline))
|
||||
):
|
||||
cache_summary(self.pipeline, details=True)
|
||||
|
||||
|
||||
Reference in new issue
Block a user