-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
[Bugfix][V1] Fix allowed_token_ids for v1 Sampler #14169
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a5457a6
Fix allowed_token_ids for v1 Sampler
houseroad 56cf0cc
address comments
houseroad 830f784
address comments to make sure we set the default value for mask corre…
houseroad 661ecf3
address comments to make sure we set the default value for mask corre…
houseroad 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 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 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 |
---|---|---|
|
@@ -199,6 +199,8 @@ def __init__( | |
self.logit_bias: list[Optional[dict[int, | ||
float]]] = [None] * max_num_reqs | ||
self.has_allowed_token_ids: set[str] = set() | ||
# NOTE(lufang): In the mask tensor, if the corresponding token allowed, | ||
# the value is False. Since we use masked_fill_ to set -inf. | ||
self.allowed_token_ids_mask: Optional[torch.Tensor] = None | ||
self.allowed_token_ids_mask_cpu_tensor: Optional[torch.Tensor] = None | ||
|
||
|
@@ -300,17 +302,17 @@ def add_request( | |
self.has_allowed_token_ids.add(req_id) | ||
if self.allowed_token_ids_mask_cpu_tensor is None: | ||
# Lazy allocation for this tensor, which can be large. | ||
self.allowed_token_ids_mask = torch.zeros(self.max_num_reqs, | ||
self.vocab_size, | ||
dtype=torch.bool, | ||
device=self.device) | ||
self.allowed_token_ids_mask_cpu_tensor = torch.zeros( | ||
self.allowed_token_ids_mask = torch.ones(self.max_num_reqs, | ||
self.vocab_size, | ||
dtype=torch.bool, | ||
device=self.device) | ||
self.allowed_token_ids_mask_cpu_tensor = torch.ones( | ||
self.max_num_reqs, | ||
self.vocab_size, | ||
dtype=torch.bool, | ||
device="cpu") | ||
self.allowed_token_ids_mask_cpu_tensor[req_index][ | ||
sampling_params.allowed_token_ids] = True | ||
sampling_params.allowed_token_ids] = False | ||
|
||
# Add request lora ID | ||
if request.lora_request: | ||
|
@@ -359,7 +361,7 @@ def remove_request(self, req_id: str) -> Optional[int]: | |
self.logit_bias[req_index] = None | ||
self.has_allowed_token_ids.discard(req_id) | ||
if self.allowed_token_ids_mask_cpu_tensor is not None: | ||
self.allowed_token_ids_mask_cpu_tensor[req_index].fill_(False) | ||
self.allowed_token_ids_mask_cpu_tensor[req_index].fill_(True) | ||
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. @houseroad this should also be reverted right? 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. True, added more comments to help understand |
||
return req_index | ||
|
||
def swap_states(self, i1: int, i2: int) -> None: | ||
|
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.
I think the updated logic here is a bit counter-intuitive to readers from a glance - can we add a
NOTE
here that all token ids withTrue
mask will be filled withfloat("-inf")
during sampling?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.
yeah, added some comments