Add XTC and token ban sampling steps - #256
Merged
Merged
Conversation
SS_BanTokens masks a fixed set of token IDs. It is recognized alongside the penalty steps when collapsing a stack, so a ban keeps the fused tail. SS_XTC excludes all but the least likely token above its threshold, leaving protected IDs in place. It reweights the distribution rather than drawing the outcome per token, which is the same distribution and needs no RNG. Only the tokens above the threshold are scaled, bounding the work by 1/threshold.
The sorted branches indexed state.indices with the argmax positions alone, selecting rows instead of one token per row. SS_XTC reaches them through its prep steps, as does any stack with an explicit sort and any top-k greedy stack under EXL3_FUSED_SAMPLER=0.
Member
|
Thanks. 👍 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR introduces sampler steps that enable XTC sampling and the banning of tokens. Previous versions such as EXL2 had these sampling features, and they are present (but not hooked up) downstream in TabbyAPI (for the EXL3 backend, they work for the EXL2 backend).
This PR also includes a bugfix for an issue I encountered during testing.
Design Notes
SS_BanTokens: Very straightforward class. We cache the mask to avoid needing to recompute each token.SS_XTC:Bugfix
During testing,
SS_Argmaxappeared to fail on unsorted states. It appears that this is due to the following.The sorted branches indexed
state.indiceswith the argmax positions alone, which selectsrows of the index tensor instead of one token per row:
This appears to have been unreachable before due to the fusion meaning this code was basically never reached. I corrected it by applying the pattern from the
SS.LOGITS_Sstate.Testing
I added some tests to
tests/test_sampler.pyfollowing the existing pattern. The tests check a few various edge cases and also show that our implementation has the same distributional result as the random version of XTC.Reverting only
custom.pyto the first commit reproduces theSS_Argmaxfailure (RuntimeError: shape '[2]' is invalid for input of size 8), and restoring it passes.Limitations
I did not implement either token banning or XTC into
ComboSampler. My understanding isComboSampleris designed to provide an easy interface for sampling, and so it would be ideal to add these samplers there. However, both of these steps require a tokenizer, whichComboSamplercurrently does not take. If desired we could add a tokenizer parameter toComboSamplerand add xtc parameter, token bans and an eos token ban option.