MoSE: Hierarchical Self-Distillation Enhances Early Layer Embeddings
Andrea Gurioli, Federico Pennino, João Monteiro, Maurizio Gabbrielli
Abstract
Deploying language models often requires navigating accuracy vs. performance trade-offs to meet latency constraints while preserving utility. Traditional model distillation reduces size but incurs substantial costs through training separate models. We introduce ModularStarEncoder (MoSE), a 1-billion-parameter multi-exit encoder for code retrieval and classification that employs a novel Self-Distillation mechanism. This approach significantly enhances lower-layer representations, enabling flexible deployment of different model portions with favorable performance trade-offs. Our architecture improves text-to-code and code-to-code search by targeting specific encoder layers as exit heads, where higher layers guide earlier ones during training, thereby improving intermediate representations at minimal additional cost. We further enhance MoSE with a repository-level contextual loss that maximizes training context window utilization. Additionally, we release a new dataset created through code translation that extends text-to code benchmarks with cross-language code-to-code pairs. Evaluations demonstrate the effectiveness of Self-Distillation as a principled approach to trading inference cost for accuracy across various code understanding tasks.
Ask Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
Lineage
Builds on16
- Learning Transferable Visual Models From Natural Language SupervisionAlec Radford, Jong Wook Kim, Chris Hallacy, Aditya Ramesh et al.ICML 2021 · 47,906 citations
- A Simple Framework for Contrastive Learning of Visual RepresentationsTing Chen, Simon Kornblith, Mohammad Norouzi, Geoffrey E. HintonICML 2020 · 24,064 citations
- ALBERT: A Lite BERT for Self-supervised Learning of Language RepresentationsZhenzhong Lan, Mingda Chen, Sebastian Goodman, Kevin Gimpel et al.ICLR 2020 · 7,418 citations
- CodeBERT: A Pre-Trained Model for Programming and Natural LanguagesZhangyin Feng, Daya Guo, Duyu Tang, Nan Duan et al.EMNLP Findings 2020 · 2,828 citations
- FlashAttention-2: Faster Attention with Better Parallelism and Work PartitioningTri DaoICLR 2024 · 2,600 citations
Related papers
- SCoder: Progressive Self-Distillation for Bootstrapping Small-Scale Data Synthesizers to Empower Code LLMsXinyu Zhang, Changzhi Zhou, Linmei Hu, Luhao Zhang et al.EMNLP Findings 2025
- RepoDistill: Distilling Repository Knowledge through Compression-Aware Budget Allocation and Policy OptimizationXin Yin, Zixiang Ding, Yiang Zhang, Qiang Wang et al.ACL Findings 2026
- Self-Distillation for Model Stacking Unlocks Cross-Lingual NLU in 200+ LanguagesFabian David Schmidt, Philipp Borchert, Ivan Vulic, Goran GlavasEMNLP Findings 2024 · 2 citations
- Fitting Into Any Shape: A Flexible LLM-Based Re-Ranker With Configurable Depth and WidthZheng Liu, Chaofan Li, Shitao Xiao, Chaozhuo Li et al.WWW 2025 · 1 citation
- Beyond Distillation: Task-level Mixture-of-Experts for Efficient InferenceSneha Kudugunta, Yanping Huang, Ankur Bapna, Maxim Krikun et al.EMNLP Findings 2021 · 41 citations
