Skip to content

moe-cache: pick a GPU device explicitly instead of the first non-meta device - #11

Open
ALeXssNdR wants to merge 1 commit into
thecodacus:perffrom
ALeXssNdR:fix/moe-cache-gpu-device-select
Open

moe-cache: pick a GPU device explicitly instead of the first non-meta device#11
ALeXssNdR wants to merge 1 commit into
thecodacus:perffrom
ALeXssNdR:fix/moe-cache-gpu-device-select

Conversation

@ALeXssNdR

Copy link
Copy Markdown

Problem

On hosts where the model device list starts with the CPU device, the expert cache silently disabled itself with no GPU device - expert cache disabled, because init_moe_expert_cache() picked the first non-meta device regardless of its type.

While investigating I also hit two cases where the model device list contains no GPU entry at all (early loading stages / mmap path), so a registry fallback is included.

Fix

  • select the first GPU-typed device from the model list
  • fall back to enumerating every backend registry (including dynamically loaded ones such as libggml-cuda) and then the default device registry

Measured

RTX 5080 Laptop 16 GB, Ornith-1.5-35B-A3B (qwen35moe, 41 blocks) Q4_K_M, built with CUDA arch 120:

-ngl 99 -ncmoe 99 -fa 1 -c 4096
--moe-cache-profile ornith35-merged.csv --moe-cache-slots 176   (9.78 GiB pack)
config decode
baseline (no cache) 56.8 tok/s
cache, 176 slots 80.0–86.4 tok/s
cache, 176 slots (short bench) 92.0 tok/s

That is +41–62% on the same hardware, bit-identical outputs, with a single slot count that fits VRAM (40 layers × 176 slots ≈ 9.8 GiB).

The routing profile was captured with llama-moe-trace (512-token code + chat prompts, merged) exactly as documented in the README.

Thanks for the great work on this fork — the video walkthrough of the LRU-vs-static tradeoff is excellent.

… device

The expert-cache init selected the first non-meta entry of the model device
list. On hosts where the list starts with the CPU device the cache silently
disabled itself with 'no GPU device'. Select the first GPU-typed device
instead, and fall back to enumerating every backend registry (including
dynamically loaded ones such as libggml-cuda) when the model list has none.

Measured on RTX 5080 Laptop 16GB, Ornith-1.5-35B-A3B (qwen35moe) Q4_K_M,
-ngl 99 -ncmoe 99 -fa 1, 176 slots (9.8 GiB pack):
baseline 56.8 t/s -> 80-92 t/s (+41-62%), single slot count that fits VRAM.
@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 427e4924-79a7-49b8-a035-7006a14ba967

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

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