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.
Source code in vllm/model_executor/models/diffusion_gemma_sampler.py
_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.
Source code in vllm/model_executor/models/diffusion_gemma_sampler.py
_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.
Source code in vllm/model_executor/models/diffusion_gemma_sampler.py
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.
Source code in vllm/model_executor/models/diffusion_gemma_sampler.py
sample_row_stats_reference(logits, temps, canvas_len, probs_dtype)
¶
The PyTorch form of the same statistics, for tests and non-CUDA runs.
Source code in vllm/model_executor/models/diffusion_gemma_sampler.py
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.
Source code in vllm/model_executor/models/diffusion_gemma_sampler.py
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.
Source code in vllm/model_executor/models/diffusion_gemma_sampler.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 | |
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).
Source code in vllm/model_executor/models/diffusion_gemma_sampler.py
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.
Source code in vllm/model_executor/models/diffusion_gemma_sampler.py
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.
Source code in vllm/model_executor/models/diffusion_gemma_sampler.py
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 | |