Repository navigation
SWF(bug): stabilize sampling at tiny positive temperatures - #69
Merged
Merged
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
6 of 7 tasks
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
Sampling with a tiny positive temperature no longer overflows and picks the lowest logit: logits
[2, 1]att = 1e-40now pick token 0, not token 1.Root cause:
sample_core(sampler/sample_impl.rs) divided raw logits by temperature before subtracting the max.[2, 1] / 1e-40becomes[inf, inf], so the softmax computesinf - inf = NaNand the cumulative draw falls through to the last candidate. The fix ranks and filters unscaled logits (dividing by a positive temperature does not change their order) and scales only the centered difference(logit - max) / t. The largest logit always gets weight 1, and the others underflow to 0 instead of becoming NaN.sample_impl.rs: Top-k, top-p and min-p now rank the unscaled logits. The newsoftmax_weighthelper applies the temperature after centering. Top-p skips zero-weight candidates.absent.rs: Split-row bounds are compared in raw logit space, so they are not scaled to inf either. When temperature is subnormal or the scaled max is non-finite, top-p uses the existing full-row fallback, because the split summary's log mass cannot be trusted there.Test plan
Regression tests in
sampler/tests.rs:tiny_positive_temperature(token 0, finite weights[1, 0], top-k/min-p/top-p) andtiny_positive_temperature_with_absent_tokens(split-row path).Before the fix (on
main):After the fix:
Full
spark-runtimeCPU suite: 581 passed, 0 failed, 11 ignored (unit); 1 passed (integration).Try it:
ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo test -p spark-runtime tiny_positive_temperaturecargo fmt --all -- --checkcargo clippy -p spark-runtime --tests(crate-scoped,ATLAS_SKIP_BUILD=1)bash scripts/check-license-headers.sh: 4267 valid, 0 invalidtyposNotes for reviewers
Untested: No GPU or live-model run. GPU testing on robert2 is reserved for HY4, so only the CPU sampler was run. Normal temperatures follow the same math as before, now in a centered form, and the existing sampler tests still pass.
CLA
Implemented in session Stabilize sampling at tiny positive temperatures
Review with Devin · Open in Devin Desktop