Add Qwen2-MoE batch prefill and single-token decode - #147
Merged
mikepapadim merged 4 commits intoAug 15, 2026
Conversation
mikepapadim
approved these changes
Aug 15, 2026
Member
|
thanks @MRPRESIDENT66 |
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
This PR adds batch prefill with B1 decode for Qwen2-MoE Q8_0 models.
The prompt is processed in batches, while autoregressive generation continues one token at a time. Both phases reuse the same GPU model weights and KV cache.
Main changes:
Validation
The Single-token and B16 paths generated identical output with the same prompt, temperature, and seed.
Each run processed 64 tokens:
Performance
Tested on an RTX 5070 Ti with JDK 21, TornadoVM 5.2.1-dev, the CUDA backend, and CUDA Graphs.
./llama-tornado --gpu \ --model Qwen1.5-MoE-A2.7B-Chat.Q8_0.gguf \ --prompt "Explain briefly how mixture of experts routing works." \ --max-tokens 64 \ --temperature 0 \ --seed 42 \ --with-prefill-decode \ --batch-prefill-size 16 \ --cuda-graphsThe Single-token baseline used the same parameters without:
One warm-up run was excluded, followed by five interleaved measured runs.
This is a 9.33% improvement.
throughput was calculated as:
Profiling
The B16 prefill and B1 decode path was profiled on an RTX 5070 Ti using JFR and Nsight Systems.
JFR showed no major Java-side bottleneck. GC pauses accounted for approximately 0.25% of the 21-second recording.
For one full B16 prefill chunk across 24 layers:
Within the routed-expert computation, Gate/Up took 10.949 ms, Down took 8.352 ms, and accumulation took 0.036 ms. Routed and shared experts together accounted for 73.98% of GPU kernel time.
Task gaps inside each layer were approximately 0.18–0.19 μs. Gaps between layer TaskGraphs totalled approximately 2.23 ms per B16 chunk.