[Model] DiffusionGemma: honor logprob_token_ids on the converging step (#57417)

Signed-off-by: Matt Mastracci <matthew@mastracci.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Matt Mastracci
2026-09-18 16:11:27 -04:00
committed by GitHub
co-authored by Claude Fable 5.1
parent 50d812b66a
commit 63d9ad0a3a
+27 -3
View File
@@ -967,6 +967,7 @@ class DiffusionSampler:
tp_group_name: str = "",
):
self.sampling_states = sampler.sampling_states
self.logprob_token_ids_state = sampler.logprob_token_ids_state
self.req_states = sampler.req_states
self.logits_mode = sampler.logprobs_mode in ("raw_logits", "processed_logits")
# Self-conditioning soft embed = probs @ embed_weight * normalizer,
@@ -1023,9 +1024,11 @@ class DiffusionSampler:
# that was aborted between its converging denoise and commit steps.
self._pending_logprobs.pop(req_idx, None)
self.sampling_states.add_request(req_idx, sampling_params)
self.logprob_token_ids_state.add_request(req_idx, sampling_params)
def apply_staged_writes(self) -> None:
self.sampling_states.apply_staged_writes()
self.logprob_token_ids_state.apply_staged_writes()
@property
def penalties_state(self):
@@ -1214,6 +1217,11 @@ class DiffusionSampler:
slots_np = input_batch.idx_mapping_np[:num_reqs]
max_num_logprobs = self.sampling_states.max_num_logprobs(slots_np)
# Requests may ask for specific token ids' logprobs instead of, or as
# well as, a top-k.
max_token_ids = self.logprob_token_ids_state.max_num_token_ids(slots_np)
want_logprobs = max_num_logprobs >= 0 or max_token_ids > 0
num_logprobs = max(max_num_logprobs, 0)
# Sample over the [num_decode * CL, vocab] logits. The fp32 pipeline in
# _compiled_sample_step keeps several live [group * CL, vocab] copies, so
@@ -1271,7 +1279,7 @@ class DiffusionSampler:
# Logprobs for denoise steps that just converged (is_encoder_phase
# flipped False→True), stashed per tile so `scaled` is freed each tile.
if max_num_logprobs >= 0:
if want_logprobs:
converged_mask = states.is_encoder_phase[tile_slots]
just_converged = converged_mask & ~is_committing[tile]
if just_converged.any():
@@ -1285,17 +1293,33 @@ class DiffusionSampler:
# positions are never emitted.
k_i = int(valid_canvas_len_np[start_req + li])
pos = li * CL
per_req_ids = max_token_ids > 0
self._pending_logprobs[slot.item()] = compute_topk_scores(
flat_logits[pos : pos + k_i],
max_num_logprobs,
num_logprobs,
argmax_tokens[local_idx][:k_i],
logprob_token_ids_state=(
self.logprob_token_ids_state if per_req_ids else None
),
# every row of this stash belongs to one slot
expanded_idx_mapping=(
torch.full(
(k_i,),
slot.item(),
dtype=torch.int32,
device=flat_logits.device,
)
if per_req_ids
else None
),
max_per_req_token_ids=max_token_ids,
logits_mode=self.logits_mode,
)
# Commit steps: is_committing was True at entry. Reassemble previously
# stashed logprobs and attach to SamplerOutput.
logprobs_tensors = None
if max_num_logprobs >= 0 and is_committing.any() and self._pending_logprobs:
if want_logprobs and is_committing.any() and self._pending_logprobs:
committing_slots = set(
decode_slots_np[is_committing.cpu().numpy()].tolist()
)