Lngram v2: Latent N-Gram Memory with Balanced Binary Routing
Yunao Zheng, Bin Wen, Xiaojie Wang, Kaiyu Jiang, Xuanyu Zheng, Changyi Liu, Hongyi Fu, Jianxiong Wang 等 15 位作者
原文摘要
Conditional memory enables Transformers to reuse learned associations through direct retrieval. Lngram v2 constructs exact n-gram addresses from hidden-state-derived binary codes, providing a unified lookup mechanism across modalities. To improve memory utilization, we introduce median-based bit calibration without auxiliary losses. Using the same calibrated logits, counterfactual surrogate gradients enable the router to learn from differences between alternative retrievals. Fixed-logit ablations show that the balancing bias reduces bit imbalance and increases per-route code entropy. In a controlled continued-training experiment on Keye30B, Lngram v2 improves average vision--language performance. We further integrate Lngram v2 into KeyeOmni, a large-scale multimodal mixture-of-experts model, during mid-training. Optimized implementations incur modest runtime overhead in Megatron training and SGLang cached decoding. Semantic analysis on held-out English and Chinese text reveals that learned route codes and n-gram addresses encode semantic information beyond lexical and contextual cues. A code dictionary illustrates recurring semantic groups, while controlled word-sense interventions show that retrieved memory increases the model's preference for contextually appropriate answers. These findings support discrete conditional memory as an efficient and semantically informative complement to conventional feed-forward computation.
cs.CL