Skip to content

vllm_omni.diffusion.forward_context

DenoiseProgressMixin

record_denoise_step

record_denoise_step(
    step_idx: int | None,
    timestep=None,
    scheduler=None,
    normalized_timestep: float | None = None,
    total_steps: int | None = None,
) -> None

ForwardContext dataclass

set forward context for diffusion models

attn_metadata class-attribute instance-attribute

attn_metadata: (
    dict[str, AttentionMetadata]
    | list[dict[str, AttentionMetadata]]
    | None
) = None

denoise_step_idx class-attribute instance-attribute

denoise_step_idx: int | None = None

denoise_timestep class-attribute instance-attribute

denoise_timestep: float | None = None

direct_condition class-attribute instance-attribute

direct_condition: Tensor | None = None

in_diffusion_kv_memory_profile class-attribute instance-attribute

in_diffusion_kv_memory_profile: bool = False

omni_diffusion_config class-attribute instance-attribute

omni_diffusion_config: OmniDiffusionConfig | None = None

paged_kv_adapter class-attribute instance-attribute

paged_kv_adapter: Any | None = None

paged_kv_cached_prefix_len class-attribute instance-attribute

paged_kv_cached_prefix_len: int = 0

paged_kv_runtime class-attribute instance-attribute

paged_kv_runtime: DiffusionPagedAttentionRuntime | None = (
    None
)

ref_latent class-attribute instance-attribute

ref_latent: Tensor | None = None

sp_active property

sp_active: bool

Returns True when SP attention parallelism should be enabled.

  • If _sp_plan hooks are applied: use _sp_shard_depth (0 = outside sharded region).
  • If _sp_plan hooks are NOT applied: default to True when sequence_parallel_size > 1, since _sp_shard_depth is only meaningful within the _sp_plan hook mechanism.

sp_original_seq_len class-attribute instance-attribute

sp_original_seq_len: int | None = None

sp_padding_size class-attribute instance-attribute

sp_padding_size: int = 0

sp_plan_hooks_applied class-attribute instance-attribute

sp_plan_hooks_applied: bool = False

sp_rank_local_seq_lens_equal property

sp_rank_local_seq_lens_equal: bool

Whether every active SP boundary guarantees equal local shard sizes.

Only framework-managed auto_pad boundaries provide this contract; a region that also shards manually keeps the dynamic length exchange.

sp_shard_metadata class-attribute instance-attribute

sp_shard_metadata: dict[str, int] = field(
    default_factory=dict
)

split_text_embed_in_sp class-attribute instance-attribute

split_text_embed_in_sp: bool = False

total_denoise_steps class-attribute instance-attribute

total_denoise_steps: int | None = None

vllm_config class-attribute instance-attribute

vllm_config: VllmConfig | None = None

build_local_sp_padding_mask

build_local_sp_padding_mask(
    batch_size: int, local_seq_len: int, device
)

Build a per-rank SP padding mask that matches the local shard shape.

Auto-padding is applied before sequence-parallel sharding, so attention on each rank must receive a mask for its local shard, not for the global padded sequence.

create_forward_context

create_forward_context(
    vllm_config: VllmConfig | None = None,
    omni_diffusion_config: OmniDiffusionConfig
    | None = None,
    attn_metadata: dict[str, AttentionMetadata]
    | list[dict[str, AttentionMetadata]]
    | None = None,
    paged_kv_runtime: DiffusionPagedAttentionRuntime
    | None = None,
    paged_kv_cached_prefix_len: int = 0,
    in_diffusion_kv_memory_profile: bool = False,
    split_text_embed_in_sp: bool = False,
    denoise_step_idx: int | None = None,
)

get_forward_context

get_forward_context() -> ForwardContext

Get the current forward context.

get_paged_kv_computed_tokens

get_paged_kv_computed_tokens() -> tuple[int, ...]

get_sp_shard_original_seq_len

get_sp_shard_original_seq_len(
    shard_group: str,
) -> int | None

Pre-padding global length of shard_group, or None if it was not split.

get_ulysses_mode

get_ulysses_mode(*, default: str = 'strict') -> str

Resolve the Ulysses-SP mode from the current ForwardContext.

Returns default when ForwardContext is unavailable or the diffusion config is not set.

is_forward_context_available

is_forward_context_available() -> bool

override_forward_context

override_forward_context(
    forward_context: ForwardContext | None,
)

A context manager that overrides the current forward context. This is used to override the forward context for a specific forward pass.

override_paged_kv_adapter

override_paged_kv_adapter(adapter: Any | None)

Temporarily expose a Worker paged-KV adapter to Omni Attention.

This is deliberately a small context override instead of a second global forward context. The model runner owns the outer context and the adapter only replaces one opaque field while its prepared native metadata is live.

paged_kv_prefill

paged_kv_prefill(sequence_id: int, num_tokens: int)

set_forward_context

set_forward_context(
    vllm_config: VllmConfig | None = None,
    omni_diffusion_config: OmniDiffusionConfig
    | None = None,
    attn_metadata: dict[str, AttentionMetadata]
    | list[dict[str, AttentionMetadata]]
    | None = None,
    paged_kv_runtime: DiffusionPagedAttentionRuntime
    | None = None,
    paged_kv_cached_prefix_len: int = 0,
    in_diffusion_kv_memory_profile: bool = False,
    split_text_embed_in_sp: bool = False,
    denoise_step_idx: int | None = None,
)

A context manager that stores the current forward context, can be attention metadata, split_text_embed_in_sp, etc. Here we can inject common logic for every model forward pass.

set_forward_context_denoise_step_idx

set_forward_context_denoise_step_idx(
    step_idx: int | None,
) -> None

Set the current diffusion denoise step on the active ForwardContext.

set_forward_context_denoise_timestep

set_forward_context_denoise_timestep(
    timestep: float | None,
) -> None

Set the normalized (descending, 1 -> 0) denoise timestep.

Timestep-gated attention features read this; pipelines that drive their own denoise loop can publish it directly instead of going through :meth:DenoiseProgressMixin.record_denoise_step.

set_forward_context_denoise_total_steps

set_forward_context_denoise_total_steps(
    total_steps: int | None,
) -> None

Set the total denoise step count on the active ForwardContext.

Denoise loops publish it so tail-fallback gates (e.g. end_step in RAINFUSION_ATTN) know when the final denoise steps begin.

set_forward_context_direct_condition

set_forward_context_direct_condition(
    direct_condition: Tensor | None,
) -> None

Set the projected direct-VLM condition on the active context.

set_forward_context_ref_latent

set_forward_context_ref_latent(
    ref_latent: Tensor | None,
) -> None

Set the per-request reference latent on the active ForwardContext.

Used by img2img-capable DiT models (e.g. Ming-flash-omni-2.0) so the transformer can read the reference latent from request scope instead of module instance state.