On-device greedy sampling (-Dllama.deviceSample): GPU argmax, keep logits device-side (~500x less D2H)#134
Open
mikepapadim wants to merge 1 commit into
Conversation
… the logits appends to the FP16 logits graph so only the sampled token id (1 int) crosses to the host instead of the full vocab logits row; decode loop reads state.sampledToken. Guarded to GPU+greedy+FP16+Llama/Mistral/Qwen3, else the host still gets logits
Member
Author
|
@orionpapadakis standalone on-device greedy sampling off feat/mma_cuda — GPU argmax, only the token id leaves the device (nsys: 13.3 MB → 1 KB D2H over 26 tokens). Opt-in |
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.
On-device greedy sampling (
-Dllama.deviceSample=true)Appends a GPU argmax over the logits to the FP16 logits task graph, so on the greedy path only the sampled token id (1 int) crosses to the host each step — the full vocab logits row stays device-side (no D2H copy, no host CPU scan). This is the single-token analog of the batched-decode on-device sampling.
How
TransformerComputeKernels.argmaxLogits— single-workgroup tree-reduce argmax overvocab, writesstate.sampledToken[0].LogitsFP16Layer(gated on-Dllama.deviceSample): adds the argmax task, transfers onlysampledToken, and skips thewrapLogitsD2H.state.sampledTokeninstead of running the host sampler.LlamaApp: enabled only for GPU + greedy (temperature 0) + FP16 + Llama/Mistral/Qwen3. Any other config (temperature > 0, non-FP16, other arch) clears the flag so the host still receives the full logits. Opt-in, default off — zero change to existing runs.Verified — mechanism works (nsys, RTX 4090, Llama-1B, 60 tokens)
~500× less D2H traffic, output bit-identical & coherent ("Paris, the capital of France…").
Honest throughput finding
At n=1 single-token decode this is throughput-neutral (Llama-1B 98.4→98.1 t/s; +graphs 110→110; Qwen3-1.7B 55.4→54.4): the eliminated copy is only one ~0.5 MB vocab row and overlaps the ~11 ms forward, so it isn't the bottleneck — the same n=1 launch/host-bound story as the hybrid-libs PR (#131). Where it pays off is batched decode (65 MB D2H → +30%, already shipped in #129) and serving/concurrency (removes per-step host CPU argmax, freeing the host thread). Shipping it here gives the single-request path the same device-resident-logits mechanism, correctly guarded.
@orionpapadakis — standalone feature off
feat/mma_cuda; review welcome. Can extend to the Q8 / Granite logits layers if you want the mechanism everywhere.