[Bugfix][Spec Decode][V1] Guard stale async spec prev rows - #47199
[Bugfix][Spec Decode][V1] Guard stale async spec prev rows#47199paulbrav wants to merge 1 commit into
Conversation
Signed-off-by: Paul Braverman <git_phony.fqo7y@simplelogin.com>
|
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in PRs do not trigger a full CI run by default. Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can either: Add If you have any questions, please reach out to us on Slack at https://slack.vllm.ai. Agent GuidelinesIMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban. 🚀 |
|
Closing this — the premise was refuted by direct instrumentation. I deployed loud guards at all three sites this PR patches and ran the crash reproduction twice on the affected deployment (2× DGX Spark TP=2, DeepSeek-V4-Flash-DSpark, async scheduling on): zero stale- The actual root cause of the crashes that motivated this PR turned out to be two out-of-bounds-index bugs in the model-recipe code, not in vLLM's async-spec bookkeeping: an unmasked gather over an uninitialized ( All validation data was synthetic. AI-assisted investigation, human-reviewed. Apologies for the noise — closing rather than leaving a speculative guard in the tree. |
Purpose
Fix an async speculative decoding batch-change failure mode where stale previous-batch row indices can outlive the tensors they index.
In async scheduling,
prev_positionsmaps current request rows to rows from the previous worker batch. The existing code handled-1for new requests, but it did not guard positive stale indices when the previous sampled-token/count tensors are shorter than the old batch mapping. That can misattribute sampled counts or index out of bounds during input staging / token-count correction.This PR makes those paths treat out-of-range previous rows the same way as new or non-participating rows.
Summary
prev_positionsagainstvalid_sampled_token_countbefore gathering accepted-token counts inupdate_num_computed_tokens_for_batch_change.prev_positionsagainstprev_sampled_token_idsinGPUModelRunner._prepare_input_ids.Why this is a draft
The original failure was observed in a DGX Spark deployment running DeepSeek V4 Flash DSpark, while this PR currently contributes focused CPU-runnable regression tests for the worker/spec-decode bookkeeping paths. I am opening this as a draft to get early maintainer feedback on whether this should remain a separate worker-side guard or be folded into adjacent async-spec scheduling work before marking it ready for review.
Scope and non-duplicate framing
This is narrower than #40768. That PR addresses
-1placeholder materialization at the scheduler boundary. This PR addresses stale positive previous-row indices inside V1 worker/spec-decode bookkeeping after async batch changes.This is also distinct from #41481, which warms spec-decode helper kernels and touches
update_num_computed_tokens_for_batch_changefor startup latency, not for stale-row correctness.An adversarial placement review considered moving the guard into
_compute_prev_positions, but the consumers have different validity bounds: input staging is bounded byprev_sampled_token_ids, while token-count correction is bounded byvalid_sampled_token_count. Guarding at each consumer keeps the invariant local to the tensor being indexed.Files changed
vllm/v1/spec_decode/utils.py0 <= prev_position < valid_count_len.valid_sampled_token_count.vllm/v1/worker/gpu_model_runner.pyprev_sampled_token_idslength.tests/v1/spec_decode/test_async_batch_change.pyprev_positionsand empty valid counts.tests/v1/worker/test_gpu_model_runner.pyTest Plan
PYTHONPATH=. VLLM_TARGET_DEVICE=cpu .venv/bin/python -m pytest \ tests/v1/spec_decode/test_async_batch_change.py \ tests/v1/worker/test_gpu_model_runner.py \ -k 'async_batch_change or valid_sampled_count_for_prev_index or prepare_input_ids_skips_stale_positive_prev_position' -q uvx ruff format --check \ vllm/v1/spec_decode/utils.py \ vllm/v1/worker/gpu_model_runner.py \ tests/v1/spec_decode/test_async_batch_change.py \ tests/v1/worker/test_gpu_model_runner.pyTest Result
DGX Spark smoke against the deployment that motivated this patch:
spark-01:8888/v1/modelsreports served modeldeepseek-v4-flash-dspark.max_model_len:1048576.AI assistance disclosure
This change was developed with AI assistance. The submitting author reviewed the changed lines, ran the test commands above, and kept this PR in draft for maintainer feedback before requesting review.
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model. Not applicable.