-
-
Notifications
You must be signed in to change notification settings - Fork 130
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
feat: typical_p threshold sampling #343
Open
AlpinDale
wants to merge
10
commits into
main
Choose a base branch
from
feat/typ_p_threshold
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
10 commits
Select commit
Hold shift + click to select a range
1f8e3f0
add typical threshold
AlpinDale 36ac0e8
add to api
AlpinDale 9818904
formatting
AlpinDale 0fdce07
correctly pass the threshold param
AlpinDale 0965d5d
clone and detached the params from the original tensors
AlpinDale aee216c
remove unneeded test unit
AlpinDale 356881d
formatting again
AlpinDale 3e3bb75
typical_threshold -> typical_p_sigma
AlpinDale 1e0e058
unsqueeze and add test
AlpinDale f0aa9b7
use a local variable
AlpinDale 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
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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import pytest | ||
import torch | ||
|
||
from aphrodite.modeling.layers.sampler import _apply_typical_sampling | ||
|
||
def test_typical_sampling_shape(): | ||
logits = torch.randn(10, 5) | ||
typical_p = torch.randn(10) | ||
typical_p_sigma = torch.randn(10) | ||
output = _apply_typical_sampling(logits, typical_p, typical_p_sigma) | ||
assert output.shape == logits.shape, "Output shape should match input shape" | ||
|
||
def test_typical_sampling_dtype(): | ||
logits = torch.randn(10, 5) | ||
typical_p = torch.randn(10) | ||
typical_p_sigma = torch.randn(10) | ||
output = _apply_typical_sampling(logits, typical_p, typical_p_sigma) | ||
assert output.dtype == logits.dtype, "Output dtype should match input dtype" | ||
|
||
def test_typical_sampling_device(): | ||
logits = torch.randn(10, 5) | ||
typical_p = torch.randn(10) | ||
typical_p_sigma = torch.randn(10) | ||
output = _apply_typical_sampling(logits, typical_p, typical_p_sigma) | ||
assert output.device == logits.device, "Output dev should match input dev" | ||
|
||
def test_typical_sampling_inf(): | ||
logits = torch.randn(10, 5) | ||
typical_p = torch.randn(10) | ||
typical_p_sigma = torch.randn(10) | ||
output = _apply_typical_sampling(logits, typical_p, typical_p_sigma) | ||
assert not torch.isinf(output).any(), "Output should not contain inf" | ||
|
||
def test_typical_sampling_nan(): | ||
logits = torch.randn(10, 5) | ||
typical_p = torch.randn(10) | ||
typical_p_sigma = torch.randn(10) | ||
output = _apply_typical_sampling(logits, typical_p, typical_p_sigma) | ||
assert not torch.isnan(output).any(), "Output should not contain NaN" |
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.
I disagree with this change (or the intentions in the code here). The modification in my original hack (not posted in this PR) was intended to retain the basic behavior of Typical_P, which first sorts the surprisal deviations by their absolute value.
Only after this is done, then, using the signed surprisal deviations (copied into a different tensor before computing the absolute values for the other), you would obtain a second subset for extending the token selection as in the algorithm described in the explanation in the discussion.