[Feat][Frontend] structured decisions: DiffusionGemma read strategy (#60466)

Signed-off-by: Matt Mastracci <matthew@mastracci.com>
Signed-off-by: Simon Veitner <sveitner@redhat.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Simon Veitner <sveitner@redhat.com>
Co-authored-by: Misha Goin <mgoin64@gmail.com>
This commit is contained in:
Matt Mastracci
2026-10-10 09:33:22 +08:00
committed by GitHub
co-authored by Claude Opus 5.5 Simon Veitner Misha Goin
parent 7d1d8660d6
commit 3c802af3cf
6 changed files with 193 additions and 40 deletions
@@ -105,7 +105,7 @@ def test_noul_labels_and_prompt():
assert q.labels == ("yes", "no")
assert [a.name for a in q.options] == ["yes", "no"]
assert q.type.prompt(q) == (
"Question: Reply within the hour?\nAnswer with yes or no only."
"Question: Reply within the hour?\nyes\nno\nAnswer with yes or no only."
)
described = noul(criteria={"true": "same day", "false": "later"})
assert described.type.prompt(described) == (
@@ -17,12 +17,16 @@ from vllm.entrypoints.generate.structured_decisions.protocol import (
StructuredDecisionRequest,
StructuredDecisionResponse,
)
from vllm.entrypoints.generate.structured_decisions.question_types import LABELS
from vllm.entrypoints.generate.structured_decisions.question_types import (
LABELS,
StructuredDecisionError,
)
from vllm.entrypoints.generate.structured_decisions.serving import (
ServingStructuredDecisions,
state_text,
)
from vllm.entrypoints.generate.structured_decisions.strategies import (
DiffusionGemmaCanvasStrategy,
NextTokenStrategy,
ReadContext,
reply_label_ids,
@@ -52,6 +56,10 @@ def test_strategy_selection():
qwen = "Qwen3ForCausalLM"
assert select_read_strategy(model(qwen)) is NextTokenStrategy
assert select_read_strategy(model(qwen, "processed_logprobs")) is NextTokenStrategy
assert (
select_read_strategy(model("DiffusionGemmaForBlockDiffusion"))
is DiffusionGemmaCanvasStrategy
)
with pytest.raises(ValueError, match="does not support LlamaForCausalLM"):
select_read_strategy(model("LlamaForCausalLM"))
with pytest.raises(ValueError, match="not raw_logits"):
@@ -220,3 +228,30 @@ async def test_request_metadata_reaches_every_question(
assert call.kwargs["trace_headers"] == (
TRACE_HEADERS if tracing_enabled and request_headers else None
)
def test_canvas_read():
strategy = DiffusionGemmaCanvasStrategy.__new__(DiffusionGemmaCanvasStrategy)
strategy.thought, strategy.end, strategy.pad = [10, 11, 12, 13], 106, 0
strategy.width, strategy.vocab_size = 16, 1000
strategy.max_model_len = 23
params = strategy._sampling_params([65, 66], prompt_ids=[1, 2, 3])
assert params.extra_args is not None
canvas = params.extra_args["diffusion_seed_canvas"]
# The label slot as noise, the end of the turn, padding.
assert canvas[1:] == [106] + [0] * 14
assert params.max_tokens == 2 and params.logprob_token_ids == [65, 66]
again = strategy._sampling_params([65, 66], prompt_ids=[1, 2, 3])
assert again.extra_args == params.extra_args
read_input = strategy._read_input(
{"type": "token", "prompt_token_ids": [1, 2, 3]}, [1, 2, 3]
)
assert read_input == {
"type": "token",
"prompt_token_ids": [1, 2, 3, 10, 11, 12, 13],
}
# One token more and the thought and the canvas no longer fit.
with pytest.raises(StructuredDecisionError, match="max_model_len=23"):
strategy._read_input(
{"type": "token", "prompt_token_ids": [1, 2, 3, 4]}, [1, 2, 3, 4]
)