Skip to content

[mirror] unslothai/llama.cpp#345: MoE cache seeds a long first prompt chunk from the last prompt's routing - #9

Draft
LeoBorcherding wants to merge 2 commits into
night-shift-tester/345-basefrom
night-shift-tester/345
Draft

LeoBorcherding wants to merge 2 commits into
night-shift-tester/345-basefrom
night-shift-tester/345

Conversation

@LeoBorcherding

Copy link
Copy Markdown
Owner

Mirror of unslothai#345 at 153050ec5 on its base (unslothai#268 head fd7489efb), for Codex review. Do not merge.

…t's routing

With experts in host memory and the MoE cache, the last large ubatch of each
llama_decode call seeds the cache. When that ubatch had no earlier routing in
the prompt (the first server chunk, or a whole prompt in one chunk) it read its
own ids first, so its expert uploads ran on the compute stream after a
per-layer readback instead of ahead on the prefetch copy queue.

Keep the routing counts across prompts. A long seeding ubatch with no routing
of its own now copies all experts ahead like any other large ubatch and seeds
from the last prompt's routing. Later chunks of the same prompt still seed from
the prompt's own routing. A small ubatch with outputs (the server's last prompt
tokens) also reads the routing of the large ubatch before it, so the fallback
follows the last prompt. Short chunks keep the routed-only copy: they leave
many experts unrouted and have little compute to hide the copies under.
…cache

ggml_backend_cuda_copy_regions_async returned false on HIP, so the prefetch
copy of a large ubatch could only take long runs of cached experts from the
MoE cache and uploaded the rest from host memory again. With the cache seeded
from the last prompt that was every expert of every layer: 23.5 GB per
4.58k-token prompt on an R9700 at ub 8192, 16 GB of it already in VRAM.

On HIP the device copies now go through the copy-regions kernel and the
uploads are one hipMemcpyAsync each (there is no batched copy API), so a
cached expert is copied from the cache and only the misses are uploaded.
@LeoBorcherding

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T20:35:48.800102Z 153050e Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 153050ec53

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant