vllm.model_executor.models.diffusion_gemma_sampler
¶
Triton kernels for the DiffusionGemma denoise sampler.
The step needs, for every canvas position, the argmax of the
temperature-scaled logits, a Gumbel-max sample from them, the entropy of
their softmax, and the softmax itself in the model dtype for the
self-conditioning matmul. As PyTorch ops these are several passes over a
[rows, vocab] fp32 tensor plus a same-sized noise tensor. The Triton
kernel reads each row once with an online max and sum, draws the noise
inline, and writes the probabilities once.
sample_step then updates each request's canvas and convergence state
from those statistics, and softcap_logits applies the final logit
softcap in one pass. Each has a PyTorch reference for tests and non-CUDA
runs. The dummy runs never take a decode step, so the model registers these
kernels for JIT warmup with every variant serving reaches.
The logprobs of a converging slot are written to a per-slot stash by
stash_converged_logprobs, which skips the rows of slots that did not
converge.
Functions:
-
sample_row_stats–Argmax, Gumbel-max sample, entropy and (optionally) softmax per row.
-
sample_row_stats_reference–The PyTorch form of the same statistics, for tests and non-CUDA runs.
-
sample_step–Advance each decode request one step: confidence, entropy-bound
-
sample_step_reference–The PyTorch form of the same step, for tests and non-CUDA runs.
-
softcap_logits–tanh(logits / cap) * capin fp32, as a new[rows, vocab]tensor. -
stability_rows–Rows of the accepted-canvas history.
-
stash_converged_logprobs–Write the logprobs of the converged requests' rows to the stash.
_empty(like, *shape, dtype)
¶
torch.empty on like's device, or only its metadata when
like is a warmup input, so warmup allocates nothing.
_lp_topk_kernel(logits_ptr, logits_stride, src_ptr, keep_ptr, valid_ptr, temps_ptr, slots_ptr, num_ids_ptr, block_max_ptr, cand_ptr, K, W, V, NUM_CHUNKS, NUM_BLOCKS, HAS_IDS, BLOCK, BLOCKS_PER_CHUNK, BLOCKS_POW2, KP)
¶
The KP largest keys of one chunk of a row, unordered.
A key orders by value, then by lower index: the fp32 bits mapped to an order-preserving int32 in the high word, the inverted index in the low. Keys are distinct, so the top-k under them is unique.
_tile_rows(max_tile_rows, cols, *itemsizes)
¶
Row counts for a [rows, cols] tile reaching each storage-size class
of tensors with these element sizes.
sample_row_stats(logits, temps, canvas_len, seed, probs_dtype)
¶
Argmax, Gumbel-max sample, entropy and (optionally) softmax per row.
logits is [rows, vocab] and row i uses temperature
temps[i // canvas_len]. A zero temperature is greedy: the sample is
the argmax, and the entropy is the reference's, which clamps the
temperature at 1e-10.
sample_row_stats_reference(logits, temps, canvas_len, probs_dtype)
¶
The PyTorch form of the same statistics, for tests and non-CUDA runs.
sample_step(*, new_tokens, argmax_tokens, token_entropy, random_tokens, decode_slots, decode_idx, valid_canvas_len, canvas, argmax_canvas, history, pin_mask, seed_canvas, step, is_encoder_phase, confident, history_len, max_steps, read_only, sampled, num_sampled, confidence_threshold, entropy_bound)
¶
Advance each decode request one step: confidence, entropy-bound accept/renoise, the history ring and convergence.
The contiguous [n, W] statistics come from sample_row_stats and
random_tokens is the renoise draw. Per-slot state is indexed by
decode_slots and updated in place over its first W columns;
sampled and num_sampled are written at decode_idx. Returns
which requests denoise again and so read their soft embed next step.
sample_step_reference(*, new_tokens, argmax_tokens, token_entropy, random_tokens, decode_slots, decode_idx, valid_canvas_len, canvas, argmax_canvas, history, pin_mask, seed_canvas, step, is_encoder_phase, confident, history_len, max_steps, read_only, sampled, num_sampled, confidence_threshold, entropy_bound)
¶
The PyTorch form of the same step, for tests and non-CUDA runs.
softcap_logits(logits, cap)
¶
tanh(logits / cap) * cap in fp32, as a new [rows, vocab] tensor.
fp32 before tanh for numerical stability (matches HF DiffusionGemma).
stability_rows(generation_config)
¶
Rows of the accepted-canvas history.
In Transformers, stability_threshold=1 means the current step must
match the previous step. The history includes the current step, so it
holds one more row.
stash_converged_logprobs(logits, canvas_len, src, slots, keep, valid, temps, num_topk, num_token_ids, token_ids, out_ids, out_logprobs, out_ranks, logits_mode)
¶
Write the logprobs of the converged requests' rows to the stash.
Request j owns logits rows src[j] * canvas_len + p for
p < valid[j], divided by temps[j]. Where keep[j], they go to
out_*[slots[j], p], laid out as compute_topk_scores lays out a row:
the argmax, then the request's token_ids if it has any, else the
num_topk largest (tied ids by lower id), padded with token 0 at -inf.
Rows not kept exit at once; the others are split into chunks so a few
kept rows still fill the GPU.