-
Notifications
You must be signed in to change notification settings - Fork 12.1k
sampling: add Top-nσ sampler to llama-server
#11896
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1bdb603
sampling: add Top-nσ sampler to `llama-server` and sampler ordering
CasualAutopsy ff8b612
revert: sampler ordering
CasualAutopsy 1dc5d84
revert: VS' crappy auto-formatting
CasualAutopsy 9068068
revert: VS' crappy auto-formatting pt.2
CasualAutopsy c05e9e0
revert: my crappy eye sight...
CasualAutopsy a9e7af0
sampling: add XTC to Top-nσ sampler chain
CasualAutopsy cc1a170
sampling: add Dyna. Temp. to Top-nσ sampler chain
CasualAutopsy a558d3a
sampling: actually remove Top-nσ from sampler(oops)
CasualAutopsy 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
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.
This special-case should probably be removed and configure the sampler chain as usual. @VJHack What was the reason to do it this way?
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.
@ggerganov When I tested the sampler it didn't work with the penalties or DRY. I'm sure that's the reason why.
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.
There was a discussion about
top_n_sigma
being added into the main chain, but it was probably lost.This sampler is supposed to run after
temp
(temp_ext
works too), but the current main chain has temperature after all other truncating samplers by default. Iftop_n_sigma
is put in that order, it will suffer from previous samplers that may be used after it, but not before. Ideally, it'stop-k->temp->top_nsigma->*everything else*
, but that would require changing current default order of samplers.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.
Seems like based on comments from the original author of
top_n_sigma
in theaphrodite-engine
PR thread (aphrodite-engine/aphrodite-engine#825), it doesn't matter whethertop_n_sigma
is used before or aftertemperature
, but it will result in errors if it is used after other "alphabet" truncation samplers, with the exception oftop_k
.Uh oh!
There was an error while loading. Please reload this page.
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 made this sampler an exception because of two reasons, one of which is stated in the PR:
top_n_sigma
is done on the logits pre-softmax. Some of the other samplers that would come beforetop_n_sigma
(liketop_p
for example) are taking the softmax before truncating the number of tokens we can sample from. I was concerned that this would degrade the quality of this sampler.top_n_sigma
must be used aftertemperature
is applied. In the paper they repeatedly mention the temperature invariance property being one of the key characteristics of this sampler. @DocShotgun, I understand that this can be a bit confusing but temperature invariance means that the set of candidate tokens remains constant regardless of the temperature value used. According to the algorithm, temperature must be applied beforetop_n_sigma
.I made
top_n_sigma
a special-case (stand alone) sampler because it operates on logits pre-softmax and must come after temperature is applied.I agree with this.
Uh oh!
There was an error while loading. Please reload this page.
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.
Not sure how significant it is for other backends, but applying penalties to the whole vocabulary affects performance in llama.cpp, so it is subject to change in the future, some day.
As for
top_n_sigma
and repetitions, I tested it a bit with the same order as in the main chain, but theoretically it should not be needed. This aspect needs more testing, and I'm currently preoccupied by figuring out if Mistral Small 3 is good or not.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.
Hmm so at least it should function properly with penalties? It doesn't look like penalties are allowed to be used with
top_n_sigma
in this current implementation.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.
Um... Sorry for the trouble, but my scatter brain ass forgot to remove the lines of code that added nsigma to common samplers. It seems to have caused and error with the workflows since it isn't using the nsigma sampler, making it hang infinitely... sorry...
Uh oh!
There was an error while loading. Please reload this page.
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.
Yes, either
repetition penalty
andDRY
should be added to the new chain (aftertop_k
), ortop_n_sigma
should be put into the main chain.I'm not sure if changing the default chain order to
logits->top_k->penalties->temp->*everything else*
is a good idea now, so maybe it is worth putting this idea aside for a separate PR.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.
Let's not add a new chain. We should either put the top-sigma sampler in the existing chain or let the user explicitly add the sampler. Remember that this is just a default configuration, the sampler is noop by default and the user can re-configure the order of the samplers. If the sampler has to be applied before softmax, the user is responsible to construct the sampling chain to make sense.