研究大模型代码生成中专家路由的层间规律,发现相同输出时路由高度重合。
Layer-wise MoE Routing Locality under Shared-Prefix Code Generation: Token-Identity Decomposition and Compile-Equivalent Fork Redundancy

- 通过分层分解分析共享前缀下的专家路由行为
- 相同词元时路由相似度达随机的40倍,中间层差异路由更显著
- 多数可编译代码集中在少数汇编等价组,适合优化搜索效率
在基于大语言模型的代码生成中,多个代码候选常从同一提示并行生成,如 best-of-N 采样或多候选补全。这些请求可通过公共前缀共享 KV 缓存,但其混合专家(MoE)专家路由的重叠程度及层间变化仍不明确。本文以 Qwen3.5-35B-A3B-FP8(256 个路由专家,top-8)为基础,采用树搜索分支生成方式从共享前缀(851 个完整代码,温度 0.7)出发,并使用编译器输出对齐(gcc -S -O0 汇编)控制词元身份混淆。结果发现:(1) 在生成相同词元的位置,杰卡德相似度达 0.649(40 倍随机),即使在不同词元位置也保持 0.175(11 倍随机);(2) 分层分解显示交叉模式:所有层中相同词元路由相似度高于不同词元,但中间层(L14–20)出现下降,而不同词元相似度在中间层峰值达 14 倍随机;(3) 在树搜索生成中,67% 可成功编译的代码集中于前三类汇编等价组,组内差异 99.6% 为注释和空行。结果表明,top-P 搜索中的多样性带来显著挑战,通过分层分析修正了先前‘上下文无关路由’的说法,并为提升代码生成搜索效率提供新方向。
原文摘要 · Abstract (English)
In LLM-based code generation, multiple code candidates are often generated in parallel from the same prompt -- for example, in best-of-N sampling or multi-candidate code completion. These requests can share KV caches through a common prefix, yet the extent to which their Mixture-of-Experts (MoE) expert routing overlaps, and how this overlap varies across layers, remains insufficiently understood. We study Qwen3.5-35B-A3B-FP8 (256 routed experts, top-8) by performing tree-search-based branching generation from a shared prefix (851 completed codes, temperature 0.7) and analyzing the results with a compiler-output-based alignment (gcc -S -O0 assembly) that controls for token-identity confounds. Our findings are threefold: (1) At positions where both sequences generated the same token, Jaccard similarity reaches 0.649 (40x random), while even at positions with different tokens it remains 0.175 (11x random). (2) A layer-wise decomposition reveals a crossing pattern: same-token routing similarity exceeds different-token similarity across all layers, but dips in the middle layers (L14-20), while different-token similarity peaks in the middle layers at 14x random. (3) In tree-search code generation, 67% of successfully compiled codes concentrate in the top three assembly-equivalent groups, and 99.6% of within-group differences consist of comments and blank lines. We show that diversity in top-P search, including beam search, poses a significant challenge. These results refine the "context-independent routing" claim of prior work through layer-wise decomposition and suggest opportunities for improving search efficiency in LLM code generation.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。