Skip to content

vllm.model_executor.models.diffusion_gemma

DiffusionGemma model, ModelState, and Sampler for vLLM.

Single Gemma4 backbone run in two modes (like YOCO): - encoder mode: causal attention, writes KV cache - decoder mode: bidirectional attention, reads encoder KV, doesn't write

Same weights, same layers. The only decoder-unique component is a self-conditioning MLP.

Multimodal support: the model always includes a vision tower (shared with Gemma4). Images are encoded through the vision tower and projected into the LM embedding space via Gemma4MultimodalEmbedder.

Classes:

DiffusionGemmaForConditionalGeneration

Bases: Module, SupportsMultiModal, SupportsQuant

DiffusionGemma for vLLM.

Single Gemma4 backbone that switches between encoder and decoder mode. The encoder path uses standard Gemma4 layers (causal attention, KV write). The decoder path uses the same weights with bidirectional attention and KV read-only, plus self-conditioning.

Always includes a vision tower (same as Gemma4) for image understanding.

In practice, the model's forward() dispatches based on the mode kwarg set by DiffusionGemmaModelState.prepare_inputs().

Methods:

  • get_mm_mapping –

    Get the module prefix mapping for multimodal models.

get_mm_mapping()

Get the module prefix mapping for multimodal models.

DiffusionGemmaModelState

Bases: ModelState

ModelState for DiffusionGemma.

Single Gemma4 backbone in two modes: - encoder mode (num_draft_tokens == 0): causal attention, writes KV - decoder mode (num_draft_tokens > 0): bidirectional attention, reads KV

DiffusionGemmaProcessingInfo

Bases: Gemma4ProcessingInfo

Processing info for DiffusionGemma, which has no audio tower.

DiffusionGemmaRequestStates

Pre-allocated GPU tensors for DiffusionGemma per-request state.

Follows the indexed-slot pattern used by RequestState.

Methods:

  • allowed_tensor –

    ids as an int64 tensor on the device, built once per tuple.

  • apply_seed_canvases –

    Replace the canvas of every seeded slot among slots_gpu.

  • batch_allowed –

    The allowed ids shared by every one of slots, or None.

  • init_canvas –

    Initialize canvas with random tokens for the given slots.

  • set_pins –

    Hold positions of the slot's seed canvas through every denoise

  • set_seed_canvas –

    ids covers the slot's canvas width; positions past it are never

allowed_tensor(ids)

ids as an int64 tensor on the device, built once per tuple.

apply_seed_canvases(slots_np, slots_gpu)

Replace the canvas of every seeded slot among slots_gpu.

batch_allowed(slots)

The allowed ids shared by every one of slots, or None.

None means the step runs over the full vocabulary. The sampler then masks each constrained slot's logit rows to its own set, so a constrained request reads the same way whoever shares its batch.

init_canvas(slot_indices)

Initialize canvas with random tokens for the given slots.

slot_indices must already be on device to avoid a cpu->gpu sync.

set_pins(slot_idx, positions)

Hold positions of the slot's seed canvas through every denoise step. Validated against the request's canvas width upstream.

set_seed_canvas(slot_idx, ids)

ids covers the slot's canvas width; positions past it are never scheduled.

DiffusionGemmaSelfConditioning

Bases: Module

Gated MLP that processes soft embeddings from the previous denoising step.

Structurally identical to Gemma4MLP but with self_conditioning_size and post_norm without learned scale.

DiffusionSampler

Batched accept/renoise sampler for DiffusionGemma.

Follows the same structure as vllm.v1.worker.gpu.sample.sampler.Sampler: decomposed into named methods, all GPU state in pre-allocated buffers, no GPU→CPU syncs on the hot path.

_build_output(input_batch, sampled, num_sampled, per_req_nlogits_np, device, logprobs_tensors=None)

Compute num_rejected and build SamplerOutput.

_emitted_logprobs(slots_np, lp_req_np, wide_req_np, num_sampled, width)

Logprobs of the requests emitting this step, picked on the host.

For steps with a wide request: a canvas of rows for every logprobs request, padded to its top-k, would not fit.

_finish_prefills(input_batch, prefill_indices_np)

Transition requests whose prompt completes this step to denoising.

Initializes their canvas, seeds draft tokens, and flips is_encoder_phase to False. Mid-chunk requests (prompt longer than the token budget) are left untouched so is_encoder_phase stays True and prepare_attn keeps causal attention for their remaining chunks.

_pend_wide_logprobs(tile_logits, W, wide_np, tile_slots_np, tile_valid_np, keep, temp, num_logprobs, max_token_ids)

Compute the logprobs of the converged wide requests at wide_np.

A per-slot stash for them would hold [canvas_length, vocab] rows, and a top-k over all their rows every step is a full sort. So read back which of them converged and compute only those.

_stash_tile_logprobs(tile_logits, W, lp_np, tile_slots, tile_valid, keep, lp_temp, allowed, num_logprobs, max_token_ids)

Stash the logprobs of the tile requests at lp_np where keep.

Requests without logprobs cost nothing. Which slots converged is only known on the device, so the kernels skip the other rows themselves.

_tile_logprobs(scaled, tile_slots, allowed, num_logprobs, max_token_ids)

Logprobs of every row of a [n, W, vocab] tile at its argmax.

_denoise_temperature(step_tensor, slots, max_denoising_steps, t_min, t_max)

The schedule's temperature for each slot at its current step.

_mask_rows_to_allowed(logits, row_starts, row_lens, allowed_per_row)

Mask every column outside a request's allowed ids on that request's rows. Request i owns rows [row_starts[i], +row_lens[i]); None leaves its rows alone. Returns a copy when any row is masked, so the caller's tensor (possibly the runner's) is never written.

Softmax over a masked row equals the K-space distribution the shared fast path computes, so both paths give the same reads. The mask value is a large finite negative rather than -inf: the entropy is probs times log-probs, and 0 * -inf is NaN, while 0 * -1e20 is 0. It stays finite after the greedy temperature clamp (1e-10) scales it by 1e10.

_store_self_conditioning(sc_embeds, decode_slots, keep, probs, pin_mask, embed_weight, normalizer, sc_vocab_start, sc_vocab_end, tp_size, tp_group_name)

Store probs @ embed_weight * normalizer, the soft embed the next step's self-conditioning MLP consumes, for the keep requests and zero it for the rest. sc_embeds and pin_mask are viewed at the tile's width.

Storing the [.., hidden] soft embed instead of the full [.., vocab] probs avoids a giant persistent buffer. probs is None when every request in the tile ends after this step, so the soft embed would never be read and the matmul, a full pass over the vocabulary matrix, is skipped.