# MoE Architecture The MoE model is the main scaling direction for code completion. The strongest current structure is sparse FFN experts with shared attention and optional multi-token prediction heads. ## Recommended Structure - Decoder-only Transformer. - RMSNorm before attention and FFN. - RoPE positional encoding. - Grouped-query attention. - SwiGLU experts. - Top-2 routing during training. - Shared expert for common syntax and indentation. - Router z-loss and auxiliary load-balancing loss. - QK norm for long-context attention stability. - Expert-choice telemetry from the first step, not after loss diverges. - Optional multi-token prediction heads with low loss weight. ## Best Current Shape Use shared attention and sparse FFN. Keep early layers mostly dense/shared so the model learns lexical syntax before specializing. - Early blocks: dense FFN or shared expert heavy. - Middle blocks: sparse MoE every other block. - Late blocks: sparse MoE with stricter router stability checks. - Expert count: start with 8 experts for smoke, then 16-32 for H100 ablation. - Routing: top-2 with capacity factor 1.25 during training. - Inference ablation: top-1 only after top-2 training is stable. For code completion, the highest-value specialization is not one expert per language. Better targets are syntax/indentation, FIM reconstruction, repository-context patterns, generated-code continuation, and real-code APIs. ## Routing Metrics Log: - Per-layer expert load. - Per-expert token fraction. - Dropped-token count. - Router entropy. - Auxiliary loss. - Domain-to-expert correlation. ## Failure Modes - Expert collapse. - Router churn. - Synthetic Python overfitting. - MTP loss overpowering next-token loss. - Shared expert absorbing too much load. - Dropped tokens above 1% for sustained windows.