-
-
Notifications
You must be signed in to change notification settings - Fork 22.3k
[Bugfix][Frontend] Truncate pooling prompts before padding them #54364
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
60 changes: 60 additions & 0 deletions
60
tests/entrypoints/pooling/scoring/test_io_processor_unit.py
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,60 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
| """Unit tests for ScoringIOProcessor post-tokenization helpers.""" | ||
|
|
||
| from dataclasses import dataclass | ||
|
|
||
| import pytest | ||
|
|
||
| from vllm import TokensPrompt | ||
| from vllm.entrypoints.pooling.scoring.io_processor import ( | ||
| _apply_post_tokenization_to_token_type_ids, | ||
| ) | ||
| from vllm.entrypoints.pooling.scoring.utils import compress_token_type_ids | ||
| from vllm.renderers import TokenizeParams | ||
|
|
||
| pytestmark = pytest.mark.skip_global_cleanup | ||
|
|
||
|
|
||
| @dataclass | ||
| class _DummyTokenizer: | ||
| truncation_side: str = "left" | ||
| # Outside the range of the prompt ids below, so a test can tell a pad | ||
| # token apart from a real one. | ||
| pad_token_id: int = 99999 | ||
|
|
||
|
|
||
| def test_token_type_ids_stay_aligned_with_a_truncated_padded_prompt(): | ||
| """The cross-encoder segment boundary must survive truncate + pad. | ||
|
|
||
| `token_type_ids` are parallel to `prompt_token_ids` and are reduced to a | ||
| single boundary index by `compress_token_type_ids`. If the two arrays are | ||
| truncated and padded in different orders they no longer describe the same | ||
| positions, and the model is told the query segment is empty. | ||
| """ | ||
| tokenizer = _DummyTokenizer() | ||
| num_query, num_doc = 20, 30 | ||
| prompt = TokensPrompt(prompt_token_ids=list(range(num_query + num_doc))) | ||
| token_type_ids = [0] * num_query + [1] * num_doc | ||
|
|
||
| tok_params = TokenizeParams( | ||
| max_total_tokens=100, | ||
| pad_prompt_tokens=-1, | ||
| truncate_prompt_tokens=40, | ||
| truncation_side="left", | ||
| ) | ||
|
|
||
| prompt = tok_params.apply_post_tokenization(tokenizer, prompt) | ||
| token_type_ids = _apply_post_tokenization_to_token_type_ids( | ||
| tokenizer, tok_params, token_type_ids | ||
| ) | ||
|
|
||
| prompt_token_ids = prompt["prompt_token_ids"] | ||
| assert len(token_type_ids) == len(prompt_token_ids) | ||
|
|
||
| # Keeping the last 40 tokens drops the first 10 query tokens, so 10 query | ||
| # tokens survive and the document starts at index 10. | ||
| first_doc = compress_token_type_ids(token_type_ids) | ||
| assert first_doc == 10 | ||
| assert prompt_token_ids[:first_doc] == list(range(10, num_query)) | ||
| assert prompt_token_ids[first_doc:40] == list(range(num_query, 50)) | ||
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
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.