mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2433
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/59
Author: @j-luwierski
Created: 9/28/2026
Status: ❌ Closed
Base:
main← Head:fix/53-sampler-penalties📝 Commits (2)
aa9a176sampler: penalties apply once, as in llama.cpp's default chain (#53, engine 0.1.17)cfdf42esampler: an empty penalty window must not touch the unsized shared bitmap📊 Changes
6 files changed (+120 additions, -30 deletions)
View changed files
📝
CMakeLists.txt(+1 -1)📝
docs/DETAILS.md(+3 -1)📝
include/strata/kernels/sampler.hpp(+4 -4)📝
setup.py(+1 -1)📝
src/kernels/cuda/sampler.cu(+29 -15)📝
src/kernels/sampler_parity.cpp(+82 -8)📄 Description
Fixes #53.
What happened
The block-per-token sampler rewrite (
4d39f7a) added penalties to thetop_kselection and kept theold application in the final stage, so the sampled chain penalised a token twice: once on the raw
logits during the selection, then again after the temperature scaling. No llama.cpp chain does that —
the default chain lists
PENALTIESexactly once, first, before the filters (the chain is built byiterating
params.samplers; reading the switch cases ofcommon_sampler_initin their textual orderis what put the second pass after
TEMPERATURE). In #53's two-token example the double pass shrankthe penalised token's probability from 10.50% to 2.55%.
Commit 1 — the fix
1/Tand nothing else:scaled()returnssel_logit[i] * inv_tinstead of with llama.cpp), and fixture 9 pins the chain against the issue's independently derived
numbers —
0.10500059for one pass vs the old0.02550967— plus a draw counter whose uniformlands in the band where only the single-pass chain picks the penalised token
by PR #54's engine)
Commit 2 — a latent contract bug found while re-auditing the sampler
use_bitsrequired only a non-null history, but the launch sizes the shared bitmap forpenalty_last_n > 0alone — a caller handing over a stale history buffer with the penaltiesdisabled made the kernel zero words of a zero-byte dynamic shared allocation. Unreachable from
the serve path (
set_historypassesnullptrwhen the window is empty) and invisible to memcheck,but undefined per the contract of the public
sample_tokens. The gate now also requires anon-empty window (
hlen > 0, both kernels); fixture 10 pins a stale history withlast_n = 0tothe no-history result.
Verification (RTX 4070 Ti SUPER, CUDA 13.4, real IQ3_XXS model)
sampler_parity --selftest: 0 failures (fixtures 1–10, incl. #53's own numbers); each commitbuilt and tested individually
logits,
top_k > n_vocab, penalty windows longer/shorter than the buffer,-1padding,seeds/counters above 2^32, batch rows)
softmax(logits/T)atT ∈ {0.5, 0.7, 1.0, 2.0} within 5σ;
T = 0is exactly the argmax; with penalties the empiricaldistribution matches the single-pass softmax while the old two-pass one sits far outside tolerance
compute-sanitizer: memcheck 0 errors, racecheck 0 hazardsple_parityneeds generated PLE fixtures absent on this machine)T=0deterministic; seededT=0.6reproduces exactly;T=1.4differs;T=0.05shares a 220/220-char prefix with greedy; penalties change picks and cutrepeats (12→5);
min_pworks through the GEN linepenalised sampling diverges exactly where it should
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.