Skip to content

Checking your reading list…

Retry

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

Running Large MoE on 4× RTX 3090: 40% of Optimizations Waste Effort, Repo Logs Failures

The author tests five large MoE models on four RTX 3090s without NVLink, documenting 115 optimization hypotheses across multiple inference engines; 42% fail outright and 16% work only conditionally, revealing that router skew, miss handling (CPU vs PCIe), speculative decoding limits, and prefill bottlenecks depend heavily on model architecture and hardware specifics.

Running Large MoE on Consumer GPUs: No Universal Tuning Recipe

The author runs five large MoE models — DeepSeek V4.1 Flash, Qwen3.8-Flash-Next, GLM-5.3-Flash, MiniMax-M3.1-Flash, and Tencent Hy4 Flash — on four RTX 3090s (96 GB VRAM, no NVLink, PCIe 3.0). Experts reside in system memory; engines tested include Strata, several Maya forks, an exllamav3 branch, llama.cpp, and vLLM, most hand-patched. A single 3090 with Inkling 2 Mini fully in VRAM serves as a control. The core finding: there is no universal tuning checklist, only a conditional map; 40% of attempted optimizations are wasted effort.

Hypothesis Ledger: 115 Experiments, 42 Failures

The repository ledger/hypotheses.md records 115 hypotheses. Final tally: 53 hold, 16 are conditional, 42 fail, 4 untested. “Fail” means “did not pay off on this model/engine/hardware combo”; each entry includes a “when to retry” condition. Figure 1 (re-drawn from raw ledger numbers) shows this distribution.

Conclusion distribution
Conclusion distribution

Figure 1: 115 hypotheses — 53 hold, 16 conditional, 42 fail, 4 untested.

A counter-example in the same repo shows why a static checklist fails: on DeepSeek, disabling the PCIe path for decode (forcing cold experts onto CPU) speeds up 17%; on GLM, routing 75% of misses over PCIe raises throughput from 24.9 to 45–46 tok/s. One knob off, one on, both double performance.

Cost Model: Token Time = Constant + Miss_Count × Miss_Cost

Offload works because each token touches only a few experts. The author verifies the same linear formula across engines:

per_token_time ≈ constant + misses_per_token × cost_per_miss

For GLM-5.3-Flash on Maya (EXL3 4.05 quant, 4-GPU layer split) the fit is remarkably clean:

t ≈ 9.5 ms + 866 MB / memory_bandwidth

2-channel DDR4 (24 GB/s): 45.9 ms/token → 21.8 tok/s

4-channel paired (35.8 GB/s): 33.4 ms/token → 29.9 tok/s

Of 68.5 misses/token, 46.7 are computed on CPU, 21.8 transferred via PCIe. The 9.5 ms constant is also the zero-miss floor (105 tok/s). To exceed 55 tok/s, per-token memory traffic must drop below 520 MB (cut 40% of misses); adding channels alone cannot reach that target. The author notes this fit was taken on 2-channel memory and says nothing about 8-channel systems.

Cost model
Cost model

Figure 2: GLM-5.3-Flash token-time breakdown. Constant 9.5 ms identical; difference lies in 68.5 misses’ transport cost. Dashed line = zero-miss floor.

Practical use: the model tells you when to stop optimizing experts. After fixing all DeepSeek bottlenecks, CPU portion is only 10% of a round; adding 10 GB VRAM for experts yields +1.8%, while switching Q8 matvec to int8 tensor cores gives +5.6% (bitwise identical). The target shifts to kernel optimization.

Router Skew Decides Whether Static Placement Helps

Miss reduction depends on whether the router concentrates on a small expert subset.

DeepSeek (384 experts/layer): online profile shows top-50 cover 51%, top-100 70%, top-200 89%. Effective experts per layer 194 (range 108–268).

Qwen3.8-Flash-Next : 24% of experts on one GPU hit 74–79%; 53% on two GPUs hit 92–95%.

GLM & MiniMax : GLM’s “cold” half still attracts 41% of picks, no dead experts; static placement cuts miss only 10%. MiniMax random placement 61%, profile-based 64–69%.

The gap is under 10 percentage points; the author calls this a heuristic, not a theorem.

Router skew
Router skew

Figure 3: DeepSeek V4.1 Flash cumulative expert selection. Top-100 covers 70%, top-200 89%. Dashed line = uniform. GLM and MiniMax curves hug the dashed line.

When skew is weak, static sets don’t work; runtime active caching is needed. MiniMax simulation lifts 61–69% to 87–96% (online 71–94%); GLM uses intra-request locality to reach 94–98%. Each answer has its own working set; the next answer’s set is unknown beforehand.

Hy4 Flash quantifies this: prompt statistics pick 220 experts covering 48% of generation picks; the answer’s own statistics cover 96%. Prompt cannot predict which experts the answer will wake.

Profile source also matters. DeepSeek online session top-180: ideal sort 94%, recent workload accumulation 86%, official engine profile 68%. Static placement yields 36 vs 42 tok/s. A short profile self-covers 80.5% but only 68% on real sessions; the service profile self-covers 57.6% but 86% on real sessions. Narrow samples inflate self-coverage.

Who Computes a Miss: CPU vs PCIe vs NVMe

This is the primary offload design choice and the biggest source of misleading checklist items.

DeepSeek (11 MB/expert): CPU in-memory AVX2 0.42–0.46 ms. On Zen 2, -march=native selects PDEP (microcoded), slowing to 1.6 ms. A compile flag to avoid PDEP restores 3.6× speedup (patched upstream in Maya and Strata).

GLM on Maya: idle CPU expert 0.14–0.18 ms, under load 0.8 ms. Planner predicted 114 ms/token, actual 42–49 ms. Moving 75% of misses to PCIe raised throughput from 24.9 to 45–46 tok/s.

MiniMax (18 MB/expert): PCIe transfer 1.4–1.5 ms > full layer decode 0.4–0.7 ms. PCIe path removed entirely; already lossy on 2-channel memory.

Miss cost
Miss cost

Figure 4: Three miss-service prices across models/engines/memory configs (order-of-magnitude only). Beige band = full layer decode time; when single-miss cost enters this band, PCIe is out. Hatched bar = compiler PDEP penalty.

NVMe tier: a third-party 3-tier (disk/memory/GPU) gives 17.3 vs 28.2 tok/s (~40% penalty). Author’s 4-month test never needed it; RAM was sufficient.

Speculative Decoding: Biggest Single Lever, Ceiling Is Model-Bound

Best single number in the repo: Qwen DFlash2 +44–46%. Dense models fully in VRAM achieve 2.75–3.62×.

Cost per verify round explains the gap:

Qwen: 11.2 ms + 3.8 ms × rows DeepSeek: 22.4 + 5.1 × rows + 13.4 × rows × miss_rate The last term means each extra row wakes a batch of cold experts. Speculative still helps by amortizing the constant, not by saving experts.

Weak-skew models: GLM DFlash2 only +4% over official MTP; reducing MTP draft length from 3 to 1 gives +17%. MiniMax DSpark drops 27.0 → 25.0 on 2K agent context until cost-based window strategy turns positive.

Hard ceiling: at T=1, model picks its own top-1 only 79% of positions → max speedup +20% (Russian +32%, reasoning +14.6%). This bound is knowable before any training.

Three models, three drafters, self-data fine-tune: DeepSeek 3.215 → 3.17–3.20 tokens/round; Qwen +4% (two-thirds from vocab change). Better ROI: Russian Cyrillic draft vocab lifts acceptance 32% → 54%, 78 → 94–101 tok/s without training; confidence threshold 0.35 → 0.5 adds +8–15%.

Speculative decoding
Speculative decoding

Figure 5: Speculative multipliers. Dense in-VRAM 2.75–3.62×; experts in memory 1.2–1.5×; weak-skew GLM only short windows help; MiniMax negative on real agent context until cost-based window. Batched: vLLM n-gram single-stream +40%, 4–8 streams -30% to -51%.

Prefill: A Different Battle, Enemy Often Not Experts

Prefill touches nearly every expert per layer → cold experts must re-traverse PCIe each block. Strategy flips: DMA into VRAM, not CPU.

DeepSeek 32K prompt: 430 → 2199 tok/s. Changes: DMA for all formats (original only MXFP4), skip unused layers, auto-chunking. Original single-card DMA 2.7 GB/s.

Hy4 Flash single-card: decouple weight-block token capacity and activation materialization. Load experts serving up to 57,600 tokens, attention slice 2048. 57,587-token prefill 415.6 → 1510.2 tok/s, wait 138.55 s → 38.13 s. Temp VRAM 629 MiB → 2005 MiB.

GLM block size 2048 → 4096: 764 → 1000 tok/s. Same trick on DeepSeek: +15% at 128K, but -7–8% on short prompts.

MiniMax 64K context: bottleneck is attention kernel reading K/V from host memory 32 bytes at a time, 73–383 reads per chunk. Moving K/V to VRAM once per block yields 3.3× prefill.

Prefill and depth
Prefill and depth

Figure 6: Left — prefill speedup factors (different builds, not directly comparable). Right — Inkling 2 Mini decode vs context depth (FP8 KV, 344K window): 340K depth 62.3 tok/s, 47-token prompt 128.7 tok/s.

All-in-VRAM Regime: Bottleneck Shifts to Kernel Launch Overhead

Inkling 2 Mini (24 physical MoE layers, 128 experts/layer, top-8, middle 12 layers repeated → 48 accesses/token, 14.7 GiB total) fits one 3090.

Problem: each token launches many kernels (2–3 μs each), SM runs 1 warp, IPC 0.2–0.3 → latency-bound, not bandwidth-bound.

llama.cpp: 57 tok/s.

Fuse router selection on device, read positions from device, whole token as CUDA graph: 112 tok/s.

Merge small kernels: launches/token 1404 → 781, each merge bitwise identical.

4K-depth profile: 8.34 ms kernel time, 781 launches; dense Q8 2.54 ms, NVFP4 experts 2.29 ms. Per-token weight read 3.7 GB, memory floor 4.6 ms, remaining 3.7 ms optimizable.

VRAM trick: 1M window with 8 global attention, FP8 KV = 16 GiB. Static max allocation leaves 285 expert slots for 3072 experts → 47-token prompt 8.72 tok/s. Global KV as CUDA managed memory lets experts stay on GPU for short requests; cost appears only at depth. Benchmarks must use max window and saturated prompts, otherwise measuring reservation overhead.

Measurement Discipline: The Hardest Part

The repo’s most valuable section is its treatment of numbers.

Short test promised UD quantization +27% decode; real generation +2%.

Synthetic prompt MiniMax 42 tok/s; real session “write an analysis” 26 tok/s.

Same build: mean 187.67, worst 159.35, worst rolling window 132.49 tok/s. Candidate improved minimum but lowered mean → rejected.

Q4 drafter head aligned first 4400 tokens; second round desynced due to snapshot boundary shift.

46 CPU threads caused 20–60 tok/s variance; engine default 32 threads stable 75+.

Hot RAM: 22.7 → 6.6 tok/s.

Background ComfyUI reduced expert cache by 146, output changed (KL 0.023). nvtop polling driver dropped generation to 11–20 tok/s.

Hard thresholds defined upfront: session sum 0.5%, median read 1.5%, decode 5%; smaller differences treated as noise. Must exceed A/A jitter (0.06%) by 3×.

Repo admits limitations: no stress framework, no concurrency data, single hardware setup. Tools: two stdlib Python scripts — one simulates skew and cache hits, one fits a + b × miss.

How to Use the Repository

Entry point is a situation table: fill model structure, quantization, GPU count, load type → tag like #offload #weak-skew #cpu-lane #multi-gpu #agent, then grep the ledger for matching conclusions.

For agents: clone repo into skills directory; root is itself a skill. README targets both human tuners and tuning agents with the same file.

Conclusion

The 42 failures kept in place with retry conditions are the real treasure. Engineering teams lack not conclusions but the conditions under which conclusions break. Guides showing only success paths mislead on different hardware; a ledger that includes failures remains a ruler when the hardware changes. The author emphasizes numbers come from one machine; each chapter ends with a migration checklist asking: can you reproduce the original bottleneck on your machine? If not, the speedups are irrelevant. Borrow the judgment order, not the absolute values.

About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

model optimizationspeculative decodinginference enginesCPU offloadRTX 3090MoE inferenceprefill optimizationmeasurement methodologyPCIe bandwidthrouter skew

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion