<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Long Context on JJ&#39;s Blog</title>
    <link>https://jjl357.github.io/blog/tags/long-context/</link>
    <description>Recent content in Long Context on JJ&#39;s Blog</description>
    <generator>Hugo -- 0.152.2</generator>
    <language>zh-cn</language>
    <lastBuildDate>Thu, 06 Aug 2026 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://jjl357.github.io/blog/tags/long-context/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>📝 LongCodeZip: Compress Long Context for Code Language Models - ASE&#39;25</title>
      <link>https://jjl357.github.io/blog/posts/longcodezip---compress-long-context-for-code-language-models---ase25/</link>
      <pubDate>Thu, 06 Aug 2026 00:00:00 +0000</pubDate>
      <guid>https://jjl357.github.io/blog/posts/longcodezip---compress-long-context-for-code-language-models---ase25/</guid>
      <description>&lt;h1 id=&#34;longcodezip-compress-long-context-for-code-language-models&#34;&gt;LongCodeZip: Compress Long Context for Code Language Models&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;Conference:&lt;/strong&gt; &lt;strong&gt;ASE 2025&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Paper:&lt;/strong&gt; &lt;a href=&#34;https://arxiv.org/abs/2510.00446&#34;&gt;https://arxiv.org/abs/2510.00446&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Github:&lt;/strong&gt; &lt;a href=&#34;https://github.com/YerbaPage/LongCodeZip&#34;&gt;https://github.com/YerbaPage/LongCodeZip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Authors:&lt;/strong&gt; Yuling Shi, Yichun Qian, Hongyu Zhang, Beijun Shen, Xiaodong Gu&lt;/p&gt;
&lt;h2 id=&#34;abstract&#34;&gt;Abstract&lt;/h2&gt;
&lt;p&gt;代码大模型在仓库级补全、模块总结和跨文件问答中，通常需要读取远超单个函数的上下文。直接把整个仓库送入模型不仅带来更高的推理延迟、显存和 API 费用，还可能因为 &lt;strong&gt;lost-in-the-middle&lt;/strong&gt; 现象让真正有用的信息淹没在长上下文中。最直接的检索增强生成（RAG）虽然能够选取与问题相似的代码，却容易漏掉变量名和表面语义都不相似、但在执行逻辑上不可缺少的依赖。&lt;/p&gt;
&lt;p&gt;LongCodeZip 是一个 &lt;strong&gt;training-free、model-agnostic、plug-and-play&lt;/strong&gt; 的长代码上下文压缩框架。它把压缩拆成两个层次：&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Coarse-grained compression&lt;/strong&gt;：以函数或类为单位，使用指令条件下的近似互信息 AMI 排序，优先保留能帮助模型理解当前任务的代码实体；&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fine-grained compression&lt;/strong&gt;：在保留下来的长函数内部，根据逐行困惑度变化切分语义块，再通过自适应预算和 0/1 背包选择最有价值的代码块。&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;这种设计同时利用了代码的层次结构和任务相关性。论文在 Long Code Completion、Long Module Summarization 与 RepoQA 三类任务上评估 LongCodeZip，在最高 &lt;strong&gt;5.6× 有效压缩率&lt;/strong&gt;下仍能维持甚至提高任务性能，并显著降低生成阶段的时间与额外显存开销。&lt;/p&gt;
&lt;h2 id=&#34;1-motivation&#34;&gt;1. Motivation&lt;/h2&gt;
&lt;h3 id=&#34;11-long-code-context-的实际代价&#34;&gt;1.1 Long Code Context 的实际代价&lt;/h3&gt;
&lt;p&gt;仓库级任务所需要的信息往往分散在不同文件、类和函数中。随着上下文长度增加，会同时出现四类问题：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;计算代价增加&lt;/strong&gt;：标准全注意力的计算量随序列长度近似二次增长；&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;部署成本增加&lt;/strong&gt;：更长的 KV Cache 占用更多显存，闭源 API 也按输入 token 计费；&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;有效性下降&lt;/strong&gt;：无关代码会稀释模型注意力，长上下文并不必然优于经过筛选的上下文；&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;窗口截断&lt;/strong&gt;：当仓库代码超过上下文窗口时，简单截断可能恰好删除关键依赖。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;因此，长代码压缩的目标不是机械地减少 token，而是回答两个问题：&lt;strong&gt;哪些函数与当前指令真正相关？一个相关函数内部又应该保留哪些连续代码块？&lt;/strong&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>📝 SWE-Pruner Pro: The Coder LLM Already Knows What to Prune</title>
      <link>https://jjl357.github.io/blog/posts/swe-pruner-pro---the-coder-llm-already-knows-what-to-prune/</link>
      <pubDate>Thu, 06 Aug 2026 00:00:00 +0000</pubDate>
      <guid>https://jjl357.github.io/blog/posts/swe-pruner-pro---the-coder-llm-already-knows-what-to-prune/</guid>
      <description>&lt;h1 id=&#34;swe-pruner-pro-the-coder-llm-already-knows-what-to-prune&#34;&gt;SWE-Pruner Pro: The Coder LLM Already Knows What to Prune&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;Status:&lt;/strong&gt; &lt;strong&gt;arXiv v1, 2026-07-20&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Paper:&lt;/strong&gt; &lt;a href=&#34;https://arxiv.org/abs/2607.18213&#34;&gt;https://arxiv.org/abs/2607.18213&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Github:&lt;/strong&gt; &lt;a href=&#34;https://github.com/Ayanami1314/swe-pruner-pro&#34;&gt;https://github.com/Ayanami1314/swe-pruner-pro&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Authors:&lt;/strong&gt; Yuhang Wang, Yuling Shi, Shaoqiu Zhang, Jialiang Liang, Shilin He, Siyu Ye, Yuting Chen, Kai Cai, Xiaodong Gu&lt;/p&gt;
&lt;h2 id=&#34;abstract&#34;&gt;Abstract&lt;/h2&gt;
&lt;p&gt;Coding Agent 在真实仓库中解决问题时，会不断调用 &lt;code&gt;cat&lt;/code&gt;、&lt;code&gt;grep&lt;/code&gt;、&lt;code&gt;ls&lt;/code&gt;、&lt;code&gt;python&lt;/code&gt; 等工具。工具输出不仅可能一次包含数百行内容，还会作为历史消息在后续轮次中被重复送入模型。真正决定修复方案的通常只是其中一小部分代码、错误信息或文件路径，其余内容却持续占用输入 token、显存和推理时间。&lt;/p&gt;
&lt;p&gt;以往的上下文剪枝大致有两条路线：通用压缩方法根据困惑度、语法结构或检索相似度选择内容；SWE-Pruner 一类任务感知方法则额外部署一个评分模型，并要求 Agent 每轮写出描述当前信息需求的 &lt;strong&gt;Goal Hint&lt;/strong&gt;。它们有一个共同点：都在 Agent 外部重新构造“哪些内容重要”这一信号。&lt;/p&gt;
&lt;p&gt;SWE-Pruner Pro 的核心观察是：&lt;strong&gt;Agent 在阅读工具输出并准备下一步行动时，其最后一层隐藏状态已经编码了每行内容与当前任务的相关性。&lt;/strong&gt; 因此，系统无需再调用独立模型，只需在冻结的 Agent backbone 上挂接一个小型分类头，将已有隐藏状态转换为逐 token 的保留概率，再通过行内多数投票得到 keep/prune 决策。一个由工具输出行数索引的长度感知嵌入，使短输出更保守、长输出更积极地压缩。&lt;/p&gt;
&lt;p&gt;论文在 Qwen3-Coder-Next 与 MiMo-V2-Flash 两个开放权重 backbone、四个多轮 benchmark 上进行评测。SWE-Pruner Pro 在所有六个只读任务设置中都降低了总 token，最高节省 &lt;strong&gt;39.4%&lt;/strong&gt;；在 MiMo-V2-Flash 的 SWE-Bench Verified 上，Resolve Rate 提高 &lt;strong&gt;3.8 个百分点&lt;/strong&gt;。部署方面，把约 18M 参数的 head 放入 SGLang 推理引擎后，16 条轨迹回放中的聚合剪枝开销约为生成时间的 &lt;strong&gt;15.0%&lt;/strong&gt;。&lt;/p&gt;</description>
    </item>
    <item>
      <title>📝 Long-Context Modeling with Dynamic Hierarchical Sparse Attention for Memory-Constrained LLM Inference - ICML&#39;26 Spotlight</title>
      <link>https://jjl357.github.io/blog/posts/long-context-modeling-with-dynamic-hierarchical-sparse-attention-for-memory-constrained-llm-inference---icml26-spotlight/</link>
      <pubDate>Fri, 10 Jul 2026 00:00:00 +0000</pubDate>
      <guid>https://jjl357.github.io/blog/posts/long-context-modeling-with-dynamic-hierarchical-sparse-attention-for-memory-constrained-llm-inference---icml26-spotlight/</guid>
      <description>&lt;h1 id=&#34;long-context-modeling-with-dynamic-hierarchical-sparse-attention-for-memory-constrained-llm-inference&#34;&gt;Long-Context Modeling with Dynamic Hierarchical Sparse Attention for Memory-Constrained LLM Inference&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;Conference:&lt;/strong&gt; &lt;strong&gt;ICML&#39;26 Spotlight&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Paper:&lt;/strong&gt; &lt;a href=&#34;https://arxiv.org/abs/2510.24606&#34;&gt;https://arxiv.org/abs/2510.24606&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Github:&lt;/strong&gt; &lt;a href=&#34;https://github.com/xiongsiheng/DHSA&#34;&gt;https://github.com/xiongsiheng/DHSA&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;abstract&#34;&gt;Abstract&lt;/h2&gt;
&lt;p&gt;Transformer Attention 的时间和显存开销随上下文长度平方增长，限制了长上下文 LLM 在有限显存设备上的部署。虽然长上下文 Attention 通常具有明显稀疏性，但显著 token 的位置会随任务和输入变化。Sliding Window、A-shape 和固定 Block-Sparse 等静态模式无法充分适应这种输入相关的稀疏分布；部分动态方法又依赖预定义模板或启发式规则。&lt;/p&gt;
&lt;p&gt;论文提出 &lt;strong&gt;Dynamic Hierarchical Sparse Attention（DHSA）&lt;/strong&gt;。DHSA 保持 LLM backbone 冻结，根据每层的 query/key 表征在线预测稀疏模式。方法首先使用轻量级边界预测器将序列划分为可变长 chunk，然后计算 chunk-level similarity，并将高分 chunk 展开为 token-level key index。稀疏注意力后端只对被选中的 token 执行精确 causal attention。&lt;/p&gt;
&lt;p&gt;&lt;img loading=&#34;lazy&#34; src=&#34;https://jjl357.github.io/blog/image/DHSA/niah-and-ttft.png&#34;&gt;&lt;/p&gt;
&lt;p&gt;在 Needle-in-a-Haystack、LongBench 和 RULER 上，DHSA 在低 token density 下保持接近 Dense Attention 的准确率。在效率方面：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;相同 prefill 成本下，相比 Block-Sparse 获得约 &lt;strong&gt;12%–20% relative accuracy gain&lt;/strong&gt;；&lt;/li&gt;
&lt;li&gt;128K context、6.25% token density 下，attention kernel 相对 FlashAttention-2 加速约 &lt;strong&gt;10.66×&lt;/strong&gt;；&lt;/li&gt;
&lt;li&gt;LLaMA-3.1-8B 4-bit 在单张 RTX 3090 24GB 上可以处理 100K context，而 Dense Attention 无法在该显存限制下运行；&lt;/li&gt;
&lt;li&gt;LongBench 上平均 TTFT 从 Dense FA2 的 3.28 秒降低到 1.88 秒。&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;1-introduction&#34;&gt;1. Introduction&lt;/h2&gt;
&lt;p&gt;长上下文能力使 LLM 能够处理长文档问答、代码仓库分析、历史记录总结和长时间 Agent 交互。然而，标准 Attention 需要计算所有 query-key pair：&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
