Skip to content

SWF(bug): keep top-n-sigma working with masked logits - #75

Merged
maplepaladin73 merged 4 commits into
mainfrom
devin/1795397793-topnsigma-masked
Nov 23, 2026
Merged

maplepaladin73 merged 4 commits into
mainfrom
devin/1795397793-topnsigma-masked

Conversation

@maplepaladin73

@maplepaladin73 maplepaladin73 commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

One masked -inf logit (grammar/tool-call masks, banned tokens) made top-n-sigma's mean and σ NaN, so the sigma > 0.0 guard silently switched the filter off and low logits got sampled again. The filter now computes mean/σ over finite logits only (f64 accumulation, Atlas's existing mean − nσ cutoff kept), and the split verification path keeps matching the full-row result.

Root cause — crates/spark-runtime/src/sampler/sample_impl.rs: sum over the row included -inf, so mean = -inf, var = NaN, sigma = NaN, and NaN > 0.0 is false → no filtering. crates/spark-runtime/src/sampler/absent.rs mirrored that by skipping its survivor check whenever a present token was masked, so it could accept a pick the (fixed) full row would reject.

Fix

  • sample_impl.rs: statistics over finite logits only; no filtering with ≤1 finite logit.
  • absent.rs: always applies the Cantelli survivor bound when top-n-sigma is on, using the known finite candidates (a conservative lower bound on the full row's finite count; the max always survives). When parity can't be proven it returns None, triggering the existing full-row fallback. Dropped the now-unused vocab parameter of sample_with_absent and updated callers.

Test plan

Failing before the fix (regression tests on unfixed code):

test sampler::sample_impl::top_n_sigma_with_masked_logits_full_row ... FAILED
  left: 2
 right: 0
test sampler::absent::tests::top_n_sigma_with_masked_logits_split_row ... FAILED
  left: Some(1)
 right: None
test result: FAILED. 0 passed; 2 failed

Passing after, on current main (includes #69's tiny-temperature fix), ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo test -p spark-runtime:

test sampler::absent::tests::top_n_sigma_with_masked_logits_split_row ... ok
test sampler::sample_impl::top_n_sigma_with_masked_logits_full_row ... ok
test sampler::tests::a_split_rows_candidates_pick_what_the_full_row_picks ... ok
test result: ok. 584 passed; 0 failed

spark-model / spark-server split-verification tests also pass.

Try it: ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo test -p spark-runtime top_n_sigma_with_masked_logits

  • cargo fmt --all -- --check
  • ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo clippy --workspace --tests
  • bash scripts/check-license-headers.sh (4268 valid, 0 invalid)
  • typos
  • Tested against a real model / hardware — not run (CPU only; no GPU or live model)
  • Added regression tests (full-row: masked row, all-masked, single finite; split-row parity)

Notes for reviewers

  • Kept Atlas's mean − nσ cutoff (the paper uses max − nσ); unchanged here.
  • The split path's bound is now conservative, so tight cutoffs may fall back to the full row slightly more often; results never diverge from the full row.
  • sample_impl.rs is 499 lines (cap 500).

CLA


Software Factory opened this PR for Robert
Implemented in session Keep top-n-sigma sampling working with masked tokens
Review with Devin · Open in Devin Desktop


maplepaladin73 and others added 4 commits November 23, 2026 01:44
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@maplepaladin73
maplepaladin73 merged commit 1290e98 into main Nov 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant