[Core] structured generation mode for DiffusionGemma model (Jev-like) (#57250)

Signed-off-by: Matt Mastracci <matthew@mastracci.com>
Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Signed-off-by: Razorback16 <razorback16@protonmail.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Lucas Wilkinson <lwilkins@redhat.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Razorback16 <razorback16@protonmail.com>
This commit is contained in:
Matt Mastracci
2026-09-22 20:51:17 +00:00
committed by GitHub
co-authored by Claude Fable 5.1 Lucas Wilkinson Codex Razorback16
parent fae5cbfc8b
commit 1b3b88ec2b
16 changed files with 2795 additions and 155 deletions
+56
View File
@@ -0,0 +1,56 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Async scheduling for diffusion requests.
These rules live here so Scheduler.schedule() and AsyncScheduler stay
unchanged. VllmConfig selects this class for a diffusion model under async
scheduling. A sync scheduler creates no output placeholders, which both rules
read.
"""
from vllm.v1.core.sched.async_scheduler import AsyncScheduler
from vllm.v1.core.sched.output import SchedulerOutput
from vllm.v1.request import Request
def diffusion_canvas_width(request: Request, canvas_length: int) -> int:
"""The canvas width a diffusion request asked for, else the served one."""
params = request.sampling_params
extra = params.extra_args if params is not None else None
width = extra.get("diffusion_canvas_length") if extra else None
return int(width) if width else canvas_length
def _read_in_flight(request: Request, width: int) -> bool:
"""True when a read-only request has all its denoise steps in flight.
The request emits its canvas on the last step and ends, so a further
step is discarded.
"""
params = request.sampling_params
extra = params.extra_args if params is not None else None
if not extra or not extra.get("diffusion_read_only"):
return False
steps = extra.get("diffusion_max_steps")
if not steps:
return False
# Each in-flight denoise step holds one canvas of placeholders.
return request.num_output_placeholders >= steps * width
class DiffusionAsyncScheduler(AsyncScheduler):
def schedule(self, throttle_prefills: bool = False) -> SchedulerOutput:
for request in self.running:
width = diffusion_canvas_width(request, self.num_spec_tokens)
# The placeholders are as wide as the served canvas.
if len(request.spec_token_ids) > width:
request.spec_token_ids = request.spec_token_ids[:width]
if _read_in_flight(request, width):
# Scheduler.schedule()'s max_tokens guard cannot be reached
# from a subclass. schedule() advances current_step before it
# checks decode eligibility, so current_step + 2 skips this
# call alone. max keeps a longer pipeline-parallel wait.
request.next_decode_eligible_step = max(
request.next_decode_eligible_step, self.current_step + 2
)
return super().schedule(throttle_prefills)
+16
View File
@@ -30,6 +30,7 @@ from vllm.tasks import GENERATION_TASKS, POOLING_TASKS, SupportedTask
from vllm.tokenizers import TokenizerLike
from vllm.utils import length_from_prompt_token_ids_or_embeds, random_uuid
from vllm.utils.async_utils import make_async
from vllm.utils.diffusion import validate_diffusion_sampling_params
from vllm.utils.jsontree import json_iter_leaves
from vllm.v1.engine import EngineCoreRequest
from vllm.v1.kv_hints import KvHintsEnvelope
@@ -53,6 +54,7 @@ class InputProcessor:
self.speculative_config = vllm_config.speculative_config
self.structured_outputs_config = vllm_config.structured_outputs_config
self.observability_config = vllm_config.observability_config
self.diffusion_config = vllm_config.diffusion_config
# Load the custom logits processor classes once; the returned callable
# runs their validate_params hooks per request at admission.
self.validate_logits_processors_params = (
@@ -129,6 +131,20 @@ class InputProcessor:
self.validate_logits_processors_params(params)
if self.model_config.is_diffusion:
# Without --diffusion-config the served canvas is unknown here;
# the ids and the read-only normalisation are still checked.
validate_diffusion_sampling_params(
params,
canvas_length=(
self.diffusion_config.canvas_length
if self.diffusion_config is not None
else None
),
vocab_size=self.model_config.get_vocab_size(),
async_scheduling=self.vllm_config.scheduler_config.async_scheduling,
)
if self.model_config.return_sampling_mask:
if params.temperature <= 0:
raise ValueError(