Skip to content

glm: draw every target row with the shared keyed sampler - #892

Merged
ashhart merged 3 commits into
ashhart:mainfrom
heitke:glm-sampling-target-rows
Oct 16, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
heitke:glm-sampling-target-rows

Conversation

@heitke

@heitke heitke commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

What this changes

Adds seeded GLM sampled decoding on one Mac using the shared tf_sample_full sampler and lanes.gpu_rule.rule.
This is the sampling follow-up requested in the #835 maintainer review.
The cache lifetime fix is excluded from this diff; #835 was reset to 027ddea as requested.

  • Draws every target row using its stream's seed and absolute output position: prompt at prompt length, queued/server and pipelined standalone rounds at input position plus one, verification windows at their row positions.
  • Supports temperature, top_k, top_p and min_p. Temperature zero retains greedy decoding. MTP drafts remain greedy; target verification determines acceptance.
  • Reuses the shared sampler and canonical rule arithmetic without lossy temperature/min-p conversions.
  • Bounds mixed-mode dispatch rule copies and preserves local greedy vocabulary widths for peer rows.
  • Keeps positive-temperature two-Mac requests unsupported.

Ports fb3cc20 and 8e8dc68 from #835 and incorporates the queued-row/shared-sampler repairs from #524 (79e1004, 1e28ee6, 0174809). #524 is unchanged; this is a consolidated replacement candidate, not another sampler implementation to merge alongside it.

Qualification receipt

Redacted logs, exact public token arrays, request bodies, native hashes and checksums.

Tested implementation: 95818b3, tree dba292097c3d46ef5df5c3e078882374cd2149b2, based on main c7137bb. The follow-up receipt commit adds documentation/evidence only; it does not change tested runtime code.

Environment: Apple M3 Ultra, 256 GB RAM, macOS 26.6.2 / 25G83; Zig 0.17.0 is the pinned compiler requirement (no independent version capture in the upload). GLM-5.3-Flash MLX 4-bit MTP, 45/45 layers plus MTP, 180.58 GB in buffers; checkpoint revision not captured. Standalone load limit GLM_LOAD_LIMIT_GB=235.

Check Result
macOS host/golden build 164/164 steps; 2000 passed, eight skipped
Frozen goldens 309/319 equal; ten known differences, zero unexpected
Synthetic shared Metal sampler 15/15 passed with Metal API validation enabled
Python served-client checks 9/9 passed
Served sampling All four cases match cold/restored/drafted and mixed-mode concurrent native hashes
Prefix restoration Cold zero; restored 11318 cached tokens in every case
Actual drafting Positive drafted counts in every case: 68, 64, 30, 61
Additional concurrency Code/chat, temperatures 0/1, one/four streams: eight cells, zero failed requests or token mismatches
Standalone plain/drafted Sampled and greedy, two prompts, depths 0/3, two repetitions: all 16 runs agree within each mode/prompt
Standalone cancellation Four recovery checks passed; next fresh reply equals baseline

The JSON results were independently rechecked against their native token hashes, restoration counts and drafting telemetry. Sampled standalone hashes differ from greedy, so sampled requests are not silently using argmax.

Additional Linux checks: 46/46 host steps succeeded; 19 draw/packing tests passed, nine client tests passed, 317 server/engine-seam tests passed, Apple Silicon production semantic compilation passed, formatting/diff checks passed. Lean: 525 inherited findings versus pinned main's 527; zero new by finding identity. The dispatch bounds and bit-preservation regressions reproduce the old failures when the inherited expressions are restored.

Scope and limits

This PR adds a feature. No performance improvement or performance-regression claim is made; speed comparisons are not supplied. Raw qualification tools retain incidental timing fields.

Not run: served streaming disconnect/recovery, MTP-omitted model execution, and two-Mac hardware behavior. Standalone cancellation passed. These configurations are not claimed as qualified. Sampled peer execution remains unsupported. The archive does not independently capture checkpoint revision, compiler version or peak physical/device memory.

Checklist

  • Target draws remain on the existing lane/pipeline paths and use absolute positions.
  • Drafted/plain, resumed/fresh and concurrent/solo token hashes match on the tested Mac cases.
  • Shared sampler/rule arithmetic; no new projection/reduction arithmetic.
  • Platforms, evidence and unrun configurations are disclosed.
  • Adapter regressions fail with the inherited defects and pass with the corrections.
  • Source line caps and comment rules checked; no new lean findings.
  • Publication tree/history inspected; private paths redacted from the attached receipt, public noreply commit identity, no tool-attribution trailers.

Merge Danger

Two-way door: reverting removes GLM sampled decoding; no migration. Affects GLM Metal target-head dispatch and standalone/server sampling. The maintainer's review, required CI and release decisions still apply.

Port the sampling follow-up from ashhart#835 (fb3cc20 and 8e8dc68), incorporating the queued-row and shared-sampler repairs from ashhart#524 (79e1004, 1e28ee6 and 0174809). Keep the cache lifetime repair separate.

Arm queued and pipelined standalone target rows at their absolute output positions. Pack canonical gpu_rule values without lossy conversions, bound dispatch-run copies, and preserve local greedy vocabulary widths on peers. Include host regressions and a Mac qualification recipe.
Record the 95818b3 implementation's one-Mac feature-correctness gates, exact public requests and token hashes. Remove user-specific filesystem paths and archive metadata. Retain unrun coverage limits without making a performance claim. Runtime code is unchanged.
@ashhart

ashhart commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thank you, @heitke, for splitting the sampling change out of #835 and supplying the four restored prompt cases.

We checked 77894a7 and found no new code issue. draw_rule.zig:96 puts the first reply's rule in row zero, and plain_rounds.zig:28 arms each draw at its absolute position. Queued rounds and mixed windows also use each request's rule through the shared sampler. The published native hashes agree across plain, restored, drafted and concurrent replies in all four cases, with positive drafting counts.

This is ready and goes into the landing batch after 1.0.12.

Posted by Ash's AI Assistant Synthena

@ashhart
ashhart merged commit 39b8334 into ashhart:main Oct 16, 2026
4 checks passed
ashhart added a commit that referenced this pull request Oct 16, 2026
#709 and #892 each added their steps to build.zig, which was already past 600 lines. The same steps now come
from zig/build/merge.zig (test-merge and tf-merge-check, host only on every OS) and glm_checks.zig's sampler
(tf-glm-sample-check and test-glm-sampling); build.zig keeps one call for each. No step, module or option changes.
ashhart added a commit that referenced this pull request Oct 16, 2026
ashhart added a commit that referenced this pull request Oct 16, 2026
…VIEW names the refused GLM pair requests rightly

One line each for #881, #882, #883, #889, #890, #709, #848, #892, #867, #868, #871 and #873, crediting their
authors. ZIG-PREVIEW said a two-Mac GLM pair refuses "temperature-1" requests; it refuses any temperature above 0
(backend.zig and engine.zig both test temperature > 0).
@ashhart

ashhart commented Oct 16, 2026

Copy link
Copy Markdown
Owner

Thank you, @heitke, for splitting the keyed sampling change out of #835.

#892 is included in 1.0.12 as merge 39b8334, at 77894a7. GLM's first reply token, plain rounds and queued rounds now use the request's shared sampling rule.

We preserved image input during the merge. 2931b7b moves the build steps into zig/build/glm_checks.zig, and f4da332 corrects the rule-row comment.

On M3 Ultra, an eight-layer GLM fixture passes drafted/plain equality in 17 of 17 cells, seed checks in 10 of 10 and sampled cached/fresh conversations in 12 of 12. Concurrent sampled replies match solo and plain runs. The nine greedy/thinking cells also match the previous build. Synthetic sampler checks pass on M3 Ultra and M5 Ultra.

The two-Mac path still refuses sampled requests; its device check remains owed.

Posted by Ash's AI Assistant Synthena

BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
ashhart#709 and ashhart#892 each added their steps to build.zig, which was already past 600 lines. The same steps now come
from zig/build/merge.zig (test-merge and tf-merge-check, host only on every OS) and glm_checks.zig's sampler
(tf-glm-sample-check and test-glm-sampling); build.zig keeps one call for each. No step, module or option changes.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
… (rule row 0, keyed at the prompt's length)
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…VIEW names the refused GLM pair requests rightly

One line each for ashhart#881, ashhart#882, ashhart#883, ashhart#889, ashhart#890, ashhart#709, ashhart#848, ashhart#892, ashhart#867, ashhart#868, ashhart#871 and ashhart#873, crediting their
authors. ZIG-PREVIEW said a two-Mac GLM pair refuses "temperature-1" requests; it refuses any temperature above 0
(backend.zig and engine.zig both test temperature > 0).
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.

2 participants