[Bugfix][PP] Never drop a decoding request from the sampled-token broadcast (#54436)
Signed-off-by: ArcheyChen <45146080+ArcheyChen@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -96,7 +96,6 @@ def _make_batch(
|
||||
num_computed_prefill_tokens_np=np.zeros(num_reqs, dtype=np.int32),
|
||||
is_prefilling_np=np.zeros(num_reqs, dtype=np.bool_),
|
||||
has_prefill=False,
|
||||
max_seq_len_np=None,
|
||||
input_ids=torch.zeros(num_tokens, dtype=torch.int32, device=DEVICE),
|
||||
positions=torch.arange(num_tokens, dtype=torch.int64, device=DEVICE),
|
||||
is_padding=torch.zeros(num_tokens, dtype=torch.bool, device=DEVICE),
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""Which rows the PP sampled-token broadcast must carry."""
|
||||
|
||||
from unittest.mock import Mock
|
||||
|
||||
import numpy as np
|
||||
|
||||
from vllm.v1.worker.gpu import pp_utils
|
||||
|
||||
|
||||
def _batch(num_computed, prefill_len, num_scheduled):
|
||||
return Mock(
|
||||
num_reqs=len(num_computed),
|
||||
num_computed_tokens_np=np.array(num_computed, dtype=np.int32),
|
||||
prefill_len_np=np.array(prefill_len, dtype=np.int32),
|
||||
num_scheduled_tokens=np.array(num_scheduled, dtype=np.int32),
|
||||
)
|
||||
|
||||
|
||||
def test_excludes_non_final_prefill_chunks():
|
||||
"""Unchanged behaviour: a chunk that does not finish its prefill is skipped."""
|
||||
# Row 0 is a middle prefill chunk and produces no sample; row 1 finishes its
|
||||
# prefill this step and therefore does.
|
||||
batch = _batch(
|
||||
num_computed=[512, 1000],
|
||||
prefill_len=[4096, 1004],
|
||||
num_scheduled=[448, 4],
|
||||
)
|
||||
|
||||
mask = pp_utils.compute_need_sampled_mask(batch)
|
||||
|
||||
assert mask is not None
|
||||
assert mask.tolist() == [False, True]
|
||||
|
||||
|
||||
def test_none_when_no_row_samples():
|
||||
"""Unchanged behaviour: an all-prefill batch needs no broadcast at all."""
|
||||
batch = _batch(
|
||||
num_computed=[0, 512],
|
||||
prefill_len=[4096, 4096],
|
||||
num_scheduled=[448, 448],
|
||||
)
|
||||
|
||||
assert pp_utils.compute_need_sampled_mask(batch) is None
|
||||
|
||||
|
||||
def test_keeps_decoding_request_past_its_length_cap():
|
||||
"""A decoding request must never be dropped from the broadcast.
|
||||
|
||||
Speculative decoding advances `num_computed_tokens` several tokens per step,
|
||||
so it can overrun `prompt_len + max_tokens` while the scheduler is still
|
||||
running the request. Predicting "this one is finishing" and skipping its
|
||||
broadcast freezes the earlier pipeline stages' `last_sampled_tokens` and
|
||||
`draft_tokens` while the last rank keeps advancing its own, and the stages
|
||||
then diverge permanently.
|
||||
"""
|
||||
batch = _batch(
|
||||
# 14176 computed tokens is already past this request's own
|
||||
# prompt_len + max_tokens; the scheduler is still running it.
|
||||
num_computed=[14176],
|
||||
prefill_len=[12175],
|
||||
num_scheduled=[8],
|
||||
)
|
||||
|
||||
mask = pp_utils.compute_need_sampled_mask(batch)
|
||||
|
||||
assert mask is not None
|
||||
assert mask.tolist() == [True]
|
||||
|
||||
|
||||
def test_decode_row_ahead_of_a_prefill_chunk():
|
||||
"""Row order does not matter: only whether the row finishes its prefill."""
|
||||
batch = _batch(
|
||||
num_computed=[10, 512],
|
||||
prefill_len=[8, 4096],
|
||||
num_scheduled=[1, 448],
|
||||
)
|
||||
|
||||
mask = pp_utils.compute_need_sampled_mask(batch)
|
||||
|
||||
assert mask is not None
|
||||
assert mask.tolist() == [True, False]
|
||||
Reference in New Issue
Block a user