2026-01-08 23:05:44 +08:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
2026-03-20 19:21:50 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2026-01-08 23:05:44 +08:00
|
|
|
from typing import (
|
2026-03-20 19:21:50 +08:00
|
|
|
TYPE_CHECKING,
|
|
|
|
|
Any,
|
2026-01-08 23:05:44 +08:00
|
|
|
ClassVar,
|
|
|
|
|
Protocol,
|
|
|
|
|
runtime_checkable,
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-20 19:21:50 +08:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
import torch
|
|
|
|
|
|
|
|
|
|
from vllm_omni.diffusion.data import DiffusionOutput
|
|
|
|
|
from vllm_omni.diffusion.worker.utils import DiffusionRequestState
|
|
|
|
|
|
2026-01-08 23:05:44 +08:00
|
|
|
|
|
|
|
|
@runtime_checkable
|
|
|
|
|
class SupportImageInput(Protocol):
|
|
|
|
|
support_image_input: ClassVar[bool] = True
|
2026-01-29 15:18:19 +08:00
|
|
|
color_format: ClassVar[str] = "RGB" # Default color format
|
2026-01-24 17:27:58 +08:00
|
|
|
|
|
|
|
|
|
2026-03-13 21:53:06 +08:00
|
|
|
@runtime_checkable
|
|
|
|
|
class SupportAudioInput(Protocol):
|
|
|
|
|
support_audio_input: ClassVar[bool] = True
|
|
|
|
|
|
|
|
|
|
|
2026-01-24 17:27:58 +08:00
|
|
|
@runtime_checkable
|
|
|
|
|
class SupportAudioOutput(Protocol):
|
|
|
|
|
support_audio_output: ClassVar[bool] = True
|
2026-03-20 19:21:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@runtime_checkable
|
|
|
|
|
class SupportsStepExecution(Protocol):
|
|
|
|
|
"""State-driven step-level execution protocol for diffusion pipelines.
|
|
|
|
|
|
|
|
|
|
Pipelines should split request-level ``forward()`` into:
|
|
|
|
|
``prepare_encode()`` (one-time request setup), ``denoise_step()``
|
|
|
|
|
(one denoise forward), ``step_scheduler()`` (one scheduler update),
|
|
|
|
|
and ``post_decode()`` (final decode).
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
supports_step_execution: ClassVar[bool] = True
|
|
|
|
|
|
|
|
|
|
def prepare_encode(self, state: DiffusionRequestState, **kwargs: Any) -> DiffusionRequestState:
|
|
|
|
|
"""Prepare request-level inputs and return initialized state."""
|
|
|
|
|
|
|
|
|
|
def denoise_step(self, state: DiffusionRequestState, **kwargs: Any) -> torch.Tensor | None:
|
|
|
|
|
"""Run one denoise step."""
|
|
|
|
|
|
|
|
|
|
def step_scheduler(self, state: DiffusionRequestState, noise_pred: torch.Tensor, **kwargs: Any) -> None:
|
|
|
|
|
"""Run one scheduler step."""
|
|
|
|
|
|
|
|
|
|
def post_decode(self, state: DiffusionRequestState, **kwargs: Any) -> DiffusionOutput:
|
|
|
|
|
"""Decode output after denoise loop."""
|
|
|
|
|
|
|
|
|
|
|
2026-04-22 16:23:00 -04:00
|
|
|
@runtime_checkable
|
2026-05-08 10:16:49 -04:00
|
|
|
class SupportsComponentDiscovery(Protocol):
|
|
|
|
|
"""Declares which submodules serve as pipeline components.
|
|
|
|
|
|
|
|
|
|
Used by the framework to locate DiT, encoder, and VAE modules for
|
|
|
|
|
CPU offload, HSDP sharding, and other operations that need to know
|
|
|
|
|
the pipeline's internal structure.
|
2026-04-22 16:23:00 -04:00
|
|
|
|
|
|
|
|
All attribute names support dotted paths for nested submodules
|
|
|
|
|
(e.g. ``"pipe.transformer"``).
|
|
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
|
_dit_modules: Denoising submodules (on GPU during diffusion).
|
|
|
|
|
_encoder_modules: Encoder submodules (offloaded during diffusion).
|
|
|
|
|
_vae_modules: VAE(s) (always on GPU).
|
|
|
|
|
_resident_modules: Extra modules pinned on GPU during layerwise
|
|
|
|
|
offloading. Optional, defaults to ``[]``.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
_dit_modules: ClassVar[list[str]]
|
|
|
|
|
_encoder_modules: ClassVar[list[str]]
|
|
|
|
|
_vae_modules: ClassVar[list[str]]
|
|
|
|
|
_resident_modules: ClassVar[list[str]] = []
|
|
|
|
|
|
|
|
|
|
|
2026-03-20 19:21:50 +08:00
|
|
|
def supports_step_execution(pipeline: object) -> bool:
|
|
|
|
|
"""Return whether `pipeline` implements :class:`SupportsStepExecution`."""
|
|
|
|
|
|
|
|
|
|
return isinstance(pipeline, SupportsStepExecution)
|