arXiv:2608.05141cs.AIcs.LG2026-08被引 1

用跨仓库代码依赖构建百万级长上下文,提升模型长期推理与编程能力。

OctoLong: Mid-Training On Cross-Repository Code Contexts Enhances Long-Context Modeling

论文配图:OctoLong: Mid-Training On Cross-Repository Code Contexts Enhances Long-Context Modeling
图 1 · 摘自论文原文
  • 通过解析器和包管理器递归获取代码依赖,生成百万级长代码上下文。
  • 仅用12%的自建数据,使模型在长程检索和代码理解上超越18个开源模型。
  • 适合需要长上下文推理的编程助手、自动化工具开发等场景。

语言模型的上下文长度大幅提升,以满足上下文学习、自我改进和长周期智能体工作流的需求。然而现有长上下文语料库主要由书籍、学术文章和代码仓库构成,资源有限且缺乏长距离依赖。本文提出OctoLong,一个基于AST解析器、语言服务器后端和包管理器的上下文工程管道,可递归检索代码引用,构建包含数百万标记的丰富依赖代码上下文。我们在此基础上训练了OctoLong-Instruct系列模型,使用600M至14B参数的基础模型,经过约500亿标记的混合数据(其中约62亿为OctoLong代码上下文)进行中段训练,再进行约100亿标记的指令微调。消融实验与18个前沿开源长上下文模型对比表明,仅将传统语料库的12%替换为OctoLong数据,即可显著提升长距离检索、长期状态追踪、仓库级代码理解及下游智能体任务表现,同时增强短上下文编程中的API使用能力。

原文摘要 · Abstract (English)

Context lengths of language models (LMs) have dramatically increased, driven by the demands for in-context learning, self-improvement, and long-horizon agentic workflows. Existing long-context corpora, however, are dominated by books, academic articles, and code repositories, which are finite resources and often scarce in long-distance dependencies. In this work, we introduce OctoLong, a context engineering pipeline that instruments an AST parser, a language server backend, and a package manager to facilitate the recursive retrieval of code references, enabling the curation of dependency-rich code contexts of millions of tokens in length. We then train OctoLong-Instruct, a suite of capable long-context open LMs, derived from base models ranging in size from 600M to 14B parameters, via context-extension mid-training on a ~50B-token mixture containing ~6.2B tokens of OctoLong code contexts, followed by ~10B tokens of instruction tuning. Our training ablations and experimental evaluations against 18 state-of-the-art open-weight long-context LMs show that supplanting just 12% of traditional context-extension corpora with OctoLong data yields substantial gains in long-range retrieval, long-term state tracking, repository-level code understanding, and downstream agentic tasks, while also enhancing API usage in short-context coding scenarios.

代码生成长上下文智能体

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。