-
Notifications
You must be signed in to change notification settings - Fork 56
Tkv limit bug #954
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
Merged
Merged
Tkv limit bug #954
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
407ddad
Add test case to reproduce tkv bug during ongoing batch
Daniel-Schenker 44fa344
Introduce initial fix for tkv limit bug
Daniel-Schenker 525ec8a
Add some comments
Daniel-Schenker e4a33b0
Formatting changes
Daniel-Schenker 0fd53ea
Address comments and ruff formatting
Daniel-Schenker 9b0b50d
Remove unused n_blocks arg from check_batch_tkv_limit_cp
Daniel-Schenker 9305204
ruff formatting
Daniel-Schenker 2561850
Remove n_blocks from function call
Daniel-Schenker 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,3 +80,106 @@ def test_scheduler_tkv_limits(monkeypatch: pytest.MonkeyPatch): | |
| scheduler.update_from_output(sched_output, output) | ||
| if len(scheduler.running) == 0: | ||
| break | ||
|
|
||
|
|
||
| @pytest.mark.cpu | ||
| @pytest.mark.chunked_prefill | ||
| def test_scheduler_tkv_limits_ongoing_batch(monkeypatch: pytest.MonkeyPatch): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A high-level overview of what's going on here would be great. IIUC this situation is:
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
| """ | ||
| Test that the scheduler correctly enforces the TKV limit constraint | ||
| when new requests are added during an ongoing batch. | ||
|
|
||
| This test schedules a 16x8k batch that will fully fill the 128k TKV limit. | ||
| Then inject a batch of smaller requests partway through processing, | ||
| which should be able to schedule only because they are guaranteed to | ||
| finish processing just before the TKV is long enough to overrun the | ||
| limit with the larger batch size. This flexes the logic for injecting | ||
| shorter requests into a running batch, which is not tested by the | ||
| other test case in this file. | ||
|
|
||
| Expected behavior (when bug is fixed): | ||
| - Test should pass without exceeding hardware constraints | ||
|
|
||
| Current behavior (with bug): | ||
| - Scheduler accepts invalid batch configurations | ||
| - Test will fail with assertion errors | ||
| """ | ||
| # Setup: Use the default test model | ||
| model = REFERENCE_MODELS[InstrumentedModelRunner.DEFAULT_TEST_MODEL] | ||
|
|
||
| # Build model runner with specific constraints | ||
| model_runner = InstrumentedModelRunner.build( | ||
| monkeypatch=monkeypatch, | ||
| max_num_batched_tokens=512, | ||
| max_num_seqs=32, | ||
| max_model_len=32768, | ||
| available_blocks=32768, | ||
| ) | ||
|
|
||
| # Configure the TKV limit | ||
| scheduler = model_runner.scheduler | ||
| scheduler.max_batch_tkv_limit = 131072 | ||
| SpyrePlatform._max_batch_tkv_limit = 131072 | ||
| monkeypatch.setenv("VLLM_DT_MAX_BATCH_TKV_LIMIT", "131072") | ||
|
|
||
| # Define prompt lengths and max tokens for requests | ||
| prompt_lengths = [1018] + [1024] * 15 | ||
| max_tokens_1 = 7168 | ||
| max_tokens_2 = 900 | ||
|
|
||
| # Create and add first set of requests to the scheduler | ||
| requests = [] | ||
| for request_id, prompt_length in enumerate(prompt_lengths): | ||
| prompt = random_prompt(model=model, seed=request_id, length=prompt_length) | ||
| request = create_request_for_scheduler_test( | ||
| model=model, | ||
| request_id=request_id, | ||
| add_step=0, | ||
| max_tokens=max_tokens_1, | ||
| prompt=prompt, | ||
| use_golden_token_injection=False, | ||
| generate_hf_results=False, | ||
| ).request | ||
| requests.append(request) | ||
| scheduler.add_request(request) | ||
|
|
||
| # Failure was observed in testing when first request generated 2920 tokens | ||
| target_generated_tokens = 2920 | ||
|
|
||
| # Run the scheduler loop until first set of requests have generated tokens | ||
| while True: | ||
| sched_output = scheduler.schedule() | ||
| output = model_runner.execute_model(sched_output) | ||
| scheduler.update_from_output(sched_output, output) | ||
|
|
||
| target_req = requests[0] | ||
|
|
||
| if target_req: | ||
| generated = target_req.num_computed_tokens - target_req.num_prompt_tokens | ||
| if generated >= target_generated_tokens: | ||
| break | ||
|
|
||
| # Create and add second set requests to the scheduler | ||
| for request_id, prompt_length in enumerate(prompt_lengths): | ||
| prompt = random_prompt(model=model, seed=request_id + 16, length=prompt_length) | ||
| request = create_request_for_scheduler_test( | ||
| model=model, | ||
| request_id=request_id + 16, | ||
| add_step=0, | ||
| max_tokens=max_tokens_2, | ||
| prompt=prompt, | ||
| use_golden_token_injection=False, | ||
| generate_hf_results=False, | ||
| ).request | ||
| requests.append(request) | ||
| scheduler.add_request(request) | ||
|
|
||
| # Run the scheduler loop until all requests complete | ||
| # With the bug present, the scheduler will incorrectly accept a batch | ||
| # configuration that exceeds the TKV limit | ||
| while True: | ||
| sched_output = scheduler.schedule() | ||
| output = model_runner.execute_model(sched_output) | ||
| scheduler.update_from_output(sched_output, output) | ||
| if len(scheduler.running) == 0: | ||
| break | ||
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.
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.
spicy stuff 🌶️