-
Notifications
You must be signed in to change notification settings - Fork 256
feat(dspark): expose forced-rejection diagnostics #1170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jhinpan
wants to merge
1
commit into
lightseekorg:main
Choose a base branch
from
jhinpan:jhinpan/feat-1132-forced-rejection-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+138
−4
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| """Forced-rejection control for acceptance-independent speculative timing.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import sys | ||
| from types import SimpleNamespace | ||
| from unittest import mock | ||
|
|
||
| import torch | ||
|
|
||
| _TEST_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
| sys.path.insert(0, _TEST_DIR) | ||
| sys.path.insert(0, os.path.dirname(_TEST_DIR)) | ||
|
|
||
| from ci_system.ci_register import register_cuda_ci | ||
|
|
||
| register_cuda_ci(est_time=5, suite="runtime-1gpu") | ||
|
|
||
| from test.runtime.conftest import requires_cuda | ||
|
|
||
| import tokenspeed.runtime.execution.input_buffer as input_buffer_module | ||
| import tokenspeed.runtime.execution.model_executor as model_executor_module | ||
| from tokenspeed.runtime.execution.input_buffer import InputBuffers | ||
| from tokenspeed.runtime.execution.model_executor import ModelExecutor | ||
|
|
||
|
|
||
| def _executor(force_mask: torch.Tensor) -> ModelExecutor: | ||
| executor = ModelExecutor.__new__(ModelExecutor) | ||
| executor.input_buffers = SimpleNamespace(force_single_token_verify_buf=force_mask) | ||
| return executor | ||
|
|
||
|
|
||
| def test_local_decode_keeps_acceptance_unchanged_by_default() -> None: | ||
| accept_lengths = torch.tensor([4, 2], dtype=torch.int32) | ||
| executor = _executor(torch.tensor([True, True])) | ||
|
|
||
| with mock.patch.object(model_executor_module, "FORCE_SINGLE_TOKEN_VERIFY", False): | ||
| actual = executor._apply_force_single_token_verify( | ||
| accept_lengths, | ||
| row_offset=0, | ||
| row_count=2, | ||
| decode_input_ids=None, | ||
| ) | ||
|
|
||
| assert actual is accept_lengths | ||
|
|
||
|
|
||
| def test_remote_recovery_mask_forces_only_marked_rows() -> None: | ||
| executor = _executor(torch.tensor([False, True, False])) | ||
|
|
||
| with mock.patch.object(model_executor_module, "FORCE_SINGLE_TOKEN_VERIFY", False): | ||
| actual = executor._apply_force_single_token_verify( | ||
| torch.tensor([4, 5], dtype=torch.int32), | ||
| row_offset=1, | ||
| row_count=2, | ||
| decode_input_ids=[7, -1], | ||
| ) | ||
|
|
||
| assert actual.tolist() == [1, 5] | ||
|
|
||
|
|
||
| def test_global_control_forces_local_decode_rows() -> None: | ||
| executor = _executor(torch.tensor([True, True])) | ||
|
|
||
| with mock.patch.object(model_executor_module, "FORCE_SINGLE_TOKEN_VERIFY", True): | ||
| actual = executor._apply_force_single_token_verify( | ||
| torch.tensor([8, 3], dtype=torch.int32), | ||
| row_offset=0, | ||
| row_count=2, | ||
| decode_input_ids=None, | ||
| ) | ||
|
|
||
| assert actual.tolist() == [1, 1] | ||
|
|
||
|
|
||
| def test_input_buffer_initializes_global_force_mask() -> None: | ||
| with mock.patch.object(input_buffer_module, "FORCE_SINGLE_TOKEN_VERIFY", True): | ||
| buffers = InputBuffers( | ||
| max_bs=3, | ||
| max_num_tokens=8, | ||
| page_size=4, | ||
| dummy_kv_slot=0, | ||
| state_write_padding_pool_index=0, | ||
| device="cpu", | ||
| ) | ||
|
|
||
| assert buffers.force_single_token_verify_buf.tolist() == [True, True, True] | ||
|
|
||
|
|
||
| @requires_cuda | ||
| def test_global_force_is_cuda_graph_capturable() -> None: | ||
| executor = _executor(torch.ones(2, dtype=torch.bool, device="cuda")) | ||
| accept_lengths = torch.tensor([8, 3], dtype=torch.int32, device="cuda") | ||
|
|
||
| with mock.patch.object(model_executor_module, "FORCE_SINGLE_TOKEN_VERIFY", True): | ||
| # Warm up the elementwise selection before capture. | ||
| executor._apply_force_single_token_verify( | ||
| accept_lengths, | ||
| row_offset=0, | ||
| row_count=2, | ||
| decode_input_ids=None, | ||
| ) | ||
| graph = torch.cuda.CUDAGraph() | ||
| with torch.cuda.graph(graph): | ||
| captured = executor._apply_force_single_token_verify( | ||
| accept_lengths, | ||
| row_offset=0, | ||
| row_count=2, | ||
| decode_input_ids=None, | ||
| ) | ||
|
|
||
| accept_lengths.fill_(6) | ||
| graph.replay() | ||
| torch.cuda.synchronize() | ||
| assert captured.tolist() == [1, 1] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
TOKENSPEED_FORCE_SINGLE_TOKEN_VERIFY=1is used with thetriton_fullorflashinfer_fullsampling backend and repetition, frequency, or presence penalties, this override happens only afterverify()has already updated its token-count state from the unmodifiedaccept_index(triton_full.py:548-560,flashinfer_full.py:476-488). Tokens discarded by forcing the returned length to one therefore remain in the sampler's history and alter penalties in subsequent rounds, so the diagnostic no longer behaves as though it committed exactly one token. Pass the forced width into verification or otherwise limit/undo the count accumulation for discarded tokens.Useful? React with 👍 / 👎.