mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #53] Sampler applies penalties twice, breaking single-pass llama.cpp sampling parity #29
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#29
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?
Originally created by @hendrikp on GitHub (Sep 28, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/53
AI disclosure
I was testing performance of various llamacpp branches/forks and measuring the parameters, and came across strata and wanted to find out how it will perform and if the quality is the same. After i finished benchmarking i wanted to find out what makes the biggest difference or if there is quality degradation (difficult to judge). Anyways one difference my agent identified.
Difference/bug identifie through codex-cli (gpt-6-astra medium).
Version
Strata v0.1.13,
Verification consisted of tracing the checked-out source, its host parity reference, and the llama.cpp sampler chain used in our comparison, plus executing the numerical example below. This report does not claim a new CUDA runtime reproduction or that later revisions remain affected.
Finding and exact source links
The non-greedy sampler applies repetition, frequency and presence penalties before candidate selection, then applies the same penalties again after temperature scaling:
The file header explicitly describes this two-pass order. The issue is therefore a sampling-semantics/parity error rather than a discrepancy between the implementation and its own comments.
For comparison, the llama.cpp fork used in our benchmark has one PENALTIES entry before TEMPERATURE in its default sampler list. Chain construction iterates that list; the textual order of switch cases does not determine execution order. The saved benchmark response also confirms exactly one penalties stage before temperature. llama.cpp supports configurable sampler chains; this comparison concerns that single-pass chain.
The corresponding llama.cpp arithmetic is in llama_sampler_penalties_apply(), lines 2950-2977: the sign-dependent repetition adjustment is followed by subtraction of
count * penalty_freq + (count > 0) * penalty_present. Temperature scaling divides the resulting logit by temperature, line 289. Together with the single penalties stage in the linked chain, this gives(logit - presence_penalty) / temperaturewhen repetition and frequency penalties are neutral. The individual penalty formula in Strata is not the problem; applying it twice is.Minimal numerical reproduction
Use two tokens A and B with logits
[0, 0], history[A],penalty_last_n=1,penalty_repeat=1,penalty_freq=0,penalty_present=1.5,temperature=0.7,top_k=2,top_p=1, andmin_p=0. Both candidates survive all filters, isolating penalty application from truncation and RNG differences.Executed output:
Expected for single-pass parity: A receives one presence penalty. Actual source behavior: A receives a second penalty after temperature scaling, reducing its probability from approximately 10.50% to 2.55%.
Why the existing parity test does not catch this
The host reference explicitly duplicates both penalty passes, and the sampled-penalties fixture tests against that reference. Agreement with this reference establishes internal consistency, not parity with the single-pass llama.cpp chain.
Scope and suggested correction
This affects non-greedy sampling with history tokens and non-neutral penalties. The greedy path applies penalties once. Neutral penalties make the extra pass inert.
For the single-pass chain described above, retain the first penalty application and make the final scaling stage temperature-only. Update the host reference and add an independently derived distribution fixture such as the example above. Other filter-order differences are outside this report.
The mismatch changes output distributions and prevents interpreting identical penalty settings across engines as equivalent. It does not by itself establish a general quality regression, explain the measured throughput gap, or imply that speculative target verification is skipped.
@hendrikp commented on GitHub (Sep 28, 2026):
Otherwise great work on the performance on my RTX5080 16b in pciegen3, with the Q2 model i get the following decode t/s:
and thats with a llamacpp fork that has hotexperts, and adaptive kv merged in the original llamacpp was 12 t/s...
@j-luwierski commented on GitHub (Sep 28, 2026):
Thanks for helping track down this bug! A fix is on the way.
@Niko1221 commented on GitHub (Sep 28, 2026):
Thank you @hendrikp - you were right, and it was worse than one stage: our notes had transcribed llama.cpp's order from the
caselabels incommon/sampling.cpprather than fromparams.samplers, which gave both the second penalties pass after the temperature and min_p before top_p. Fixed in v0.1.17: penalties once, then top_k, top_p, min_p, temperature - llama.cpp's default chain restricted to the samplers Strata has. The parity test's host reference had copied the same order, so it now also checks against an independently computed distribution: your example over 8,000 draws gives token A 0.1040 (expected 0.1050; it was 0.0255), and a second fixture makes top_p-before-min_p observable. Both fail on the old kernel. Greedy decoding was not affected. And thanks for the 5080 numbers! (@j-luwierski - this landed before your fix; if yours covers something else, a PR is still welcome.)@j-luwierski commented on GitHub (Sep 28, 2026):
While re-checking the sampler I did find one small thing though: with penalties off but a stale
history buffer still passed in, both kernels touch the shared bitmap the launch never sized
(shmem is only allocated when penalty_last_n > 0). Not reachable from the server, but easy to
guard - just hlen > 0 in use_bits. I'll rebase and send that as a small standalone PR.
@Niko1221 commented on GitHub (Sep 28, 2026):
A follow-up to this one, fixed in v0.1.19: the penalties were applied once after #53, but only to the first token of each speculative batch.
presence_penalty/repeat_penalty, andpenalty_last_nnear 4096 could crash the engine.Requests with penalties are 1-11% slower now, because more draft guesses are rejected; requests without penalties are unchanged. Thanks again for the careful report.
@hendrikp commented on GitHub (Sep 28, 2026):
@Niko1221 i still continued on 0.1.13 a small swebench sample today to verify a bit more the quality and it was fine with the code/thinking settings. I think this shows that
strataoutput is good. Feel free to share, Sadly i cant run more extensive verifcations on my local hw.Setup
--spec 4 --spec-min-p 0.5, meaning up to three MTP proposals plus the current token per window. Suffix drafting can use a different verification window.random.Random(42), then take the first 30. The table below preserves that order.Thinking and sampling settings
The sampling values follow the Qwen thinking recommendations; seed and output limits are evaluation choices. Neutral penalties make the previously identified double-penalty sampler discrepancy inactive in this run, so these results do not validate a fix for that discrepancy.
Configuration change during the pilot
django__django-15930, which ended withLimitsExceededat 100 model calls. This does not establish the underlying cause of failure.Per-task results
One agent turn is one recorded model response, not one individual shell command. All context lengths are tokens. Final input is the full prompt on the last turn, including reused tokens; final total adds that turn's generated tokens. Peak total is the largest input-plus-output context of any recorded turn. Output tokens are cumulative across the task.
Average decode is total generated tokens divided by summed engine decode seconds. Average prefill is newly processed prompt tokens divided by summed engine prompt-processing seconds; reused cached tokens are excluded from its numerator. These are time-weighted averages, not the mean of per-turn rates. Small cached prompt extensions can show lower prefill t/s while completing much faster. All 1,244 recorded response timings matched the engine log in order using prompt and completion token counts; the initial API smoke request was excluded.
django__django-14672sphinx-doc__sphinx-10449django__django-11299django__django-14493django__django-11551django__django-12143pydata__xarray-6938django__django-15916django__django-12193pytest-dev__pytest-5262sphinx-doc__sphinx-8459sphinx-doc__sphinx-9281django__django-13012django__django-16082sympy__sympy-20916django__django-11749scikit-learn__scikit-learn-14629django__django-14631django__django-15930django__django-7530sympy__sympy-14248pylint-dev__pylint-4551pallets__flask-5014sphinx-doc__sphinx-7440astropy__astropy-14096sympy__sympy-17655django__django-17084django__django-16485django__django-16901django__django-15957--prefill autopicks 8192 by VRAM alone; lent slots + file tier exceed the page cache, so a 28.7K prompt re-reads 28-45 GB (TTFT 164-287 s);--prefill 4096fits: 0.9-1.4 GB read, TT… #1136