[Bugfix][CPU][DiffusionGemma] Support narrower canvas w/ sync scheduling (#59107)

Signed-off-by: ojeda-e <estefania.b.ojeda@gmail.com>
This commit is contained in:
Mia Ojeda
2026-09-29 23:28:50 -04:00
committed by GitHub
parent 1b77cc3d67
commit e006d761a5
7 changed files with 78 additions and 41 deletions
@@ -36,10 +36,9 @@ layer when available, otherwise Triton. FlashInfer cannot serve this model (a
batch mixes causal prefill with bidirectional denoising), and
`--attention-backend FLASHINFER` is rejected.
Per-request canvas widths smaller than the served canvas require async
scheduling. The diffusion async scheduler is selected automatically; no
`--scheduler-cls` argument is needed. Synchronous execution supports full-width
canvases only.
Per-request canvas widths may be smaller than the served canvas with either
synchronous or asynchronous scheduling. Omit `diffusion_canvas_length` to use
the served canvas width.
Question types: `noul` (yes/no), `choice` with `options`, `score` with
ordered `levels`. Each label must be a single token in the answer template,
+2 -7
View File
@@ -71,7 +71,6 @@ def _verify_diffusion(params: SamplingParams, canvas_length: int | None = None):
params,
canvas_length=canvas_length,
vocab_size=model_config.get_vocab_size(),
async_scheduling=True,
)
@@ -100,7 +99,7 @@ def test_diffusion_extra_args_are_validated_without_a_served_canvas():
{"diffusion_canvas_length": 8},
],
)
def test_narrow_diffusion_canvas_requires_async_scheduling(
def test_diffusion_canvas_width_is_accepted_with_either_scheduler(
async_scheduling, extra_args
):
processor = SimpleNamespace(
@@ -115,11 +114,7 @@ def test_narrow_diffusion_canvas_requires_async_scheduling(
validate_logits_processors_params=lambda params: None,
)
params = SamplingParams(extra_args=extra_args)
if not async_scheduling and extra_args.get("diffusion_canvas_length") == 4:
with pytest.raises(VLLMValidationError, match="requires --async-scheduling"):
InputProcessor._validate_params(processor, params, ("generate",))
else:
InputProcessor._validate_params(processor, params, ("generate",))
InputProcessor._validate_params(processor, params, ("generate",))
@pytest.mark.parametrize(
+48 -9
View File
@@ -42,6 +42,7 @@ from vllm.v1.core.kv_cache_coordinator import HybridKVCacheCoordinator
from vllm.v1.core.kv_cache_utils import get_request_block_hasher, init_none_hash
from vllm.v1.core.sched.diffusion_scheduler import (
DiffusionAsyncScheduler,
DiffusionScheduler,
diffusion_canvas_width,
)
from vllm.v1.core.sched.interface import PauseState
@@ -7109,14 +7110,15 @@ def diffusion_model_runner(monkeypatch):
monkeypatch.setenv("VLLM_USE_V2_MODEL_RUNNER", "1")
def _diffusion_scheduler(**kwargs) -> DiffusionAsyncScheduler:
def _diffusion_scheduler(async_scheduling: bool = True, **kwargs) -> DiffusionScheduler:
scheduler_cls = DiffusionAsyncScheduler if async_scheduling else DiffusionScheduler
scheduler = create_scheduler(
async_scheduling=True,
async_scheduling=async_scheduling,
diffusion_canvas_length=8,
scheduler_cls=DiffusionAsyncScheduler,
scheduler_cls=scheduler_cls,
**kwargs,
)
assert isinstance(scheduler, DiffusionAsyncScheduler)
assert isinstance(scheduler, scheduler_cls)
return scheduler
@@ -7127,7 +7129,7 @@ def test_diffusion_scheduler_is_selected_by_default(async_scheduling):
async_scheduling=async_scheduling, diffusion_canvas_length=8
).vllm_config.scheduler_config
assert config.get_scheduler_cls() is (
DiffusionAsyncScheduler if config.async_scheduling else Scheduler
DiffusionAsyncScheduler if config.async_scheduling else DiffusionScheduler
)
@@ -7149,10 +7151,13 @@ def test_diffusion_scheduler_narrows_the_canvas_per_request():
@pytest.mark.parametrize("structured", [False, True])
@pytest.mark.parametrize("async_scheduling", [False, True])
@pytest.mark.usefixtures("diffusion_model_runner")
def test_diffusion_scheduler_trims_full_width_worker_drafts(structured):
def test_diffusion_scheduler_trims_full_width_worker_drafts(
structured, async_scheduling
):
"""Padded worker drafts must be narrowed before scheduling or grammar validation."""
scheduler = _diffusion_scheduler()
scheduler = _diffusion_scheduler(async_scheduling=async_scheduling)
wide = _diffusion_request("wide", {})
narrow = _diffusion_request("narrow", {"diffusion_canvas_length": 4})
for request in (wide, narrow):
@@ -7167,8 +7172,12 @@ def test_diffusion_scheduler_trims_full_width_worker_drafts(structured):
)
tokens = list(range(8)) if structured else [-1] * 8
drafts = DraftTokenIds(["wide", "narrow"], [tokens.copy(), tokens.copy()])
output = scheduler.schedule()
scheduler.update_draft_token_ids_in_output(drafts, output)
if async_scheduling:
output = scheduler.schedule()
scheduler.update_draft_token_ids_in_output(drafts, output)
else:
scheduler.update_draft_token_ids(drafts)
output = scheduler.schedule()
assert output.scheduled_spec_decode_tokens == {
"wide": tokens,
@@ -7180,6 +7189,36 @@ def test_diffusion_scheduler_trims_full_width_worker_drafts(structured):
assert narrow.structured_output_request.grammar.seen == [tokens[:4]]
@pytest.mark.parametrize(
"sampled, expected_status",
[
pytest.param([], RequestStatus.RUNNING, id="denoising"),
pytest.param([1] * 4, RequestStatus.FINISHED_LENGTH_CAPPED, id="final"),
],
)
@pytest.mark.usefixtures("diffusion_model_runner")
def test_sync_diffusion_step_commits_only_emitted_tokens(sampled, expected_status):
"""An empty denoising step reuses the canvas; a completed read emits it."""
scheduler = _diffusion_scheduler(async_scheduling=False)
request = _diffusion_request(
"read", {"diffusion_canvas_length": 4, "diffusion_read_only": True}
)
request.max_tokens = request.sampling_params.max_tokens = 4
scheduler.add_request(request)
_model_output(scheduler, scheduler.schedule(), [[]])
scheduler.update_draft_token_ids(
DraftTokenIds([request.request_id], [list(range(8))])
)
output = scheduler.schedule()
assert output.num_scheduled_tokens == {request.request_id: 4}
_model_output(scheduler, output, [sampled])
assert request.num_computed_tokens == request.num_prompt_tokens + len(sampled)
assert list(request.output_token_ids) == sampled
assert request.status == expected_status
@pytest.mark.usefixtures("diffusion_model_runner")
def test_diffusion_scheduler_defers_a_read_with_every_step_in_flight():
scheduler = _diffusion_scheduler()
+6 -2
View File
@@ -2020,11 +2020,15 @@ class VllmConfig:
# After the platform hook, which has the last word on async scheduling.
if (
self.diffusion_config is not None
and self.scheduler_config.async_scheduling
and self.scheduler_config.scheduler_cls is None
):
scheduler_name = (
"DiffusionAsyncScheduler"
if self.scheduler_config.async_scheduling
else "DiffusionScheduler"
)
self.scheduler_config.scheduler_cls = (
"vllm.v1.core.sched.diffusion_scheduler.DiffusionAsyncScheduler"
f"vllm.v1.core.sched.diffusion_scheduler.{scheduler_name}"
)
self._normalize_piecewise_cudagraph_mode(
-10
View File
@@ -15,7 +15,6 @@ def validate_diffusion_sampling_params(
*,
canvas_length: int | None,
vocab_size: int,
async_scheduling: bool | None,
) -> None:
"""Validate request options and normalize one-canvas reads at admission."""
extra = params.extra_args
@@ -105,12 +104,3 @@ def validate_diffusion_sampling_params(
bool(params.logprob_token_ids),
"diffusion_constrained needs logprob_token_ids: they are the allowed set.",
)
check(
bool(async_scheduling)
or width is None
or canvas_length is None
or width == canvas_length,
"A diffusion_canvas_length smaller than the served canvas "
"requires --async-scheduling.",
)
+19 -8
View File
@@ -1,15 +1,11 @@
# 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.
"""
"""Canvas-width handling and async read deferral for diffusion requests."""
from vllm.v1.core.sched.async_scheduler import AsyncScheduler
from vllm.v1.core.sched.output import SchedulerOutput
from vllm.v1.core.sched.scheduler import Scheduler
from vllm.v1.outputs import DraftTokenIds
from vllm.v1.request import Request
@@ -38,7 +34,22 @@ def _read_in_flight(request: Request, width: int) -> bool:
return request.num_output_placeholders >= steps * width
class DiffusionAsyncScheduler(AsyncScheduler):
class DiffusionScheduler(Scheduler):
def update_draft_token_ids(self, draft_token_ids: DraftTokenIds) -> None:
for i, (req_id, token_ids) in enumerate(
zip(draft_token_ids.req_ids, draft_token_ids.draft_token_ids)
):
request = self.requests.get(req_id)
if request is None:
continue
width = diffusion_canvas_width(request, self.num_spec_tokens)
# Remove padded positions before the base scheduler validates grammar.
if len(token_ids) > width:
draft_token_ids.draft_token_ids[i] = token_ids[:width]
super().update_draft_token_ids(draft_token_ids)
class DiffusionAsyncScheduler(DiffusionScheduler, AsyncScheduler):
def schedule(self, throttle_prefills: bool = False) -> SchedulerOutput:
for request in self.running:
width = diffusion_canvas_width(request, self.num_spec_tokens)
-1
View File
@@ -158,7 +158,6 @@ class InputProcessor:
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: