Repository navigation
GPU token selection and pipelined decode (1.1.1) - #5
Merged
Merged
Conversation
The next token is chosen on the GPU at the end of each decode command buffer (repetition penalty, exact top-k, min-p, top-p, seeded xorshift draw) and written to a per-position token-history buffer that the next step's embedding lookup reads. The engine commits step N+1 before reading back step N, so the GPU never waits for CPU sampling, detokenization or launch latency. RMSNorm kernels use float4 loads with up to 1024 threads per row (norms on Mistral 7B: 0.62 -> 0.21 ms per step). M2 Pro, 4 alternating pairs against 1.1.0: decode @16 Qwen3 0.6B +10.7%, Llama 3.2 1B +8.5%, Mistral 7B +4.1%; @1k +9.0%, +7.8%, +4.0%; prefill flat. Real generation: 238 -> 282, 180 -> 201, 39.3 -> 40.9 tok/s. Greedy output is token-identical on five architectures. Speculative decoding and constrained tool-call names keep the CPU sampler. `mlxr bench` measures the pipelined decode and the sampler cost; `profile` adds a per-kernel-class breakdown of a decode step. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
🚀 Deploying Preview to Cloudflare 🚀Preview Deployments by commit
|
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.
Summary
mlxr benchmeasures the pipelined decode, the app's default sampler and the token-selection cost;profileprints a per-kernel-class breakdown of one decode step.Numbers (M2 Pro, 4 alternating pairs against 1.1.0)
mlxr run)Prefill is unchanged. Greedy output is token-identical to main on Qwen3 0.6B, Qwen2.5 0.5B, Llama 3.2 1B, Phi-3.5 and Mistral 7B.
Measured and rejected: a 2-rows-per-simdgroup matvec for small matrices (faster in isolated sweeps, 5% slower in the real decode step) and a ballot-based counting pass in the sampler.
Test plan
swift test(116 tests) passes; newSampleKernelTestscompare the GPU sampler with the CPUSampler(greedy with ties and penalty, drawn distributions for four top-k / top-p / min-p settings, tied maxima, tiny vocabularies, huge top-k, non-finite logits).mlxr run --temp 0, 300 tokens, long prompt).prefillMatchesIncrementalDecodeand the server suites pass on the real models.🤖 Generated with Claude Code