Add TopNSigmaLogitsWarper and top_n_sigma generation config support#45172
Add TopNSigmaLogitsWarper and top_n_sigma generation config support#45172ezylopx5 wants to merge 2 commits intohuggingface:mainfrom
Conversation
Signed-off-by: HarshRathva <harshrathvaai@gmail.com>
Signed-off-by: HarshRathva <harshrathvaai@gmail.com>
|
Please don't ask your code agent to find old issues and "fix" them! |
|
@Rocketknight1 thanks for the feedback, and sorry for the noise.You are right that I handled the process poorly. I moved too fast without prior discussion on the issue, and that made this look agent-first. |
Problem
Transformers currently provides sampling filters such as top-k, top-p, min-p, and top-h, but does not include top-n-sigma sampling from "Top-nσ: Not All Logits Are You Need".
This makes it harder to use a temperature-invariant truncation rule based directly on pre-softmax logits.
Closes #39850.
Root Cause
There is no logits warper implementing a dynamic threshold of:
max(logits) - n_sigma * std(logits)and no corresponding
GenerationConfigparameter routed throughGenerationMixin._get_logits_processor().Fix
This PR adds
TopNSigmaLogitsWarperand integrates it into generation config and sampling flow.Code changes
TopNSigmaLogitsWarperto generation logits processors.top_n_sigmafield and validation inGenerationConfig.top_n_sigmasampling integration inGenerationMixin.TopNSigmaLogitsWarperfrom generation and top-level package init files.Files changed
src/transformers/generation/logits_process.pysrc/transformers/generation/configuration_utils.pysrc/transformers/generation/utils.pysrc/transformers/generation/__init__.pysrc/transformers/__init__.pytests/generation/test_logits_process.pytests/generation/test_configuration_utils.pyValidation
Ran locally in editable install environment:
Results:
test_logits_process.py: 50 passedtest_configuration_utils.py: 34 passed, 5 skippedAlso ran style checks:
Risks
top_n_sigmadefaults toNone).top_n_sigmais explicitly set.Out of Scope