feat(moe): add--freq and --collect-routing, train predictor of experts

Merged
HO
6mo ago
+1120-5

Add expert frequency tracking and binary routing data collection for training MLP expert predictors.

New features:

  • --freq: prints per-layer expert frequency analysis at shutdown
  • --collect-routing

New files:

  • server/src/common/moe_routing_collector.{h,cpp}: thread-safe binary writer for per-token routing decisions
  • scripts/train_predictor.py: MLP/linear predictor training script (ported from StreamMoE, supports CUDA, mlp/linear/cross variants)

Binary format per sample:
[int32 layer_idx, int32 K, float32[n_embd] hidden, int32[K] experts]

Hooks added in qwen35moe pipelined decode (cached + dynamic paths), qwen35moe prefill, laguna hybrid decode, and laguna hybrid prefill.

Tested: 1K tokens , Qwen3.6-35B-A3B

Modeltop-4 Hittop-8 Hittop-16 Hit
linear34.9%53.5%69.2%
mlp-cross38.5%59.7%75.5%
baseline19.4%--

the mlp-cross predictor achieves 2x the baseline with only 1K token of training data.