Repository navigation
Conversation
Distinguish CUDA graph cache entries that share the first tensor pointer but have different first-node extents.
Due to keying by shape, it is possible to have lots of cached keys. To reduce memory foot print, keep at most eight graph entries per CUDA backend context. DFlash stress peak GPU went from 20,343 -> 19,773 MiB (-570 MiB) and host RSS was about 2,912 -> 2,198 MiB. Caching retained most of the performance benefits due to the new keying.
|
I think this problem needs to be solved the llama.cpp level where materially different graphs (i.e. differing n_tokens) should come via different memory arenas. Currently there are rebuilds at
This PR seems to address 3 but IMO we can tackle at least 2. Spec-dec workloads have become common and the rebuilds on the scheduler side probably are costing some cpu time. I think the least we can do here it to create separate arenas like done for MTP in #28549. For small batches (n_tokesn <=8) we can separate Lines 414 to 415 in 3982664 Note this would miss the |
|
Thank you so much, Aman, for the feedback! This is very useful, I agree that addressing at higher levels first would likely be a better approach. I will investigate the issue along the same lines in the coming days and let you know what I find. FWIW, I tried to keep this PR small so complexity wise it is a small change, but we can explore solving it at higher level first as you suggest. |
Implement graph shape keying to support multiple CUDA graphs with different first node shapes.
Rewrote original PR (PR #28666) by @Lisiyuan233 to be simpler and added bounded
caching with frequency-based eviction. With this, I retain most of the benefits
I mentioned in my comment on #28666 (comment)
Model: Qwen3.8-27B Q4_K_M target; DFlash2 rows also used the Qwen3.8-27B-DFlash2 Q4_K_M draft.
llama-server test: eight fresh-server baseline/candidate pairs per device and
mode, alternating arm order. Each server received three sequential /completion
requests with distinct fixed 512-token prompts and n_predict=256; the first
conditioned the server. Decode tok/s was the average of 256000 / predicted_ms
for responses 2 and 3. DFlash2-7 used a maximum of seven draft tokens.
I also ran llama-batched-bench and do not see any change in performance with this PR.
Tested also Aman's PR #30804 and I see improvements with this PR both
with/without that PR, so this PR is additive in improvement on top of the
chunked graph PR.
CC @ORippler @gaugarg-nv @am17an