feat(qwen3): double-buffered decoding with on-device embedding lookup#46
Open
feat(qwen3): double-buffered decoding with on-device embedding lookup#46
Conversation
…okup Fuse greedy sampling and embedding lookup into a single device kernel so the selected token's embedding stays on device and feeds the next iteration directly, eliminating the per-token host round-trip (D2H token ID → host embedding lookup → H2D embedding). Two next_id buffers alternate so the D2H of the previous token overlaps with the current iteration's non-blocking kernel execution. Adds --no-double-buffering flag to compare performance against the baseline decode path.
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
greedy_sampling_with_embedding) so the token embedding stays on device, eliminating the per-token host round-trip (D2H token ID → host embedding lookup → H2D embedding)next_idoutput: two alternating DeviceTensors so the D2H of the previous token overlaps with the current iteration's non-blocking kernel execution--no-double-bufferingCLI flag to fall back to the original baseline decode path for A/B performance comparisonTest plan
torchrun ... qwen3.py "prompt"— verify correct output and tokens/sectorchrun ... qwen3.py --no-double-buffering "prompt"— verify identical output