Skip to content

Conversation

yuz207
Copy link

@yuz207 yuz207 commented Oct 14, 2025

Summary

  • Reworks NWOR masking logic to a vectorized cumprod-based approach, preserving masking semantics.
  • Adds speculative chunk verify (SCV) mode support via VLLM_SCV_MODE environment variable with options "off", "graph", or "adaptive" (default "off"). Runtime support integrated into GPUModelRunner with graph-backed execution path and vectorized/graph-based SCV paths.

Changes

NWOR masking

  • In vllm/v1/worker/gpu_model_runner.py, replaced per-slice accepted/reject branching with vectorized computation:
    • Compute comparison = (row == draft_slice)
    • Compute prefix = torch.cumprod(comparison.to(torch.int32), dim=0)
    • Apply mask_work[start:end] = prefix.to(torch.bool)
  • Introduced SCV-aware vectorized path: when SCV is enabled, attempt to use the vectorized SCV routine to produce a mask early.
  • Removed prior explicit accepted/reject handling and related control flow.

SCV mode support

  • In vllm/envs.py, added VLLM_SCV_MODE environment variable with options "off", "graph", or "adaptive" (default "off").
  • In vllm/v1/worker/gpu_model_runner.py, introduced self._scv_mode initialized from envs.VLLM_SCV_MODE.lower() and added _scv_enabled() to validate and enable SCV modes.
  • Added new vectorized SCV path and graph-backed execution support:
    • _scv_vectorized_mask(...) handles SCV mask computation across modes.
    • _SCVGraphEntry and SCVGraphExecutor enable CUDA graph-based SCV execution when in graph mode.

Rationale

  • Simplifies NWOR masking logic and leverages tensor operations for potential performance gains while preserving the same masking semantics (true up to first mismatch, false thereafter).
  • Introduces optional speculative chunk verify modes that can be enabled as needed without altering public APIs.

Tests

  • Validate NWOR mask generation on synthetic slices:
    • All tokens match: mask is all True for the slice
    • Mismatch at various positions: mask is True up to first mismatch, then False
    • Mismatch at first element: mask is all False for the slice
  • Ensure no public API changes and that downstream NWOR paths behave identically.
  • Validate SCV mode parsing and enabling logic (default off; graph/adaptive when configured).
  • Verify graph-based SCV path executes when enabled and CUDA graph is available.
  • New test to ensure SCV vectorized mask matches reference:
    • test_scv_vectorized_mask_matches_reference validates the SCV-based mask equals the expected reference for a given metadata and sampled inputs.

Backwards Compatibility

  • No API changes; internal refactor only. SCV mode defaults to off, maintaining compatibility.

How to Review

  • Focus on the GPUModelRunner NWOR masking block in vllm/v1/worker/gpu_model_runner.py.
  • Verify edge cases (no mismatch, first-element mismatch, later mismatch) behave identically to the previous implementation.
  • Verify SCV mode parsing, enabling logic, and vectorized/graph paths are wired correctly.
  • Review the new SCV graph entry/executor logic to ensure safe graph-based execution and fallback behavior.

📎 Task: https://www.terragonlabs.com/task/cfda0cbe-9bb8-4b82-9858-540824550cf2

@yuz207 yuz207 changed the title Refactor NWOR masking in GPUModelRunner to cumprod Refactor NWOR masking to cumprod; add SCV mode flag Oct 14, 2025
yuz207 added 2 commits October 14, 2025 22:47
Replaced explicit conditional logic and nonzero indexing with a cumulative product approach to compute mask_work. This change streamlines the code for better readability and maintainability without altering functionality.
…omputation

Introduced SCV (Speculative Computation Vectorization) mode to GPUModelRunner to optimize mask computation during decoding. Added SCVGraphExecutor and _SCVGraphEntry classes leveraging CUDA Graphs for efficient repeated mask calculations. The SCV mode supports 'graph' and 'adaptive' operation and falls back gracefully if CUDA graph execution fails. This enhancement improves decoding performance by reusing captured CUDA graphs for mask operations in speculative decoding workflows.

Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
@yuz207 yuz207 changed the title Refactor NWOR masking to cumprod; add SCV mode flag NWOR masking via cumprod; add SCV mode support Oct 14, 2025
yuz207 and others added 4 commits October 14, 2025 22:55
…peculation tokens

Introduce an adaptive mode in the GPUModelRunner to dynamically compute and adjust the speculation token mask based on recent acceptance ratios during decoding. This update adds the `_scv_update_controller` method to modify the number of speculative tokens used, aiming to maintain a target acceptance ratio, improving decoding efficiency and performance.

Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
…V adaptive mode

Add a new unit test `test_scv_vectorized_mask_matches_reference` to validate the behavior of the `_build_nwor_acceptance_mask` method in the GPUModelRunner class configured with SCV adaptive mode. This test ensures the mask output matches the expected reference.

Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
@yuz207 yuz207 changed the title NWOR masking via cumprod; add SCV mode support NWOR masking via cumprod; add SCV modes (graph/adaptive) Oct 15, 2025
yuz207 and others added 2 commits October 15, 2025 00:51
…lization code

The _scv_enabled method was relocated within the GPUModelRunner class to follow the initialization code block, improving code readability and organization without changing functionality.

Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant