Repository navigation
metal: presence and frequency penalties on Flash Next and Qwen3.8-27B, each row over the reply and its own path - #3145
Merged
Merged
Conversation
|
Klk |
ashhart
added a commit
that referenced
this pull request
Nov 17, 2026
ashhart
force-pushed
the
lead/metal-penalties
branch
from
November 17, 2026 21:43
8122891 to
920e7ce
Compare
ashhart
added a commit
that referenced
this pull request
Nov 17, 2026
ashhart
force-pushed
the
lead/metal-penalties
branch
from
November 17, 2026 23:28
920e7ce to
c340a5f
Compare
ashhart
added a commit
that referenced
this pull request
Nov 21, 2026
ashhart
force-pushed
the
lead/metal-penalties
branch
from
November 21, 2026 20:40
c340a5f to
8862cfe
Compare
ashhart
added a commit
that referenced
this pull request
Nov 21, 2026
ashhart
added a commit
that referenced
this pull request
Nov 21, 2026
…n today's main (three blank lines fewer) Main's metal_main.zig is at 600 lines; #3145's penalties suite adds three, which lean_check counts. Three blank lines between adjacent declarations go; no code changes.
ashhart
force-pushed
the
lead/metal-penalties
branch
from
November 21, 2026 23:53
8862cfe to
7f1ef97
Compare
ashhart
added a commit
that referenced
this pull request
Nov 22, 2026
ashhart
added a commit
that referenced
this pull request
Nov 22, 2026
…n today's main (three blank lines fewer) Main's metal_main.zig is at 600 lines; #3145's penalties suite adds three, which lean_check counts. Three blank lines between adjacent declarations go; no code changes.
ashhart
force-pushed
the
lead/metal-penalties
branch
from
November 22, 2026 03:47
7f1ef97 to
17e3a03
Compare
…, each row over the reply and its own path core/lanes/penalty_rows.zig stages a forward's (row, token, amount) entries as CUDA's cuda_penalties does: the reply's tokens before the cache, the pending (or fed) token, then each row's own drafts from the window's first row, following parents for a tree; a distinct token held c times loses presence + frequency * c, once per row. A verify row's entries are the one-token round's at the same position, so drafted replies equal "draft": false. Flash Next lowers its shared rounds' logits on the GPU (fz_penalize_rows, fp32 subtract rounded once to bf16, as tf_penalize_rows) after the grammar masks and before the argmax and the sampled draws; the entries are staged before the round's command buffer opens. Qwen3.8-27B draws a penalized row on the host from a lowered copy of its frame row, greedy too, and leaves the round-wide argmax and the fused keep tail to unpenalized windows. The first token has no reply to count. A lone driver no longer takes a penalized stream, so it stays in the lane core. With both penalties 0 nothing is staged and every round encodes and draws as before. --instruct-sampling card on these two now serves the card's presence_penalty 1.5 instead of leaving it out. Other Metal families still refuse nonzero penalties.
…n today's main (three blank lines fewer) Main's metal_main.zig is at 600 lines; #3145's penalties suite adds three, which lean_check counts. Three blank lines between adjacent declarations go; no code changes.
ashhart
force-pushed
the
lead/metal-penalties
branch
from
November 22, 2026 05:38
17e3a03 to
0071ee3
Compare
ashhart
added a commit
that referenced
this pull request
Nov 22, 2026
ashhart
added a commit
that referenced
this pull request
Nov 22, 2026
…n today's main (three blank lines fewer) Main's metal_main.zig is at 600 lines; #3145's penalties suite adds three, which lean_check counts. Three blank lines between adjacent declarations go; no code changes.
ashhart
added a commit
that referenced
this pull request
Nov 22, 2026
ashhart
added a commit
that referenced
this pull request
Nov 22, 2026
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.
Closes #3113.
Metal now takes
presence_penaltyandfrequency_penaltyon Qwen3.8-Flash-Next and Qwen3.8-27B; before, they were refused. Each row's counts cover the reply so far plus that row's own draft path, so a drafted reply equals an undrafted one. Counting matches CUDA'scuda_penalties. Flash Next applies them in a GPU pass before argmax and draws (fz_penalize_rows: fp32 subtract, then round to bfloat). Qwen3.8-27B applies them in its queue and verify draws on the host, and skips the GPU argmax and fused tail for penalized windows only. With both penalties at 0 nothing is staged, so the default path is unchanged. Penalized Flash Next streams no longer use the lone driver.Flash Next stages its penalty entries before the command buffer opens, so an error can't leave an encoder open.
Tests: the lone-driver test fails on main (expected 0, found 1); lanes 363 to 369, with new
penalty_rowstests; a recording-device test runs the realround/fill/encodeand applies the recorded dispatch, and fails when a buffer offset is broken on purpose; a verify row stages exactly what the one-token round at its position stages, for a chain and a tree; new steptest-flashnext-penalties-host, in the Linux host list.check-native-cuda-hostandcompile-cuda-testspass for both Linux targets. The kernel compiles offline for Metal 3.1, 3.2 and 4.0.With
--instruct-sampling card, both Metal models now serve their card's presence_penalty 1.5, as CUDA already does.Device check pending (M5): with penalties at 0, token hashes equal main's, greedy and seeded, drafted and not, 1 and 4 streams; with presence 1.5 and frequency 0.5, drafted equals undrafted and 4 streams equal solo; an unpenalized stream beside a penalized one keeps its solo hashes; decode tok/s with penalties at 0 level with main.