vllm_omni.diffusion.worker ¶
Worker classes for diffusion models.
Modules:
| Name | Description |
|---|---|
diffusion_model_runner | Diffusion Model Runner for vLLM-Omni. |
diffusion_worker | Diffusion Worker for vLLM-Omni. |
input_batch | Diffusion input-batch structures following the MRV2-style vLLM layout. |
request_batch | Request-level batch abstraction for diffusion runner. |
stage_payload | |
utils | Per-request mutable state for step-wise diffusion execution. |
DiffusionModelRunner ¶
Bases: DiffusionStagePayloadMixin
Model runner that handles model loading and execution for diffusion models.
This class follows the AR pattern where the Runner handles all model-related operations including loading, compilation, offloading, caching, and execution. The Worker only handles infrastructure (device, distributed env).
diffusion_kv_backend instance-attribute ¶
diffusion_kv_backend = DiffusionKVModelRunnerBackend(
vllm_config=vllm_config,
od_config=od_config,
device=device,
)
kv_transfer_manager instance-attribute ¶
kv_transfer_manager = (
payload_transfer_manager
if getattr(od_config, "kv_transfer_config", None)
is None
else None
)
clear_prompt_embed_cache ¶
Evict all cached text-encoder outputs (e.g. between training epochs).
Kept primarily for extension purposes.
execute_model ¶
execute_model(
req: OmniDiffusionRequest,
kv_prefetch_job: KVPrefetchJob | None = None,
diffusion_kv_metadata: DiffusionKVMetadata
| None = None,
) -> DiffusionOutput
Execute a forward pass for the given requests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
req | OmniDiffusionRequest | A diffusion request containing a list of prompts to process. | required |
Returns:
| Type | Description |
|---|---|
DiffusionOutput | DiffusionOutput with generated results. |
Note
We use torch.no_grad() for HSDP because HSDP2's fully_shard requires access to tensor version counters in pre_forward hooks, which inference tensors do not track. For non-HSDP inference, we use torch.inference_mode() for better performance.
execute_model_batch ¶
execute_model_batch(
scheduler_output: DiffusionSchedulerOutput,
od_config: OmniDiffusionConfig,
) -> BatchRunnerOutput
Execute scheduled request-mode requests through the batch forward path.
Builds a DiffusionRequestBatch from scheduled new requests, runs per-request setup, and calls pipeline.forward(batch). The pipeline must declare supports_request_batch = True.
execute_stepwise ¶
execute_stepwise(
scheduler_output: DiffusionSchedulerOutput,
) -> BatchRunnerOutput
Execute one step for one scheduled request and return runner output.
get_diffusion_kv_row ¶
get_diffusion_kv_row(
request_id: str,
sequence_id: int | None,
context_id: str | None = None,
) -> int
get_kv_cache_spec ¶
Collect native specs from cache-enabled loaded attention modules.
get_prompt_embed_cache_stats ¶
get_prompt_embed_cache_stats() -> dict | None
Return hit/miss statistics for the prompt-embedding cache, if enabled.
Kept primarily for extension purposes.
install_diffusion_kv_metadata ¶
install_diffusion_kv_metadata(
metadata: DiffusionKVMetadata,
) -> bool
load_model ¶
load_model(
memory_pool_context_fn: Callable[
[str], AbstractContextManager[Any]
]
| None = None,
load_format: str = "default",
custom_pipeline_name: str | None = None,
) -> None
Launch the diffusion pipeline, applying compilation, offloading, and caching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
memory_pool_context_fn | Callable[[str], AbstractContextManager[Any]] | None | Optional function that returns a context manager for memory pool allocation (used for sleep mode). | None |
load_format | str | Format for loading model weights. Supported formats: - "default" (default): Automatically detect and use the default format based on configuration - "custom_pipeline": Init model from a custom pipeline class specified by | 'default' |
custom_pipeline_name | str | None | Optional custom pipeline class name to use. | None |
profile_run ¶
profile_run(requests: list[OmniDiffusionRequest]) -> None
Run the maximum per-rank request batch for memory profiling.
This deliberately bypasses Scheduler admission and Diffusion KV metadata validation because cache capacity has not been sized yet. It otherwise uses the normal execution-mode path so model inputs, collective communication, backend workspaces, denoising, and decode allocations contribute to the observed peak. Step execution profiles one fused InputBatch instead of sequential single-request forwards.
release_captured_graphs ¶
Drop every CUDA graph held for this model, wherever it is kept.
Sleep level 2 discards the memory a capture was recorded against, so a graph that outlives it replays over freed storage. The runner owns compilation and execution resources, so it owns the release: a pipeline that captures graphs of its own implements release_captured_graphs and is collected here, instead of every caller having to know which pipelines have one.
remove_diffusion_kv_requests ¶
set_kv_cache_config ¶
Physically initialize the Engine-generated rank-local config.
submit_interaction ¶
submit_interaction(
request_id: str, interaction: OmniInteractionPrompt
) -> None
Route a midway interaction through the pipeline interaction coordinator.
DiffusionWorker ¶
A worker that manages GPU infrastructure and delegates to the model runner.
This class handles infrastructure initialization only: - Device setup (CUDA device selection) - Distributed environment (NCCL, model parallel) - Memory management (sleep/wake)
All model-related operations (loading, compilation, execution) are delegated to DiffusionModelRunner.
model_runner instance-attribute ¶
model_runner: DiffusionModelRunner | None = (
model_runner_cls(
vllm_config=self.vllm_config,
od_config=self.od_config,
device=self.device,
)
)
close_ar_diffusion_session ¶
Close runner-owned AR state through the collective RPC boundary.
determine_available_kv_memory ¶
determine_available_kv_memory(
profile_requests: list[OmniDiffusionRequest],
) -> list[int]
Profile and return each rank's safe Diffusion KV memory budget.
execute_model ¶
execute_model(
req: OmniDiffusionRequest | list[NewRequestData],
od_config: OmniDiffusionConfig,
kv_prefetch_job: KVPrefetchJob | None = None,
diffusion_kv_metadata: DiffusionKVMetadata
| None = None,
) -> DiffusionOutput
Execute a forward pass by delegating to the model runner.
If req is a list (DP multi-concurrency), each rank picks one complete NewRequestData envelope based on its distributed rank. AllGather in the layerwise offload only gathers weight shards (request-independent), so all ranks stay synchronised at each AllGather call while computing different activations. Selecting the envelope keeps Scheduler-issued KV metadata bound to the request that owns its block tables.
Each rank returns its OWN DiffusionOutput (no gather). The executor collects N responses via the per-worker result queues.
execute_model_batch ¶
execute_model_batch(
scheduler_output: DiffusionSchedulerOutput,
od_config: OmniDiffusionConfig,
) -> BatchRunnerOutput
Batch forward: LoRA activate once, delegate to model runner.
execute_stepwise ¶
execute_stepwise(
scheduler_output: DiffusionSchedulerOutput,
) -> BaseRunnerOutput
Execute one diffusion step by delegating to the model runner.
get_kv_cache_specs ¶
Return native rank-local specs for every diffusion Worker.
load_model ¶
load_model(
load_format: str = "default",
custom_pipeline_name: str | None = None,
**kwargs,
) -> None
Load the diffusion model using DiffusionModelRunner.
profile ¶
remove_diffusion_kv_requests ¶
Clear Worker-local rows without freeing Scheduler-owned blocks.
reset_ar_diffusion_session ¶
Reset runner-owned AR state through the collective RPC boundary.
set_kv_cache_configs ¶
Select this rank's config and initialize its physical KV pages.
sleep ¶
Put the worker to sleep, offloading model weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level | int | Sleep level. Level 1 offloads weights, level 2 also saves buffers. | 1 |
submit_interaction ¶
submit_interaction(
request_id: str, interaction: OmniInteractionPrompt
) -> None
Apply a midway interaction to an active stepwise request.
synchronize_device ¶
synchronize_device(timeout: float | None = None) -> None
Wait until this rank has no device work left.
A KV prefetch still receiving on its background thread has queued no device work yet, so it is joined first. timeout bounds that join (and the multi-process worker's output drain before this call); the device wait itself is unbounded.
wake_up ¶
Wake up the worker from sleep mode.
Re-activates the memory allocator for the specified tags and restores model buffers from CPU back to GPU if they were saved during Level 2 sleep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tags | list[str] | None | List of memory pool tags to re-activate (e.g., ["weights"] to match Level 1 sleep). If None, all pools are re-activated. | None |
WorkerProc ¶
Wrapper that runs one Worker in a separate process.
result_mq instance-attribute ¶
worker instance-attribute ¶
drain_async_outputs ¶
Block until background D2H/SHM packing has no work left.
Returns False if outputs are still in flight when timeout expires.
recv_message ¶
recv_message() -> Any
Receive one complete broadcast message without dropping overflow data.
worker_main staticmethod ¶
worker_main(
rank: int,
od_config: OmniDiffusionConfig,
pipe_writer: Connection,
broadcast_handle,
wake_event: Event,
worker_extension_cls: str | None = None,
custom_pipeline_args: dict[str, Any] | None = None,
) -> None
Worker initialization and execution loops.