Repository navigation
MoE Expert cache improvement for looped transformer architecture in inkling mini 2 - #410
Conversation
…nkling mini 2 Assisted-by: Codex
|
Thanks for this, and good catch. Keying the cache by the shared weights is the right fix (ggml-org#32744 is the same report). I compared it with a version we had been building, on a B200 with Inkling-2-Mini. Both remove the duplication: at the 8 GB budget with UD-Q4_K_XL, host experts drop from 28188 MiB to 15066 MiB, and filled slots equal distinct experts. Both are exact against the base: KLD 0 and top-1 100% at Your budget split by physical bytes is clearly better on IQ1_S: at 5500 MiB the hit rate goes from 97.65% to 99.62% and uploads from 97.3 GB to 17.6 GB compared with our visit-weighted split. We are adopting it, with credit to this PR. Things I would change if this were to land as is:
We will ship this as one pin with your split folded in, so I will link it here when it is up. |
The layers of a looped model (Inkling 2, 48 visits of 24 layers) that read the same expert weights got one cache entry, one slot map and one upload per visit: Inkling-2-Mini UD-Q4_K_XL reported 28188 MiB of host experts for 15066 MiB of experts. A layer whose experts are the same tensors as an earlier layer of its group (or whole views of them) now shares that layer's slots and LRU keys. The owner's visit advances the LRU clock once per ubatch. Each layer keeps its own slot map tensor and CPU map. The host bytes, the budget split among the groups and the slot cap count each expert weight once. The physical-bytes budget split follows AhmadSaeedZaidi's unslothai#410. Models without shared expert weights are unchanged. LLAMA_MOE_CACHE_DEDUPE=0 restores one entry per layer. test-llama-archs runs inkling2_loop with the experts in host memory and with the MoE cache, so a looped model with shared expert weights is checked against the CPU through the cache.
Overview
The cache, uses the visit ID as part of the key, so identical weights can be considered different, and occupy multiple cache slots.
Use the model's
layer_weights()mapping for cache residency and memory accounting.Additional information
Stacked on Unsloth #396
Benchmark results
Inkling-2-Mini UD-Q4_K_XL · RTX 3060 12 GiB · Ubuntu 24.04 WSL2 · Unsloth
b12631-mix-acc0843with the7c7edbaoverlay5,000 MiB expert cache · CPU miss share 0 · 32K context · Q8_0 K/V · microbatch 128
Nsight Systems, matched 40-token decode · host-to-GPU traffic 541.9 → 247.3 MiB/token (54.4% lower).
Validation
maintests and CUDAMUL_MAT_IDsweep passedb62e1bcBenchmark CSVs and validation report · Exact launch flags
Requirements