-
-
Notifications
You must be signed in to change notification settings - Fork 11.3k
test_chunked_prefill_pooler refrencing #23436 #24114
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
ArkVex
wants to merge
7
commits into
vllm-project:main
Choose a base branch
from
ArkVex:main
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c5fe531
test_chunked_prefill_pooler
ArkVex 477abe2
Merge branch 'vllm-project:main' into main
ArkVex f4bc324
test_chunked_prefill_pooler
ArkVex e532ac0
Merge branch 'main' of https://github.com/ArkVex/vllm
ArkVex b1749c9
suggestd changes
ArkVex d7084c0
new changes
ArkVex 0c4e290
updated pr
ArkVex 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
| import pytest | ||
| import os | ||
| import torch | ||
| from vllm.config import ModelConfig, PoolerConfig | ||
| from vllm.model_executor.layers.pooler import LastPool | ||
|
|
||
| def test_chunked_prefill_pooler(monkeypatch): | ||
| """Test chunked prefill for pooling models with LastPool.""" | ||
| model_id = "sentence-transformers/all-MiniLM-L6-v2" | ||
| config = ModelConfig(model_id) | ||
| config.pooler_config = PoolerConfig(pooling_type="LAST") | ||
|
|
||
| # Use a closure to track chunks | ||
| chunks = [] | ||
|
|
||
| class DummyPooler(LastPool): | ||
| def __call__(self, hidden_states, pooling_cursor): | ||
| chunks.append(hidden_states) | ||
| return super().__call__(hidden_states, pooling_cursor) | ||
|
|
||
| monkeypatch.setattr("vllm.model_executor.layers.pooler.LastPool", DummyPooler) | ||
|
|
||
| # Set environment variables for Windows compatibility | ||
| os.environ["VLLM_WORKER_MULTIPROC_METHOD"] = "spawn" | ||
| os.environ["CUDA_VISIBLE_DEVICES"] = "" # Force CPU usage on Windows | ||
|
|
||
| # Set chunking parameters to force chunked prefill | ||
| from vllm.entrypoints.llm import LLM | ||
|
|
||
| # Note: Chunked prefill is automatically handled by vLLM internally based on the model size and prompt | ||
| llm = LLM( | ||
| model=model_id, | ||
| runner="pooling", | ||
| override_pooler_config=PoolerConfig(pooling_type="LAST"), | ||
| trust_remote_code=True, | ||
| tensor_parallel_size=1, | ||
| enforce_eager=True, # Helps with Windows compatibility | ||
| ) | ||
|
|
||
| prompt = "This is a test prompt for chunked prefill." | ||
| output = llm.embed([prompt]) | ||
|
|
||
| # Check that DummyPooler was called and chunks were received | ||
| assert len(chunks) > 0 | ||
|
|
||
| # Verify the sum of the lengths of the chunks matches the prompt length | ||
| total_chunk_len = sum(len(chunk) for chunk in chunks) | ||
| assert total_chunk_len == len(prompt) | ||
|
|
||
| # Compare with non-chunked output | ||
| llm_non_chunked = LLM( | ||
| model=model_id, | ||
| runner="pooling", | ||
| override_pooler_config=PoolerConfig(pooling_type="LAST"), | ||
| trust_remote_code=True, | ||
| tensor_parallel_size=1, | ||
| enforce_eager=True, | ||
| ) | ||
| output_non_chunked = llm_non_chunked.embed([prompt]) | ||
|
|
||
| # Compare embeddings with tolerance for floating point differences | ||
| assert torch.allclose(torch.tensor(output[0]), torch.tensor(output_non_chunked[0]), atol=1e-6) | ||
|
|
||
| # Note: For faster tests, use a smaller model like 'Qwen/Qwen3-Embedding-0.6'. | ||
| # To override the pooler, you can set trust_remote_code=True and use auto_map in hf_config. | ||
|
|
||
| def test_chunked_prefill_prefix_caching(monkeypatch): | ||
| """Test chunked prefill with prefix caching for pooling models.""" | ||
| model_id = "sentence-transformers/all-MiniLM-L6-v2" | ||
| config = ModelConfig(model_id) | ||
| config.pooler_config = PoolerConfig(pooling_type="LAST") | ||
|
|
||
| chunks = [] | ||
|
|
||
| class DummyPooler(LastPool): | ||
| def __call__(self, hidden_states, pooling_cursor): | ||
| chunks.append(hidden_states) | ||
| return super().__call__(hidden_states, pooling_cursor) | ||
|
|
||
| monkeypatch.setattr("vllm.model_executor.layers.pooler.LastPool", DummyPooler) | ||
|
|
||
| # Set environment variables for Windows compatibility | ||
| os.environ["VLLM_WORKER_MULTIPROC_METHOD"] = "spawn" | ||
| os.environ["CUDA_VISIBLE_DEVICES"] = "" # Force CPU usage on Windows | ||
|
|
||
| from vllm.entrypoints.llm import LLM | ||
|
|
||
| # Note: Chunked prefill is automatically handled by vLLM internally based on the model size and prompt | ||
| llm = LLM( | ||
| model=model_id, | ||
| runner="pooling", | ||
| override_pooler_config=PoolerConfig(pooling_type="LAST"), | ||
| trust_remote_code=True, | ||
| tensor_parallel_size=1, | ||
| enforce_eager=True, # Helps with Windows compatibility | ||
| ) | ||
|
|
||
| prefix = "Common prefix. " | ||
| prompt1 = prefix + "First input." | ||
|
Contributor
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. The prefix has to be bigger than a paged attention block, otherwise it's not cached. |
||
| prompt2 = prefix + "Second input." | ||
|
|
||
| llm.embed([prompt1]) | ||
| chunks.clear() | ||
| llm.embed([prompt2]) | ||
|
|
||
| # Only the last hidden states should be checked (those going into the pooler) | ||
| # Verify the sum of the lengths of the chunks matches the prompt length minus prefix | ||
| total_chunk_len = sum(len(chunk) for chunk in chunks) | ||
| assert total_chunk_len == len(prompt2) - len(prefix) | ||
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.
Wait, where is it being configured for prompt prefill?