-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
[V1][Spec Decode][Feature] Spec decode with probs #20459
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
andylolu2
wants to merge
15
commits into
vllm-project:main
Choose a base branch
from
andylolu2:andy/v1-sd-with-probs
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.
Open
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c8e31e6
Spec decode with probs
andylolu2 5937e7b
Update vllm/v1/spec_decode/eagle.py
andylolu2 c2dd566
Warmup
andylolu2 20e43fd
torch compile sampling kernel
andylolu2 20a8a36
Merge branch 'main' into andy/v1-sd-with-probs
andylolu2 d7e5edb
Merge branch 'main' into andy/v1-sd-with-probs
andylolu2 98a58f5
Fix tests
andylolu2 3e42139
Clean up
andylolu2 1bf1f83
Better test
andylolu2 4b83278
Fix scheduling test
andylolu2 19ce732
Script
andylolu2 760f97d
Naming
andylolu2 e44a6e5
Merge branch 'main' into andy/v1-sd-with-probs
andylolu2 46465c0
Fix indent
andylolu2 e594708
Fix merge conflict
andylolu2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,253 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
| import tempfile | ||
|
|
||
| import pytest | ||
| import torch | ||
|
|
||
| from tests.v1.worker.test_gpu_model_runner import _schedule_new_request | ||
| from vllm.config import VllmConfig | ||
| from vllm.distributed import (cleanup_dist_env_and_memory, | ||
| init_distributed_environment, | ||
| initialize_model_parallel) | ||
| from vllm.engine.arg_utils import EngineArgs | ||
| from vllm.v1.core.sched.output import CachedRequestData, SchedulerOutput | ||
| from vllm.v1.engine.core import get_kv_cache_config | ||
| from vllm.v1.worker.gpu_model_runner import GPUModelRunner | ||
|
|
||
| model_dir = "meta-llama/Llama-3.1-8B-Instruct" | ||
| eagle_dir = "yuhuili/EAGLE-LLaMA3.1-Instruct-8B" | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def should_do_global_cleanup_after_test(request) -> bool: | ||
| # So we can share the DraftModelProposer between tests | ||
| return False | ||
|
|
||
|
|
||
| @pytest.fixture(scope="class") | ||
| def monkeyclass(): | ||
| with pytest.MonkeyPatch.context() as mp: | ||
| yield mp | ||
|
|
||
|
|
||
| @pytest.fixture(scope="class") | ||
| def spec_decode_vllm_config_and_env_setup(monkeyclass: pytest.MonkeyPatch): | ||
| with monkeyclass.context() as m: | ||
| m.setenv("VLLM_USE_V1", "1") | ||
| vllm_config = EngineArgs(model=model_dir, | ||
| max_model_len=256, | ||
| cuda_graph_sizes=[1, 2, 4], | ||
| gpu_memory_utilization=0.8, | ||
| speculative_config={ | ||
| "model": eagle_dir, | ||
| "method": "eagle", | ||
| "num_speculative_tokens": 2, | ||
| }).create_engine_config() | ||
| temp_file = tempfile.mkstemp()[1] | ||
| init_distributed_environment( | ||
| world_size=1, | ||
| rank=0, | ||
| distributed_init_method=f"file://{temp_file}", | ||
| local_rank=0, | ||
| backend="nccl", | ||
| ) | ||
| initialize_model_parallel(1, 1) | ||
| yield vllm_config | ||
| cleanup_dist_env_and_memory() | ||
|
|
||
|
|
||
| @pytest.fixture(scope="class") | ||
| def mock_spec_decode_model_runner( | ||
| spec_decode_vllm_config_and_env_setup: VllmConfig): | ||
| model_runner = GPUModelRunner(spec_decode_vllm_config_and_env_setup, | ||
| torch.device("cuda")) | ||
| model_runner.load_model() | ||
| kv_cache_spec = model_runner.get_kv_cache_spec() | ||
|
|
||
| kv_cache_config = get_kv_cache_config( | ||
| spec_decode_vllm_config_and_env_setup, kv_cache_spec, 1024**3) # 1GB | ||
| model_runner.initialize_kv_cache(kv_cache_config) | ||
| yield model_runner | ||
|
|
||
|
|
||
| class TestSpecDecodeScheduling: | ||
|
|
||
| def test_spec_decode_partial_scheduling( | ||
| self, mock_spec_decode_model_runner: GPUModelRunner): | ||
| """Make sure we don't crash when the scheduler schedules only a subset | ||
| of the requests. | ||
|
|
||
| Four iterations: | ||
| 1. Schedule both req1 (w/ 0 draft) and req2 (w/ 0 draft) | ||
| 2. Schedule only req1 (w/ 1 draft) | ||
| 3. Schedule both req1 (w/ 1 draft) and req2 (w/ 2 draft) | ||
| 4. Terminate req1 and req2 | ||
| """ | ||
| # Schedule both req1 and req2 on the first iteration | ||
| scheduler_output = _schedule_new_request("req1", "req2") | ||
| mock_spec_decode_model_runner.execute_model(scheduler_output) | ||
|
|
||
| # Only schedule req1 on the second iteration | ||
| cached_req_data = CachedRequestData( | ||
| req_ids=["req1"], | ||
| resumed_from_preemption=[False], | ||
| new_token_ids=[[3]], | ||
| new_block_ids=[([], )], | ||
| num_computed_tokens=[3], | ||
| ) | ||
| scheduler_output = SchedulerOutput( | ||
| scheduled_new_reqs=[], | ||
| scheduled_cached_reqs=cached_req_data, | ||
| num_scheduled_tokens={"req1": 2}, | ||
| total_num_scheduled_tokens=2, | ||
| scheduled_spec_decode_tokens={"req1": [1001]}, | ||
| scheduled_encoder_inputs={}, | ||
| num_common_prefix_blocks=[0], | ||
| finished_req_ids=set(), | ||
| free_encoder_input_ids=[], | ||
| structured_output_request_ids={}, | ||
| grammar_bitmask=None, | ||
| ) | ||
| mock_spec_decode_model_runner.execute_model(scheduler_output) | ||
|
|
||
| # Schedule both req1 and req2 on the third iteration | ||
| cached_req_data = CachedRequestData( | ||
| req_ids=["req1", "req2"], | ||
| resumed_from_preemption=[False, False], | ||
| new_token_ids=[[10], [11]], | ||
| new_block_ids=[([], ), ([], )], | ||
| num_computed_tokens=[4, 3], | ||
| ) | ||
| scheduler_output = SchedulerOutput( | ||
| scheduled_new_reqs=[], | ||
| scheduled_cached_reqs=cached_req_data, | ||
| num_scheduled_tokens={ | ||
| "req1": 2, | ||
| "req2": 3 | ||
| }, | ||
| total_num_scheduled_tokens=5, | ||
| scheduled_spec_decode_tokens={ | ||
| "req1": [1001], | ||
| "req2": [2001, 2002] | ||
| }, | ||
| scheduled_encoder_inputs={}, | ||
| num_common_prefix_blocks=[0], | ||
| finished_req_ids=set(), | ||
| free_encoder_input_ids=[], | ||
| structured_output_request_ids={}, | ||
| grammar_bitmask=None, | ||
| ) | ||
| mock_spec_decode_model_runner.execute_model(scheduler_output) | ||
|
|
||
| # Terminate both req1 and req2 | ||
| cached_req_data = CachedRequestData( | ||
| req_ids=[], | ||
| resumed_from_preemption=[], | ||
| new_token_ids=[], | ||
| new_block_ids=[], | ||
| num_computed_tokens=[], | ||
| ) | ||
| scheduler_output = SchedulerOutput( | ||
| scheduled_new_reqs=[], | ||
| scheduled_cached_reqs=cached_req_data, | ||
| num_scheduled_tokens={}, | ||
| total_num_scheduled_tokens=0, | ||
| scheduled_spec_decode_tokens={}, | ||
| scheduled_encoder_inputs={}, | ||
| num_common_prefix_blocks=[0], | ||
| finished_req_ids={"req1", "req2"}, | ||
| free_encoder_input_ids=[], | ||
| structured_output_request_ids={}, | ||
| grammar_bitmask=None, | ||
| ) | ||
| mock_spec_decode_model_runner.execute_model(scheduler_output) | ||
|
|
||
| def test_spec_decode_preemption_scheduling( | ||
| self, mock_spec_decode_model_runner: GPUModelRunner): | ||
| """Make sure we don't crash when the scheduler preempts a request. | ||
|
|
||
| Four iterations: | ||
| 1. Schedule req1 (w/ 0 draft) and req2 (w/ 0 draft) | ||
| 2. Schedule req1 (w/ 1 draft) and preempt req2 | ||
| 3. Schedule req1 (w/ 1 draft) and resume req2 (w/ 2 draft) | ||
| 4. Terminate req1 and req2 | ||
| """ | ||
| # Schedule both req1 and req2 on the first iteration | ||
| scheduler_output = _schedule_new_request("req1", "req2") | ||
| mock_spec_decode_model_runner.execute_model(scheduler_output) | ||
|
|
||
| # Only schedule req1 on the second iteration | ||
| cached_req_data = CachedRequestData( | ||
| req_ids=["req1"], | ||
| resumed_from_preemption=[False], | ||
| new_token_ids=[[3]], | ||
| new_block_ids=[([], )], | ||
| num_computed_tokens=[3], | ||
| ) | ||
| scheduler_output = SchedulerOutput( | ||
| scheduled_new_reqs=[], | ||
| scheduled_cached_reqs=cached_req_data, | ||
| num_scheduled_tokens={"req1": 2}, | ||
| total_num_scheduled_tokens=2, | ||
| scheduled_spec_decode_tokens={"req1": [1001]}, | ||
| scheduled_encoder_inputs={}, | ||
| num_common_prefix_blocks=[0], | ||
| finished_req_ids=set(), | ||
| free_encoder_input_ids=[], | ||
| structured_output_request_ids={}, | ||
| grammar_bitmask=None, | ||
| ) | ||
| mock_spec_decode_model_runner.execute_model(scheduler_output) | ||
|
|
||
| # Schedule both req1 and req2 on the third iteration | ||
| cached_req_data = CachedRequestData( | ||
| req_ids=["req1", "req2"], | ||
| resumed_from_preemption=[False, True], | ||
| new_token_ids=[[10], [11]], | ||
| new_block_ids=[([], ), ([0], )], | ||
| num_computed_tokens=[4, 0], | ||
| ) | ||
| scheduler_output = SchedulerOutput( | ||
| scheduled_new_reqs=[], | ||
| scheduled_cached_reqs=cached_req_data, | ||
| num_scheduled_tokens={ | ||
| "req1": 2, | ||
| "req2": 6 | ||
| }, | ||
| total_num_scheduled_tokens=8, | ||
| scheduled_spec_decode_tokens={ | ||
| "req1": [1001], | ||
| "req2": [2001, 2002] | ||
| }, | ||
| scheduled_encoder_inputs={}, | ||
| num_common_prefix_blocks=[0], | ||
| finished_req_ids=set(), | ||
| free_encoder_input_ids=[], | ||
| structured_output_request_ids={}, | ||
| grammar_bitmask=None, | ||
| ) | ||
| mock_spec_decode_model_runner.execute_model(scheduler_output) | ||
|
|
||
| # Terminate both req1 and req2 | ||
| cached_req_data = CachedRequestData( | ||
| req_ids=[], | ||
| resumed_from_preemption=[], | ||
| new_token_ids=[], | ||
| new_block_ids=[], | ||
| num_computed_tokens=[], | ||
| ) | ||
| scheduler_output = SchedulerOutput( | ||
| scheduled_new_reqs=[], | ||
| scheduled_cached_reqs=cached_req_data, | ||
| num_scheduled_tokens={}, | ||
| total_num_scheduled_tokens=0, | ||
| scheduled_spec_decode_tokens={}, | ||
| scheduled_encoder_inputs={}, | ||
| num_common_prefix_blocks=[0], | ||
| finished_req_ids={"req1", "req2"}, | ||
| free_encoder_input_ids=[], | ||
| structured_output_request_ids={}, | ||
| grammar_bitmask=None, | ||
| ) | ||
| mock_spec_decode_model_runner.execute_model(scheduler_output) |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.