<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://ninehills.tech/feed.xml" rel="self" type="application/atom+xml" /><link href="https://ninehills.tech/" rel="alternate" type="text/html" /><updated>2026-05-25T00:39:30+00:00</updated><id>https://ninehills.tech/feed.xml</id><title type="html">九原山</title><subtitle>技术笔记与思考。关注大语言模型、AI Agent、推理优化、SRE 等领域。</subtitle><author><name>ninehills</name></author><entry><title type="html">Pi Agent 个人配置</title><link href="https://ninehills.tech/2026/05/15/162/" rel="alternate" type="text/html" title="Pi Agent 个人配置" /><published>2026-05-15T00:00:00+00:00</published><updated>2026-05-15T00:00:00+00:00</updated><id>https://ninehills.tech/2026/05/15/162</id><content type="html" xml:base="https://ninehills.tech/2026/05/15/162/"><![CDATA[<p>经过好几周的摸索和各种尝试，pi agent 的配置基本稳定，之前发了一个 list，没有解释不太友好，这次发个全量带注释的。</p>

<p>首先 Pi Agent 的优点就是原生 Pi 的功能极其简单，而扩展机制非常完善，所以即使社区没有你需要的扩展，也很容易 Vibe 出一个自用。
非常适合需要对 Agent 上下文进行精细控制的人。如果你需要的是开箱即用的产品，推荐还是使用 Claude Code 或者 Codex。</p>

<p>扩展选择原则：</p>
<ol>
  <li>占用上下文最小化，尽可能的摒弃大量注册 Tools 的行为</li>
  <li>同类插件选更新活跃、功能齐全的。</li>
  <li>有些不占用上下文没什么副作用，只是单纯显示优化和扩展功能的，入围标准很低。</li>
</ol>

<p>最终 Tools 占用 7.7k tokens。</p>

<p>功能扩展类：增加MCP Adapter、WebSearch、SubAgent、Goal 等功能</p>
<ul>
  <li>npm:pi-mcp-adapter：使用 Lazy load 的方式加载 mcp 服务器，我基本全局不会开启 MCP，在某些特定项目上会用。</li>
  <li>npm:pi-web-access：支持多个 Provider 的搜索聚合，效果很佳（社区有更多别的选择，可以自己找更好的实现）</li>
  <li>npm:pi-btw：实现 /btw 功能，但是我很少用。</li>
  <li>npm:@tintinweb/pi-subagents：尝试了多种实现，最终这个占用上下文 tokens 最少，用起来也还算稳定。</li>
  <li>npm:pi-goal：实现 /goal 功能</li>
  <li>npm:@juicesharp/rpiv-todo：实现 Todo 功能</li>
  <li>npm:@juicesharp/rpiv-ask-user-question：实现结构化对用户提问的功能（可选，其实我不爱用，这个工具要占 1k tokens 上下文）</li>
  <li>npm:@plannotator/pi-extension：提供网页可标注的 Plan 文件以及 Code Review。（挺好用的，但是它自带的逻辑有点多，我只需要交互式标注功能）</li>
  <li><code class="language-plaintext highlighter-rouge">https://github.com/davebcn87/pi-autoresearch</code>：增加 autoresearch 功能，不过我默认是禁用的，或者可以安装到项目级中，全局开启没必要。</li>
</ul>

<p>功能优化和管理类：各种 TUI 优化、扩展管理、体验优化等</p>
<ul>
  <li>npm:@marckrenn/pi-sub-bar：显示各种订阅的用量信息，最近不咋更新了</li>
  <li>npm:@tmustier/pi-usage-extension：增加 /usage 命令，查看 session 详细的统计信息。</li>
  <li><code class="language-plaintext highlighter-rouge">git:github.com/fluxgear/pi-thinking-steps</code>：将思考过程结构化显示，更美观</li>
  <li>npm:pi-cache-graph：显示缓存命中率的变化，可用来 Debug 影响上下文的扩展</li>
  <li>npm:pi-context-usage：增加 /context 命令，显示上下文的详细情况</li>
  <li>npm:@ramarivera/pi-skill-selector: 优化了斜杠选择 skill 的交互体验</li>
  <li>npm:pi-fallback-provider：可以配置一个虚拟模型，然后后面是多个模型组成的 Fallback Chain，这样当挂掉后可以自动fallback。（推荐要么就是相同模型跨不同的 Provider fallback，要么就是廉价模型组个 chain 完成特殊任务。不要混杂不同的模型，否则很难 debug ）</li>
  <li>npm:pi-command-history：使用 Ctrl + Up 来找相同目录的历史 command。(Pi 默认 Up 只能着同 session 的，很怪)</li>
  <li>npm:pi-discord-remote：这个插件很有意思，开启后它会为每个 session 都配置单独的会话，结束对话后自动销毁。这样在 discord 那边用起来就很简单，尤其是自动销毁。</li>
  <li>npm:@vanillagreen/pi-extension-manager：可以不用卸载扩展，而是禁用扩展。这玩意很卡，可以不用。</li>
  <li>npm:@vanillagreen/pi-session-manager：可以更好的在历史 session 中检索、跳转什么的，用处不大。</li>
</ul>

<p>Agent 行为优化类：会修改 Pi Agent 自身行为，影响较大</p>
<ul>
  <li>npm:pi-rtk-optimizer：使用 rtk 大幅压缩 Bash Tool 的输出</li>
  <li>npm:pi-caveman：Caveman 模式，可以让模型输出更少的废话（尤其是思维链）。如果模型用 gpt-5.5 off/low 的话没必要开，用一些思维链比较长的模型（比如 DeepSeek-V4-Pro high）的时候，可以考虑开启。默认我是关闭的。</li>
  <li>npm:pi-context-prune：通过自动将 tools output summary &amp; offload 来降低上下文占用。推荐要么是 agent-message 模式（也就是当 agent 完成任务后触发）或者 on-demand 模式（手动触发）。我是手动触发，从而最大限度规避 cache miss。</li>
  <li>npm:@ff-labs/pi-fff：优化文件、内容的搜索功能，效果很好，推荐。</li>
  <li>npm:pi-hashline-readmap：通过给文件每行增加一个 Hash Anchor 的方式，来解决大文件编辑失败的问题。还在测试效果。</li>
</ul>

<hr />

<blockquote>
  <p>原文发布于 <a href="https://github.com/ninehills/blog/issues/162">GitHub Issue #162</a><br />
创建于 2026-05-15T05:22:39Z，更新于 2026-05-25T00:28:33Z</p>
</blockquote>]]></content><author><name>ninehills</name></author><summary type="html"><![CDATA[经过好几周的摸索和各种尝试，pi agent 的配置基本稳定，之前发了一个 list，没有解释不太友好，这次发个全量带注释的。]]></summary></entry><entry><title type="html">OpenClaw 思考</title><link href="https://ninehills.tech/2026/02/05/154/" rel="alternate" type="text/html" title="OpenClaw 思考" /><published>2026-02-05T00:00:00+00:00</published><updated>2026-02-05T00:00:00+00:00</updated><id>https://ninehills.tech/2026/02/05/154</id><content type="html" xml:base="https://ninehills.tech/2026/02/05/154/"><![CDATA[<h2 id="openclaw-产品形态贾维斯jarvis">OpenClaw 产品形态：贾维斯（J.A.R.V.I.S.）</h2>

<p>OpenClaw 和 Claude Code/Cowork 等 Agent 产品的核心区别有四：</p>

<table>
  <thead>
    <tr>
      <th> </th>
      <th>Manus/Claude Code/Claude Cowork 等通用 Agent 产品</th>
      <th>OpenClaw</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>交互入口</td>
      <td>以CLI、Web、桌面App 作为入口</td>
      <td>以IM作为核心入口，主要在手机上使用。</td>
    </tr>
    <tr>
      <td>交互方式</td>
      <td>用户-&gt;Agent 的单向交互（用户下发任务，Agent 完成任务）</td>
      <td>双向交互，Agent 可以根据 Cron、Heartbeat 机制主动执行任务和联系用户</td>
    </tr>
    <tr>
      <td>Agent 生命周期</td>
      <td>按需启动</td>
      <td>7x24h 全天在线</td>
    </tr>
    <tr>
      <td>Agent 运行环境</td>
      <td>分散的或一次性的</td>
      <td>持久的工作区和运行环境</td>
    </tr>
  </tbody>
</table>

<p>OpenClaw 是完整的个人助理产品形态，7x24h 运行在个人电脑上，可响应指令也可主动发起任务。其产品形态意义等同于 Manus 之于通用智能体。</p>

<h2 id="openclaw-技术实现简单的通用-agent-实现">OpenClaw 技术实现：简单的通用 Agent 实现</h2>

<p>核心概念和实现方式（部分概念虽好但实现欠佳，如 Node，此处不做展开）如下：</p>

<ul>
  <li>Gateway：统一的后台服务进程</li>
  <li>Agent：Gateway 启动后可注册多个 Agent（智能体），每个 Agent 拥有独立的 Workspace（工作区）。
    <ul>
      <li>实现：基于 Pi 极简 Agent 框架，核心采用 ReACT（System Prompt + 工具使用）范式。</li>
      <li>SubAgent：子 Agent，允许在会话中启动子 Agent（子 Agent 仅共享工作区，不共享上下文），任务完成后向主 Agent 发送摘要。</li>
    </ul>
  </li>
  <li>Workspace：每个 Agent 独立的工作区，核心文件如下（均支持对话式隐式修改，例如用户说”从现在起你叫 Jack”，会自动更新 IDENTITY.md）
    <ul>
      <li><code class="language-plaintext highlighter-rouge">AGENTS.md</code>：相当于 <code class="language-plaintext highlighter-rouge">CLAUDE.md</code>，附加到 system prompt 中，定义 Agent 核心行为。</li>
      <li><code class="language-plaintext highlighter-rouge">IDENTITY.md</code>：Agent 身份定义（名称、头像等）</li>
      <li><code class="language-plaintext highlighter-rouge">SOUL.md</code>：Agent 核心人设或性格特征</li>
      <li><code class="language-plaintext highlighter-rouge">USER.md</code>：用户偏好设置（称呼、习惯、地点等）</li>
      <li><code class="language-plaintext highlighter-rouge">MEMORY.md</code>：每次会话前必读的核心记忆，例如默认语言等。</li>
      <li><code class="language-plaintext highlighter-rouge">memory/</code>：记忆目录，除 Agent 自主生成外，按时间组织（2026-02-03-2134.md 或 2026-02-05.md），保存 Session 摘要。</li>
      <li><code class="language-plaintext highlighter-rouge">HEARTBEAT.md</code>：定义心跳任务，每 30 分钟执行一次。</li>
      <li><code class="language-plaintext highlighter-rouge">TOOLS.md</code>：工具使用指引，定义工具调用场景和条件。</li>
    </ul>
  </li>
  <li>Session：会话，每个 Agent 支持多个会话（如不同 IM 账号、群组、主题等），会话间上下文独立，但共享同一 Workspace。
    <ul>
      <li>会话上下文默认累积，除非达到上限触发压缩，或手动使用 <code class="language-plaintext highlighter-rouge">/new</code> 清空。</li>
      <li>同一 Session 内，Agent 交互串行处理，新消息进入队列等待。</li>
    </ul>
  </li>
  <li>Channel：频道（通常为 IM），Agent 与用户交互的主要载体，支持常见聊天应用。
    <ul>
      <li>以 Telegram 为例：可配置多个 Bot，每个 Bot 可加入不同群组，每个群组可配置不同主题。</li>
      <li>用户向 Bot 发起聊天后，会创建或复用已有 Session。</li>
    </ul>
  </li>
  <li>Cron and Heartbeat：定时任务和心跳机制。
    <ul>
      <li>Heartbeat：每 30 分钟（可配置）在指定 Session 中（默认为主 Session）执行 HEARTBEAT.md 中的任务并发送消息。无需发送时返回 HEARTBEAT_OK。</li>
      <li>Cron：定时任务，指定特定 Agent，可选择新建 Session 或在特定 Session 中执行。</li>
    </ul>
  </li>
  <li>Tools &amp; Skills：工具和技能体系
    <ul>
      <li>内置工具：Bash、文件编辑、Web Reader/Searcher、浏览器等。
        <ul>
          <li>浏览器控制目前效果尚不理想。</li>
        </ul>
      </li>
      <li>Skills：OpenClaw 通过 Skills 扩展能力，支持官方 Skill 和外部 Skill 目录。</li>
      <li>MCP vs Skill：
        <ul>
          <li><strong>OpenClaw 默认不支持 MCP，这是很正确的实现。</strong>
            <ul>
              <li>如确需调用已有 MCP Server，可以用 mcporter 命令行工具调用（封装为单独的 skill）</li>
            </ul>
          </li>
          <li>Skill 实现上优先使用 CLI 调用外部工具，而非 API 调用。
            <ul>
              <li>当前 LLM 对 CLI 工具调用有较好理解，例如 qmd（文件搜索）、gogs（Gmail 控制）、agent-browser（浏览器控制）。</li>
            </ul>
          </li>
        </ul>
      </li>
    </ul>
  </li>
</ul>

<p>抛开那些不稳定的特性和兼容代码，OpenClaw 的核心功能很容易实现。</p>

<h2 id="openclaw-个人案例">OpenClaw 个人案例</h2>

<ol>
  <li>每次心跳检查我的新推、搜索感兴趣的领域、回顾对话历史等，并编写日记，推送到 Github pages中。比较有意思的一篇：<a href="https://ninehills.github.io/jack-diary/articles/20260204-sentience-vs-consciousness.html">知道与痛苦</a></li>
  <li>单独的投资 Bot，检查我的持仓（截图后让其识别为本地 JSON文件），查询基本面和技术面，给出投资建议（加仓、建仓等）。交易日每个小时运行。</li>
</ol>

<p><img width="400" alt="Image" src="https://github.com/user-attachments/assets/1bfb2b0d-1247-4aec-9571-dd705806cea5" /></p>

<hr />

<blockquote>
  <p>原文发布于 <a href="https://github.com/ninehills/blog/issues/154">GitHub Issue #154</a><br />
创建于 2026-02-05T07:03:29Z，更新于 2026-03-05T05:36:04Z</p>
</blockquote>]]></content><author><name>ninehills</name></author><summary type="html"><![CDATA[OpenClaw 产品形态和技术实现的深度思考，对比通用 Agent 产品的核心差异。]]></summary></entry><entry><title type="html">自主 Agent / 上下文工程资料索引</title><link href="https://ninehills.tech/2026/01/04/150/" rel="alternate" type="text/html" title="自主 Agent / 上下文工程资料索引" /><published>2026-01-04T00:00:00+00:00</published><updated>2026-01-04T00:00:00+00:00</updated><id>https://ninehills.tech/2026/01/04/150</id><content type="html" xml:base="https://ninehills.tech/2026/01/04/150/"><![CDATA[<p>自主 Agent / 上下文工程资料索引和个人的一些点评，基本以工程为主。学术界普遍集中在 Agent RL 上，这里不进行展开。</p>

<ul>
  <li><a href="https://www.anthropic.com/engineering/building-effective-agents">Building effective agents</a> by Anthropic
    <ul>
      <li>【可选】24年12月的文章，比较鲜明的将 Workflow 和 Autonomous Agent 拆分，并着重在未来 Agent 的发展。</li>
    </ul>
  </li>
  <li><a href="https://www.anthropic.com/engineering/multi-agent-research-system">How we built our multi-agent research system</a> by Anthropic
    <ul>
      <li>【<strong>必读</strong>】Anthropic 的博客文章，核心解析 <strong>Claude  Deep Research</strong> 的技术框架，介绍了 SubAgent（Agent as Tool）、Todo tools 等方法。</li>
    </ul>
  </li>
  <li><a href="https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents">Effective context engineering for AI agents</a> by Anthropic
    <ul>
      <li>【<strong>必读</strong>】Anthropic 上下文工程标志性文章，包括上下文压缩、SubAgent、Agentic Memory 等方法的介绍。</li>
    </ul>
  </li>
  <li><a href="https://www.anthropic.com/engineering/advanced-tool-use">Introducing advanced tool use on the Claude Developer Platform</a> by Anthropic
    <ul>
      <li>【<strong>必读</strong>】介绍<strong>Tool Search Tool</strong>（工具搜索工具）、<strong>Programmatic Tool Calling</strong>（程序化工具调用）、<strong>Tool Use Examples</strong>（工具示例）三种范式，虽然实现细节被隐藏到 Claude API 之后，但不难复刻。</li>
      <li>相关文章：
        <ul>
          <li><a href="https://www.anthropic.com/engineering/code-execution-with-mcp">Code execution with MCP: Building more efficient agents</a> Programmatic Tool Calling 范式的首次介绍。</li>
        </ul>
      </li>
    </ul>
  </li>
  <li><a href="https://www.anthropic.com/engineering/equipping-agents-for-the-real-world-with-agent-skills">Equipping agents for the real world with Agent Skills</a> by Anthropic
    <ul>
      <li>【<strong>必读</strong>】介绍 <strong>Agent Skills</strong> 范式，Skills 目前是最优雅的 Agent 垂直能力注入方式，强烈建议采用。</li>
    </ul>
  </li>
  <li><a href="https://www.anthropic.com/engineering/claude-code-sandboxing">Beyond permission prompts: making Claude Code more secure and autonomous</a> Anthropic
    <ul>
      <li>【可选】Claude Code Sandbox 机制的介绍，同时有开源实现 <a href="https://github.com/anthropic-experimental/sandbox-runtime">sandbox-runtime</a> 供参考，是比较轻量级的 Sandbox 实现。还可以通过 Container 来进行较重的实现。</li>
    </ul>
  </li>
  <li><a href="https://www.anthropic.com/engineering/writing-tools-for-agents">Writing effective tools for agents — with agents</a> by Anthropic
    <ul>
      <li>【<strong>必读</strong>】如何为 Agent 设计更有效的工具，不是把接口封装到 MCP Server 那么简单，参数、返回值、描述和错误信息都需要优化。</li>
    </ul>
  </li>
  <li><a href="https://www.anthropic.com/engineering/claude-code-best-practices">Claude Code: Best practices for agentic coding</a> by Anthropic
    <ul>
      <li>【可选】跨时代的产品： Claude Code 的发布文章。</li>
      <li>相关资料
        <ul>
          <li><a href="https://github.com/marckrenn/claude-code-changelog">Claude Code Changelog</a>：追踪 Claude Code 的系统提示词的变化，能学到很多 Agent 设计技巧。</li>
        </ul>
      </li>
    </ul>
  </li>
  <li><a href="https://www.anthropic.com/engineering/building-agents-with-the-claude-agent-sdk">Building agents with the Claude Agent SDK</a> by Anthropic
    <ul>
      <li>【<strong>必读</strong>】使用 Claude Agent SDK 开发自主 Agent，虽然效果依然最佳，但 Agent SDK 的底层是闭源的 Claude Code，谨慎使用。</li>
    </ul>
  </li>
  <li><a href="https://www.anthropic.com/engineering/effective-harnesses-for-long-running-agents">Effective harnesses for long-running agents</a> by Anthropic
    <ul>
      <li>【<strong>必读</strong>】讲设计长时运行 Agent 的一些经验，内容不多但有较大价值。</li>
    </ul>
  </li>
  <li><a href="https://rlancemartin.github.io/2025/06/23/context_engineering/">Context Engineering for Agents</a> by Lance Martion and Langchain
    <ul>
      <li>【<strong>必读</strong>】上下文工程的另一个介绍，图主要来自于 Langchain 的 blog。</li>
    </ul>
  </li>
  <li><a href="https://rlancemartin.github.io/2025/10/15/manus/">Context Engineering in Manus</a> by Manus
    <ul>
      <li>【<strong>必读</strong>】Manus 的上下文工程的实践经验，虽然 Manus 争议很大，但他们在自主 Agent 领域至少和 Anthropic 一样走在行业前列。提到了上下文 Offload、Reduce和Isolate 等方法。此外自25年3月到10月，Manus 已经重构了 5 次，切记一点，Agent 处在架构和模型迅猛变更的环境中。</li>
      <li>相关资料：<a href="https://www.youtube.com/watch?v=6_BcCthVvb8">视频</a> <a href="https://drive.google.com/file/d/1QGJ-BrdiTGslS71sYH4OJoidsry3Ps9g/view">PPT</a>  <a href="https://www.bestblogs.dev/video/087a1f3">文字稿</a></li>
    </ul>
  </li>
  <li><a href="https://metr.org/blog/2025-03-19-measuring-ai-ability-to-complete-long-tasks/">Measuring AI Ability to Complete Long Tasks</a> by METR
    <ul>
      <li>【可选】我经常引用的评测结果：自主Agent 能够完成的等效人类任务时长每7个月翻一番。</li>
    </ul>
  </li>
  <li><a href="https://github.com/MoonshotAI/kimi-cli">Kimi CLI Agent</a> by Kimi
    <ul>
      <li>【<strong>必读</strong>】设计良好，代码非常优雅的 CLI Agent 开源项目。</li>
    </ul>
  </li>
  <li><a href="https://github.com/langchain-ai/deepagents">DeepAgents</a> by Langchain
    <ul>
      <li>【<strong>必读</strong>】LangChain 的自主 Agent 实现，借鉴了 LangGraph 的成功经验，提出的 Middleware 机制对上下文工程来说是非常不错的抽象。更新很快，Skills等均已经得到支持。还提供一个不错的 UI 界面。</li>
    </ul>
  </li>
  <li><a href="https://www.philschmid.de/agents-2.0-deep-agents">Agents 2.0: From Shallow Loops to Deep Agents</a> by Philschmid
    <ul>
      <li>【可选】提出了 Agent 2.0 的概念，算是个总结。</li>
    </ul>
  </li>
  <li><a href="https://rlancemartin.github.io/2025/07/30/bitter_lesson/">Learning the Bitter Lesson</a> by Lance Martin
    <ul>
      <li>【可选】把 Bitter Lesson 和目前的 Agent 结合，也是我最近引用的一种思想。</li>
    </ul>
  </li>
  <li><a href="https://rllm-project.com/post.html?post=sdk.md">rLLM SDK: Training Any Agentic Program without Code Changes</a> by rLLM
    <ul>
      <li>【可选】有很多 Agent RL Training 的库，尝试了一圈，还是 rLLM 更可靠，更新更快。ART、agent-lightning 等项目都有各自的问题。</li>
    </ul>
  </li>
  <li><a href="https://saurabhalone.com/blog/agent">The Hitchhikers Guide to LLM Agent</a> by Saurabhalone
    <ul>
      <li>【<strong>必读</strong>】作者从头搭建了一个 Coding Agent，这是他的经验，最近比较好的文章之一。</li>
    </ul>
  </li>
  <li><a href="https://lucumr.pocoo.org/2025/12/13/skills-vs-mcp/">Skills vs Dynamic MCP Loadouts</a> by Armin Ronachers
    <ul>
      <li>【可选】很简单的一件事，<strong>使用 Skills 替代 MCP，</strong> 这也是我的实践。</li>
    </ul>
  </li>
  <li><a href="https://arxiv.org/abs/2510.16720">Beyond Pipelines: A Survey of the Paradigm Shift toward Model-Native Agentic AI</a>
    <ul>
      <li>【可选】一篇综述文章，介绍从Pipeline（Workflow）到自主 Agent 的范式转移。</li>
    </ul>
  </li>
</ul>

<hr />

<blockquote>
  <p>原文发布于 <a href="https://github.com/ninehills/blog/issues/150">GitHub Issue #150</a><br />
创建于 2026-01-04T08:04:33Z，更新于 2026-02-17T17:53:55Z</p>
</blockquote>]]></content><author><name>ninehills</name></author><summary type="html"><![CDATA[自主 Agent 和上下文工程的资料索引与点评，涵盖 Anthropic、Google 等前沿研究。]]></summary></entry><entry><title type="html">Tinker RL 测试（含代码库）</title><link href="https://ninehills.tech/2025/12/25/148/" rel="alternate" type="text/html" title="Tinker RL 测试（含代码库）" /><published>2025-12-25T00:00:00+00:00</published><updated>2025-12-25T00:00:00+00:00</updated><id>https://ninehills.tech/2025/12/25/148</id><content type="html" xml:base="https://ninehills.tech/2025/12/25/148/"><![CDATA[<p>Tinker 全量放开后，做了个简单的 RL 测试。</p>

<ol>
  <li><strong>Countdown-4 任务</strong>，也就是给四个数字比如 [90, 48, 12, 12]，让模型得出目标数 88 的表达式[90 - (48 / (12 + 12)) = 88]，类似于小时候玩的24点。</li>
  <li>基础模型选用 <strong>Qwen3-4B</strong>，未训练的正确率是42%（限制3K tokens 输出）</li>
  <li>使用默认的 RL 算法，200 steps，每个step(batch) 64 group，每个group 4 rollout。</li>
</ol>

<p>总共花费 $45（tinker 赠金 $150），这个任务在4090 本地这个数据量得跑好几天，用tinker的话4个小时左右。</p>

<p><strong>效果很明显，超过 Qwen3-235B。</strong></p>

<p><img width="800" height="450" alt="Image" src="https://github.com/user-attachments/assets/003f8056-20aa-44ff-83d8-e39a1ab883bb" /></p>

<p>代码库：https://github.com/ninehills/tinker-countdown</p>

<hr />

<blockquote>
  <p>原文发布于 <a href="https://github.com/ninehills/blog/issues/148">GitHub Issue #148</a><br />
创建于 2025-12-25T02:49:42Z，更新于 2025-12-25T02:49:42Z</p>
</blockquote>]]></content><author><name>ninehills</name></author><summary type="html"><![CDATA[Tinker RL 强化学习框架测试：使用 Qwen3-4B 在 Countdown 任务上的 RL 训练实验。]]></summary></entry><entry><title type="html">LLM 量化（GPTQ、GGUF）实战以及效果和推理性能实测</title><link href="https://ninehills.tech/2025/09/22/143/" rel="alternate" type="text/html" title="LLM 量化（GPTQ、GGUF）实战以及效果和推理性能实测" /><published>2025-09-22T00:00:00+00:00</published><updated>2025-09-22T00:00:00+00:00</updated><id>https://ninehills.tech/2025/09/22/143</id><content type="html" xml:base="https://ninehills.tech/2025/09/22/143/"><![CDATA[<p>涉及到的代码在： https://github.com/ninehills/llm-speedup</p>

<h2 id="1-安装环境">1. 安装环境</h2>

<p>硬件环境：</p>

<ul>
  <li>GTX 4090 24GB x 1</li>
  <li>Windows 11 + WSL2</li>
  <li>Driver Version: 581.29</li>
</ul>

<p>安装软件环境（依赖conda: https://conda-forge.org/download/）</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># 国内配置：export HF_ENDPOINT=https://hf-mirror.com</span>
conda create <span class="nt">-n</span> llm-speedup <span class="nv">python</span><span class="o">==</span>3.12
conda activate llm-speedup

pip <span class="nb">install</span> <span class="s2">"vllm==0.10.2"</span> <span class="s2">"sglang==0.5.2"</span> <span class="s2">"evalscope[perf]==1.0.1"</span> langdetect immutabledict
<span class="nb">cd </span>llm-compressor
pip <span class="nb">install</span> <span class="nt">-e</span> ./

pip <span class="nb">install</span> <span class="s2">"datasets&lt;4.0.0"</span> <span class="c"># fix evalscope datasets failed</span>
</code></pre></div></div>

<h2 id="2-量化">2. 量化</h2>

<h3 id="21-使用-llm-compressor-gptq-量化">2.1 使用 llm-compressor GPTQ 量化</h3>

<p>我们以 GPTQ w4a16g128 量化 Qwen/Qwen3-4B-Instruct-2507 模型为例，其他量化方法（AWQ等）请参考 llm-compressor 文档。</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># 生成校准数据集，使用中英文高质量 SFT 数据</span>
python calib_data.py
<span class="c"># 进行 GPTQ 量化</span>
python qwen3_dense_instruct_w4a16.py
<span class="c"># 逐层量化，大约需要 10 - 20 分钟</span>
</code></pre></div></div>

<ul>
  <li>校准数据集使用中英文混合的高质量对话 SFT 数据1024条。</li>
  <li>从各种评测和经验看，推荐使用 GPTQ w8a16/w4a16 量化，效果损失最小。</li>
  <li>注意 MoE 模型量化时，需要额外忽略 Gate 层，避免量化误差过大。</li>
  <li>如果量化损失过大，可以控制忽略掉前 N 层。</li>
</ul>

<h3 id="22-gptq-量化前后效果分析">2.2 GPTQ 量化前后效果分析</h3>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># 启动bf16推理服务</span>
vllm serve Qwen/Qwen3-4B-Instruct-2507 <span class="nt">--max-model-len</span> 8192 <span class="nt">--served-model-name</span> Qwen3-4B-Instruct-2507 <span class="nt">--port</span> 8080
<span class="c"># 评测 Math500（数学）、IFEval（指令遵循）、IQuiz（中文理解）</span>
evalscope <span class="nb">eval</span> <span class="se">\</span>
 <span class="nt">--model</span> Qwen3-4B-Instruct-2507 <span class="se">\</span>
 <span class="nt">--api-url</span> http://127.0.0.1:8080/v1 <span class="se">\</span>
 <span class="nt">--api-key</span> EMPTY <span class="se">\</span>
 <span class="nt">--eval-type</span> openai_api <span class="se">\</span>
 <span class="nt">--datasets</span> math_500 ifeval iquiz <span class="se">\</span>
 <span class="nt">--eval-batch-size</span> 100
+------------------------+-----------+--------------------------+----------+-------+---------+---------+
| Model                  | Dataset   | Metric                   | Subset   |   Num |   Score | Cat.0   |
+<span class="o">========================</span>+<span class="o">===========</span>+<span class="o">==========================</span>+<span class="o">==========</span>+<span class="o">=======</span>+<span class="o">=========</span>+<span class="o">=========</span>+
| Qwen3-4B-Instruct-2507 | ifeval    | mean_prompt_level_strict | default  |   541 |  0.8299 | default |
| Qwen3-4B-Instruct-2507 | ifeval    | mean_inst_level_strict   | default  |   541 |  0.8882 | default |
| Qwen3-4B-Instruct-2507 | iquiz     | mean_acc                 | OVERALL  |   120 |  0.525  | -       |
| Qwen3-4B-Instruct-2507 | math_500  | mean_acc                 | OVERALL  |   500 |  0.776  | -       |
+------------------------+-----------+--------------------------+----------+-------+---------+---------+ 

<span class="c"># 启动w4a16推理服务</span>
vllm serve Qwen3-4B-Instruct-2507-W4A16-G128 <span class="nt">--max-model-len</span> 8192 <span class="nt">--served-model-name</span> Qwen3-4B-Instruct-2507-W4A16-G128 <span class="nt">--port</span> 8080
<span class="c"># 评测</span>
evalscope <span class="nb">eval</span> <span class="se">\</span>
 <span class="nt">--model</span> Qwen3-4B-Instruct-2507-W4A16-G128 <span class="se">\</span>
 <span class="nt">--api-url</span> http://127.0.0.1:8080/v1 <span class="se">\</span>
 <span class="nt">--api-key</span> EMPTY <span class="se">\</span>
 <span class="nt">--eval-type</span> openai_api <span class="se">\</span>
 <span class="nt">--datasets</span> math_500 ifeval iquiz <span class="se">\</span>
 <span class="nt">--eval-batch-size</span> 100
+-----------------------------------+-----------+--------------------------+----------+-------+---------+---------+
| Model                             | Dataset   | Metric                   | Subset   |   Num |   Score | Cat.0   |
+<span class="o">===================================</span>+<span class="o">===========</span>+<span class="o">==========================</span>+<span class="o">==========</span>+<span class="o">=======</span>+<span class="o">=========</span>+<span class="o">=========</span>+
| Qwen3-4B-Instruct-2507-W4A16-G128 | ifeval    | mean_prompt_level_strict | default  |   541 |  0.8355 | default |
| Qwen3-4B-Instruct-2507-W4A16-G128 | ifeval    | mean_inst_level_strict   | default  |   541 |  0.8879 | default |
| Qwen3-4B-Instruct-2507-W4A16-G128 | iquiz     | mean_acc                 | OVERALL  |   120 |  0.5333 | -       |
| Qwen3-4B-Instruct-2507-W4A16-G128 | math_500  | mean_acc                 | OVERALL  |   500 |  0.782  | -       |
+-----------------------------------+-----------+--------------------------+----------+-------+---------+---------+ 
</code></pre></div></div>

<p>发现：量化后指标反而全面高于未量化模型，这是因为我们的校准数据集为高质量 SFT 数据，属于正常现象。</p>

<h3 id="23-gptq-量化前后-vllm-推理性能分析">2.3 GPTQ 量化前后 vLLM 推理性能分析</h3>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>vllm serve Qwen/Qwen3-4B-Instruct-2507 <span class="nt">--max-model-len</span> 8192 <span class="nt">--served-model-name</span> Qwen3-4B-Instruct-2507 <span class="nt">--port</span> 8080
evalscope perf <span class="se">\</span>
  <span class="nt">--parallel</span> 1 10 20 50 100 <span class="se">\</span>
  <span class="nt">--number</span> 10 30 50 100 200 <span class="se">\</span>
  <span class="nt">--model</span> Qwen3-4B-Instruct-2507 <span class="se">\</span>
  <span class="nt">--url</span> http://127.0.0.1:8080/v1/chat/completions <span class="se">\</span>
  <span class="nt">--api</span> openai <span class="se">\</span>
  <span class="nt">--dataset</span> random <span class="se">\</span>
  <span class="nt">--max-tokens</span> 1024 <span class="se">\</span>
  <span class="nt">--min-tokens</span> 1024 <span class="se">\</span>
  <span class="nt">--prefix-length</span> 0 <span class="se">\</span>
  <span class="nt">--min-prompt-length</span> 1024 <span class="se">\</span>
  <span class="nt">--max-prompt-length</span> 1024 <span class="se">\</span>
  <span class="nt">--tokenizer-path</span> Qwen3-4B-Instruct-2507 <span class="se">\</span>
  <span class="nt">--extra-args</span> <span class="s1">'{"ignore_eos": true}'</span>

┏━━━━━━┳━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┓
┃      ┃      ┃      Avg ┃      P99 ┃    Gen. ┃      Avg ┃     P99 ┃      Avg ┃     P99 ┃   Success┃
┃Conc. ┃  RPS ┃  Lat.<span class="o">(</span>s<span class="o">)</span> ┃  Lat.<span class="o">(</span>s<span class="o">)</span> ┃  toks/s ┃  TTFT<span class="o">(</span>s<span class="o">)</span> ┃ TTFT<span class="o">(</span>s<span class="o">)</span> ┃  TPOT<span class="o">(</span>s<span class="o">)</span> ┃ TPOT<span class="o">(</span>s<span class="o">)</span> ┃      Rate┃
┡━━━━━━╇━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━┩
│    1 │ 0.09 │   11.530 │   11.588 │   88.81 │    0.050 │   0.065 │    0.011 │   0.011 │    100.0%│
│   10 │ 0.65 │   15.284 │   15.711 │  669.34 │    0.288 │   0.628 │    0.015 │   0.015 │    100.0%│
│   20 │ 0.93 │   18.492 │   20.202 │  954.49 │    0.467 │   1.304 │    0.018 │   0.019 │    100.0%│
│   50 │ 1.52 │   30.359 │   38.295 │ 1555.54 │    1.214 │   3.216 │    0.029 │   0.034 │    100.0%│
│  100 │ 1.54 │   54.048 │   75.195 │ 1579.02 │   13.821 │  39.359 │    0.039 │   0.066 │    100.0%│
└──────┴──────┴──────────┴──────────┴─────────┴──────────┴─────────┴──────────┴─────────┴──────────┘

vllm serve Qwen3-4B-Instruct-2507-W4A16-G128 <span class="nt">--max-model-len</span> 8192 <span class="nt">--served-model-name</span> Qwen3-4B-Instruct-2507-W4A16-G128 <span class="nt">--port</span> 8080
evalscope perf <span class="se">\</span>
  <span class="nt">--parallel</span> 1 10 20 50 100 <span class="se">\</span>
  <span class="nt">--number</span> 10 30 50 100 200 <span class="se">\</span>
  <span class="nt">--model</span> Qwen3-4B-Instruct-2507-W4A16-G128 <span class="se">\</span>
  <span class="nt">--url</span> http://127.0.0.1:8080/v1/chat/completions <span class="se">\</span>
  <span class="nt">--api</span> openai <span class="se">\</span>
  <span class="nt">--dataset</span> random <span class="se">\</span>
  <span class="nt">--max-tokens</span> 1024 <span class="se">\</span>
  <span class="nt">--min-tokens</span> 1024 <span class="se">\</span>
  <span class="nt">--prefix-length</span> 0 <span class="se">\</span>
  <span class="nt">--min-prompt-length</span> 1024 <span class="se">\</span>
  <span class="nt">--max-prompt-length</span> 1024 <span class="se">\</span>
  <span class="nt">--tokenizer-path</span> Qwen3-4B-Instruct-2507-W4A16-G128 <span class="se">\</span>
  <span class="nt">--extra-args</span> <span class="s1">'{"ignore_eos": true}'</span>
┏━━━━━━┳━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┓
┃      ┃      ┃      Avg ┃      P99 ┃    Gen. ┃      Avg ┃     P99 ┃      Avg ┃     P99 ┃   Success┃
┃Conc. ┃  RPS ┃  Lat.<span class="o">(</span>s<span class="o">)</span> ┃  Lat.<span class="o">(</span>s<span class="o">)</span> ┃  toks/s ┃  TTFT<span class="o">(</span>s<span class="o">)</span> ┃ TTFT<span class="o">(</span>s<span class="o">)</span> ┃  TPOT<span class="o">(</span>s<span class="o">)</span> ┃ TPOT<span class="o">(</span>s<span class="o">)</span> ┃      Rate┃
┡━━━━━━╇━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━┩
│    1 │ 0.16 │    6.150 │    9.323 │  166.50 │    0.059 │   0.068 │    0.006 │   0.009 │    100.0%│
│   10 │ 1.03 │    9.666 │   10.177 │ 1058.72 │    0.386 │   0.807 │    0.009 │   0.009 │    100.0%│
│   20 │ 1.29 │   13.762 │   15.793 │ 1316.59 │    0.528 │   1.476 │    0.013 │   0.014 │    100.0%│
│   50 │ 1.77 │   28.100 │   31.295 │ 1816.37 │    1.165 │   3.533 │    0.026 │   0.027 │    100.0%│
│  100 │ 1.76 │   50.314 │   83.056 │ 1805.55 │    7.330 │  28.528 │    0.042 │   0.074 │    100.0%│
└──────┴──────┴──────────┴──────────┴─────────┴──────────┴─────────┴──────────┴─────────┴──────────┘
</code></pre></div></div>

<p>发现：量化后，单用户 OTPS 提升 100%，但是最大 OTPS 提升较少。</p>

<h3 id="24-gguf-imatrix-量化">2.4 GGUF imatrix 量化</h3>

<p>GGUF 各种量化方法参考：https://huggingface.co/docs/hub/en/gguf</p>

<p>我们使用 imatrix 4bit 量化（类似于 GPTQ的方法）IQ4_XS</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git clone https://github.com/ggml-org/llama.cpp.git
<span class="c"># INSTALL CUDA TOOLKIT: https://developer.nvidia.com/cuda-toolkit-archive</span>
<span class="c"># 安装依赖库</span>
<span class="nb">sudo </span>apt-get <span class="nb">install </span>cmake curl libssl-dev libcurl4-openssl-dev
<span class="c"># 配置cuda 的路径，具体和你的CUDA版本有关</span>
<span class="nb">export </span><span class="nv">PATH</span><span class="o">=</span>/usr/local/cuda-12.6/bin<span class="k">${</span><span class="nv">PATH</span>:+:<span class="k">${</span><span class="nv">PATH</span><span class="k">}}</span>
<span class="nb">export </span><span class="nv">LD_LIBRARY_PATH</span><span class="o">=</span>/usr/local/cuda-12.6/lib64<span class="k">${</span><span class="nv">LD_LIBRARY_PATH</span>:+:<span class="k">${</span><span class="nv">LD_LIBRARY_PATH</span><span class="k">}}</span>
<span class="c"># 编辑 llama.cpp GPU 版本</span>
cmake <span class="nt">-B</span> build <span class="nt">-DGGML_CUDA</span><span class="o">=</span>ON
cmake <span class="nt">--build</span> build <span class="nt">--config</span> Release <span class="nt">-j16</span>
<span class="c"># 把模型下载到本地</span>
hf download <span class="s2">"Qwen/Qwen3-4B-Instruct-2507"</span> <span class="nt">--local-dir</span> <span class="s2">"Qwen3-4B-Instruct-2507"</span>
<span class="c"># 转换为 fp16 gguf 格式</span>
python llama.cpp/convert_hf_to_gguf.py <span class="s2">"Qwen3-4B-Instruct-2507"</span> <span class="nt">--outtype</span> f16 <span class="nt">--outfile</span> Qwen3-4B-Instruct-2507-f16.gguf
<span class="c"># 生成 imatrix.dat</span>
./llama.cpp/build/bin/llama-imatrix <span class="nt">-m</span> Qwen3-4B-Instruct-2507-f16.gguf <span class="nt">-f</span> calibration.txt <span class="nt">-ngl</span> 99 <span class="nt">--output-frequency</span> 10 <span class="nt">-o</span> imatrix.dat <span class="nt">--parse-special</span>
<span class="c"># 进行带校准量化</span>
./llama.cpp/build/bin/llama-quantize <span class="nt">--leave-output-tensor</span> <span class="nt">--imatrix</span> imatrix.dat Qwen3-4B-Instruct-2507-f16.gguf Qwen3-4B-Instruct-2507-iq4_xs.gguf IQ4_XS
<span class="c"># 无校准量化</span>
./llama.cpp/build/bin/llama-quantize <span class="nt">--leave-output-tensor</span> Qwen3-4B-Instruct-2507-f16.gguf Qwen3-4B-Instruct-2507-q4_k_m.gguf Q4_K_M
</code></pre></div></div>

<h4 id="gguf-量化效果评测">GGUF 量化效果评测</h4>

<p>评测模型在 wiki.test 数据集上的 PPL（困惑度），越低越好。</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># ppl</span>
./llama.cpp/scripts/get-wikitext-2.sh
./llama.cpp/build/bin/llama-perplexity <span class="nt">-m</span> Qwen3-4B-Instruct-2507-f16.gguf <span class="nt">-f</span> wikitext-2-raw/wiki.test.raw <span class="nt">-ngl</span> 99
PPL <span class="o">=</span> 10.5498 +/- 0.08436
./llama.cpp/build/bin/llama-perplexity <span class="nt">-m</span> Qwen3-4B-Instruct-2507-iq4_xs.gguf <span class="nt">-f</span> wikitext-2-raw/wiki.test.raw <span class="nt">-ngl</span> 99
PPL <span class="o">=</span> 10.7011 +/- 0.08542
./llama.cpp/build/bin/llama-perplexity <span class="nt">-m</span> Qwen3-4B-Instruct-2507-q4_k_m.gguf <span class="nt">-f</span> wikitext-2-raw/wiki.test.raw <span class="nt">-ngl</span> 99
PPL <span class="o">=</span> 10.7434 +/- 0.08562
</code></pre></div></div>

<p>可以看到 iq4_xs 不仅体积小，效果也较好</p>

<p>评测模型的真实推理效果。</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># 见下文，vllm 并发性能要好于 llama.cpp</span>
vllm serve ./Qwen3-4B-Instruct-2507-iq4_xs.gguf <span class="nt">--served-model-name</span> Qwen3-4B-Instruct-2507-iq4_xs <span class="nt">--max-model-len</span> 8192 <span class="nt">--port</span> 8080 <span class="nt">--tokenizer</span> Qwen3-4B-Instruct-2507

evalscope <span class="nb">eval</span> <span class="se">\</span>
 <span class="nt">--model</span> Qwen3-4B-Instruct-2507-iq4_xs <span class="se">\</span>
 <span class="nt">--api-url</span> http://127.0.0.1:8080/v1 <span class="se">\</span>
 <span class="nt">--api-key</span> EMPTY <span class="se">\</span>
 <span class="nt">--eval-type</span> openai_api <span class="se">\</span>
 <span class="nt">--datasets</span> math_500 ifeval iquiz <span class="se">\</span>
 <span class="nt">--eval-batch-size</span> 100

+-------------------------------+-----------+--------------------------+----------+-------+---------+---------+
| Model                         | Dataset   | Metric                   | Subset   |   Num |   Score | Cat.0   |
+<span class="o">===============================</span>+<span class="o">===========</span>+<span class="o">==========================</span>+<span class="o">==========</span>+<span class="o">=======</span>+<span class="o">=========</span>+<span class="o">=========</span>+
| Qwen3-4B-Instruct-2507-iq4_xs | ifeval    | mean_prompt_level_strict | default  |   541 |  0.8262 | default |
| Qwen3-4B-Instruct-2507-iq4_xs | ifeval    | mean_inst_level_strict   | default  |   541 |  0.8851 | default |
| Qwen3-4B-Instruct-2507-iq4_xs | iquiz     | mean_acc                 | OVERALL  |   120 |  0.5    | -       |
| Qwen3-4B-Instruct-2507-iq4_xs | math_500  | mean_acc                 | OVERALL  |   500 |  0.758  | -       |
+-------------------------------+-----------+--------------------------+----------+-------+---------+---------+
</code></pre></div></div>

<p>发现：比 GPTQ 量化效果略弱，但整体削弱较小。</p>

<h4 id="gguf-量化性能评测">GGUF 量化性能评测</h4>

<p>vllm + gguf iq4 推理。</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>vllm serve ./Qwen3-4B-Instruct-2507-iq4_xs.gguf <span class="nt">--served-model-name</span> Qwen3-4B-Instruct-2507-iq4_xs <span class="nt">--max-model-len</span> 8192 <span class="nt">--port</span> 8080 <span class="nt">--tokenizer</span> Qwen3-4B-Instruct-2507
evalscope perf <span class="se">\</span>
  <span class="nt">--parallel</span> 1 10 20 50 100 <span class="se">\</span>
  <span class="nt">--number</span> 10 30 50 100 200 <span class="se">\</span>
  <span class="nt">--model</span> Qwen3-4B-Instruct-2507-iq4_xs <span class="se">\</span>
  <span class="nt">--url</span> http://127.0.0.1:8080/v1/chat/completions <span class="se">\</span>
  <span class="nt">--api</span> openai <span class="se">\</span>
  <span class="nt">--dataset</span> random <span class="se">\</span>
  <span class="nt">--max-tokens</span> 1024 <span class="se">\</span>
  <span class="nt">--min-tokens</span> 1024 <span class="se">\</span>
  <span class="nt">--prefix-length</span> 0 <span class="se">\</span>
  <span class="nt">--min-prompt-length</span> 1024 <span class="se">\</span>
  <span class="nt">--max-prompt-length</span> 1024 <span class="se">\</span>
  <span class="nt">--tokenizer-path</span> Qwen3-4B-Instruct-2507/ <span class="se">\</span>
  <span class="nt">--extra-args</span> <span class="s1">'{"ignore_eos": true}'</span>

┏━━━━━━┳━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┓
┃      ┃      ┃      Avg ┃      P99 ┃    Gen. ┃      Avg ┃     P99 ┃      Avg ┃     P99 ┃   Success┃
┃Conc. ┃  RPS ┃  Lat.<span class="o">(</span>s<span class="o">)</span> ┃  Lat.<span class="o">(</span>s<span class="o">)</span> ┃  toks/s ┃  TTFT<span class="o">(</span>s<span class="o">)</span> ┃ TTFT<span class="o">(</span>s<span class="o">)</span> ┃  TPOT<span class="o">(</span>s<span class="o">)</span> ┃ TPOT<span class="o">(</span>s<span class="o">)</span> ┃      Rate┃
┡━━━━━━╇━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━┩
│    1 │ 0.17 │    5.884 │    5.945 │  174.02 │    0.044 │   0.087 │    0.006 │   0.006 │    100.0%│
│   10 │ 0.40 │   24.839 │   25.406 │  412.00 │    0.449 │   1.034 │    0.024 │   0.024 │    100.0%│
│   20 │ 0.66 │   25.413 │   26.805 │  677.62 │    0.658 │   1.838 │    0.024 │   0.025 │    100.0%│
│   50 │ 1.17 │   42.447 │   46.481 │ 1201.77 │    1.444 │   4.483 │    0.040 │   0.041 │    100.0%│
│  100 │ 1.20 │   72.823 │  118.206 │ 1225.47 │    8.692 │  37.972 │    0.063 │   0.106 │    100.0%│
└──────┴──────┴──────────┴──────────┴─────────┴──────────┴─────────┴──────────┴─────────┴──────────┘
</code></pre></div></div>

<p>llama.cpp + gguf  iq4 推理。</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># set max input tokens = 4096, max output tokens = 4096</span>
./llama.cpp/build/bin/llama-server <span class="nt">-m</span> Qwen3-4B-Instruct-2507-iq4_xs.gguf <span class="nt">-c</span> 4096 <span class="nt">-n</span> 4096 <span class="nt">-ngl</span> 99
<span class="c"># test</span>
curl <span class="nt">-X</span> POST http://127.0.0.1:8080/v1/chat/completions <span class="se">\</span>
  <span class="nt">-H</span> <span class="s2">"Content-Type: application/json"</span> <span class="se">\</span>
  <span class="nt">-d</span> <span class="s1">'{
    "model": "Qwen3-4B-Instruct-2507-iq4_xs",
    "messages": [
      {"role": "user", "content": "你好"}
    ], "stream": true
  }'</span>
<span class="c"># 注意首次执行一会ctrl+c，进行warmup</span>
evalscope perf <span class="se">\</span>
  <span class="nt">--parallel</span> 1 10 20 50 100 <span class="se">\</span>
  <span class="nt">--number</span> 10 30 50 100 200 <span class="se">\</span>
  <span class="nt">--model</span> Qwen3-4B-Instruct-2507-iq4_xs <span class="se">\</span>
  <span class="nt">--url</span> http://127.0.0.1:8080/v1/chat/completions <span class="se">\</span>
  <span class="nt">--api</span> openai <span class="se">\</span>
  <span class="nt">--dataset</span> random <span class="se">\</span>
  <span class="nt">--max-tokens</span> 1024 <span class="se">\</span>
  <span class="nt">--min-tokens</span> 1024 <span class="se">\</span>
  <span class="nt">--prefix-length</span> 0 <span class="se">\</span>
  <span class="nt">--min-prompt-length</span> 1024 <span class="se">\</span>
  <span class="nt">--max-prompt-length</span> 1024 <span class="se">\</span>
  <span class="nt">--tokenizer-path</span> Qwen3-4B-Instruct-2507 <span class="se">\</span>
  <span class="nt">--extra-args</span> <span class="s1">'{"ignore_eos": true}'</span>

┏━━━━━━┳━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┓
┃      ┃      ┃      Avg ┃      P99 ┃    Gen. ┃      Avg ┃     P99 ┃      Avg ┃     P99 ┃   Success┃
┃Conc. ┃  RPS ┃  Lat.<span class="o">(</span>s<span class="o">)</span> ┃  Lat.<span class="o">(</span>s<span class="o">)</span> ┃  toks/s ┃  TTFT<span class="o">(</span>s<span class="o">)</span> ┃ TTFT<span class="o">(</span>s<span class="o">)</span> ┃  TPOT<span class="o">(</span>s<span class="o">)</span> ┃ TPOT<span class="o">(</span>s<span class="o">)</span> ┃      Rate┃
┡━━━━━━╇━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━┩
│    1 │ 0.21 │    4.812 │    4.816 │  212.76 │    0.061 │   0.063 │    0.005 │   0.005 │    100.0%│
│   10 │ 0.20 │   41.531 │   48.982 │  209.89 │   36.711 │  44.152 │    0.005 │   0.005 │    100.0%│
│   20 │ 0.20 │   80.076 │   99.156 │  207.84 │   75.205 │  94.257 │    0.005 │   0.005 │    100.0%│
│   50 │ 0.20 │  189.758 │  251.990 │  204.79 │  184.814 │ 247.020 │    0.005 │   0.005 │    100.0%│
│  100 │ 0.20 │  378.942 │  504.018 │  204.04 │  373.980 │ 499.034 │    0.005 │   0.005 │    100.0%│
└──────┴──────┴──────────┴──────────┴─────────┴──────────┴─────────┴──────────┴─────────┴──────────┘
</code></pre></div></div>

<p>结论：看 OTPS 指标，llama.cpp 单用户性能最好，但是大并发性能下，vllm+GPTQ &gt; vllm+GGUF。</p>

<hr />

<blockquote>
  <p>原文发布于 <a href="https://github.com/ninehills/blog/issues/143">GitHub Issue #143</a><br />
创建于 2025-09-22T16:31:39Z，更新于 2025-09-23T09:07:10Z</p>
</blockquote>]]></content><author><name>ninehills</name></author><summary type="html"><![CDATA[LLM 量化实战：GPTQ 和 GGUF 量化的效果对比、推理性能实测和代码实现。]]></summary></entry><entry><title type="html">使用Coding Agent 作为通用智能体完成 DeepResearch 任务</title><link href="https://ninehills.tech/2025/09/16/141/" rel="alternate" type="text/html" title="使用Coding Agent 作为通用智能体完成 DeepResearch 任务" /><published>2025-09-16T00:00:00+00:00</published><updated>2025-09-16T00:00:00+00:00</updated><id>https://ninehills.tech/2025/09/16/141</id><content type="html" xml:base="https://ninehills.tech/2025/09/16/141/"><![CDATA[<p>CLI Agent 是文本模态 Agent 的天然形态，比如 Manus，其本质就是在 VM 执行的 CLI Agent。
在 VLLM 不成熟的今天，我们需要先实现文本模态的 Agent。</p>

<p>尝试用 Gemini CLI 实现 DeepReasearch 任务，复现 Prompt 如下。</p>

<p>效果：使用 gemini-2.5-flash 模型，相比于 Gemini  DR，效果要好得多。（但是目前的引用管理不太好）</p>

<div class="language-markdown highlighter-rouge"><div class="highlight"><pre class="highlight"><code>请严格按照深度研究步骤，产出如对应主题调研报告。需要广泛的搜集信息，包括使用中文和英文关键词搜索，搜索学术论文和新闻报告等。

<span class="gu">## 要求</span>
<span class="p">
-</span> 所有临时文件，保存本地目录。
<span class="p">-</span> 将所有的研究计划，以 Markdown TODO list 的方式保存在 TODO.md 文件中。

<span class="gu">## 研究主题</span>

针对 GraphRAG 主题，找到2025年的全部论文，深入读取论文内容，给出完整综述。

<span class="gu">## 深度研究步骤</span>

准备阶段：
（1）创建 TODO.md 文件，保存所有待办步骤到 TODO.md 中，每个任务完成后反思和更新计划。

第一阶段：信息搜集和研究大纲生成
（1）信息搜索：收集相关领域的信息，明确研究背景、细化通过研究想要达成的具体成果
（2）生成研究大纲，写入到 <span class="sb">`research_outline.md`</span> 文件

第二阶段：进行深度信息收集
（1）系统手机目标领域的历史数据和案例，将这些信息整理成标准化的内容，可选择用数据表格形态整理。关键是确保数据的完整性、准确性和时序性，为后续所有分析提供可靠的事实基础，数据收集必须覆盖足够的时间范围，包含所有相关的关键信息字段
（2）请广泛的进行信息收集，需要收集 100 条以上的参考文献。
（3）将所有的参考论文、网页等URL保存到 <span class="sb">`reference.md`</span> 文件中，使用Markdown表格存储，如果为PDF格式论文，将所有论文下载到本地（可以先生成URL列表后用 wget批量下载）。

第三阶段：深度分析与信息深度挖掘
（1）深度模式分析：基于收集到的数据，深入分析其中的新研究对象、关键模式、规律和趋势等。这包括频率统计、周期性变化、发展趋势等量化分析，目标是揭示隐藏在数据背后的内在逻辑和规律性特征。对于上一步中出现的新的重要概念或实体，需对该类需要探究的内容进行二次信息搜集。分析结果尽可能用统计数据和可视化图表来呈现。
（2）核心驱动因素提取：通过对模式的深度分析，需要识别出真正影响结果的核心驱动因素。这些因素需要按照影响力大小进行排序，并评估各自的权重。重点是找到那些具有决定性作用的关键变量，而不是表面的相关性因素。
（3）现实背景信息补强：针对已识别的核心驱动因素，我会收集当前相关的现实背景信息。这包括最新的政策变化、市场环境、技术发展、社会趋势等可能影响分析结果的现实因素。目标是将历史规律与当前实际情况相结合，确保分析的时效性和准确性。
（4）在这个阶段中，随时判断已有信息是否足够，应尽可能的收集更多的信息，让参考文献越多越好。

第四阶段：输出研究报告
（1）研究报告大纲生成：根据收集的全部信息，生成报告大纲（约10个章节），并写入文件 <span class="sb">`research_report_outline.md`</span>
（2）研究报告分章节生成：逐个章节编写报告内容，每个章节内容写到到文件 <span class="sb">`research_report_章节.md`</span>
（3）研究报告合并：使用shell命令将所有章节内容合并到文件 <span class="sb">`research_final_report.md`</span>。

<span class="gu">## 报告格式要求</span>
<span class="p">
1.</span> 总文本量不低于 50000 字，使用中文。
<span class="p">2.</span> 使用 Markdown格式。
<span class="p">3.</span> 必须使用 markdown表格、mermaid 图表的方式表达复杂概念和内容。
<span class="p">4.</span> 报告最后是专门的引用章节，有所有引用的参考文献，格式为 <span class="sb">`[1] 参考文献1`</span>
</code></pre></div></div>

<hr />

<blockquote>
  <p>原文发布于 <a href="https://github.com/ninehills/blog/issues/141">GitHub Issue #141</a><br />
创建于 2025-09-16T09:24:54Z，更新于 2025-09-16T09:26:09Z</p>
</blockquote>]]></content><author><name>ninehills</name></author><summary type="html"><![CDATA[使用 Coding Agent 作为通用智能体完成 DeepResearch 深度研究任务的实践。]]></summary></entry><entry><title type="html">不同硬件和推理引擎模型输出的精度差异</title><link href="https://ninehills.tech/2025/09/09/137/" rel="alternate" type="text/html" title="不同硬件和推理引擎模型输出的精度差异" /><published>2025-09-09T00:00:00+00:00</published><updated>2025-09-09T00:00:00+00:00</updated><id>https://ninehills.tech/2025/09/09/137</id><content type="html" xml:base="https://ninehills.tech/2025/09/09/137/"><![CDATA[<p>不同硬件（如NVIDIA GPU, 华为Ascend NPU）和不同推理框架（如PyTorch, vLLM, MindIE）上，对同一模型相同输入进行推理得到不同结果：</p>

<ol>
  <li>
    <p><strong>浮点数计算的非确定性</strong>
现代处理器为追求极致性能，广泛采用并行计算与融合运算（FMA），导致<strong>浮点运算顺序不固定</strong>
由于浮点数运算不满足严格的结合律 <code class="language-plaintext highlighter-rouge">(a+b)+c ≠ a+(b+c)</code>，不同的计算顺序会导致微小的舍入误差累积，最终造成结果差异。</p>
  </li>
  <li><strong>算子实现的差异</strong>
不同的硬件平台和推理框架拥有各自高度优化的算子库。
    <ul>
      <li><strong>硬件层面</strong>：NVIDIA GPU依赖cuBLAS/cuDNN，华为Ascend NPU依赖CANN。它们的底层数学实现、优化策略和精度处理存在差异。</li>
      <li><strong>框架层面</strong>：vLLM、MindIE等框架会实现自定义的高性能算子（如PagedAttention），其算法逻辑和数值稳定性可能与PyTorch的原生算子不同，从而引入计算路径上的差异。
        <ul>
          <li>即使数学公式相同，不同 kernel 的实现（如矩阵乘的分块大小、是否使用 shared memory、是否融合 layernorm）都会导致数值路径差异。</li>
        </ul>
      </li>
    </ul>
  </li>
  <li><strong>解码策略的敏感性</strong>
即使计算上的差异极其微小，解码过程也会将其放大。
    <ul>
      <li><strong>采样解码 (temperature &gt; 0)</strong>：微小的<code class="language-plaintext highlighter-rouge">logits</code>差异会改变整体概率分布，导致采样到完全不同的token，从而放大不确定性。</li>
      <li><strong>贪心解码 (temperature = 0)</strong>：即使使用贪心解码，当两个token的<code class="language-plaintext highlighter-rouge">logits</code>值非常接近时，微小的计算误差足以改变它们的排序，使得<code class="language-plaintext highlighter-rouge">argmax</code>操作选择不同的token。
        <ul>
          <li>示例：logits_A = 10.00, logits_B = 10.01 → softmax 后 P(A)≈49.9%, P(B)≈50.1% → argmax 选 B；若误差使 logits_A=10.012，则 argmax 可能选 A。</li>
        </ul>
      </li>
      <li>一旦在某个生成步骤选择了不同的token，它将作为后续步骤的输入，引发“蝴蝶效应”，导致最终生成的序列产生巨大差异。</li>
    </ul>
  </li>
</ol>

<p>调试办法：</p>
<ol>
  <li>相同模型在不同环境的表现有极大的差别如何确认？
    <ol>
      <li>使用相同的模型权重和模型精度，不使用量化或使用相同的量化权重</li>
      <li>使用贪心解码（temperature = 0 ）</li>
      <li>使用固定的随机种子</li>
      <li>关闭 prefix-cache、NTP 等可能影响推理精度的优化选项</li>
      <li>【极大影响性能】禁用并行计算非确定性：PyTorch 中设置 <code class="language-plaintext highlighter-rouge">torch.use_deterministic_algorithms(True)</code>。</li>
      <li>使用相同的 Prompt，并<strong>确保 Chat Template 渲染后的 Tokens 完全匹配</strong></li>
      <li>开启输出 logits 分布（https://platform.openai.com/docs/api-reference/chat/create#chat_create-logprobs）
        <ol>
          <li>logprobs = true</li>
          <li>Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the content of message.</li>
        </ol>
      </li>
      <li>检查 Token 输出的 logprobs 的差异</li>
    </ol>
  </li>
  <li>如何进行算子级差异检查？
    <ol>
      <li>修改模型前向函数，<strong>逐层保存隐藏状态</strong>（hidden states）；</li>
      <li>在两个平台分别运行，保存每层输出张量；</li>
      <li>计算每层输出的<strong>相对误差</strong>或<strong>余弦相似度</strong>：
        <ul>
          <li>L2 相对误差：<code class="language-plaintext highlighter-rouge">||A - B||₂ / ||A||₂</code></li>
          <li>余弦相似度：<code class="language-plaintext highlighter-rouge">cos_sim = (A·B) / (||A|| * ||B||)</code></li>
        </ul>
      </li>
      <li>定位误差突增的层（如相似度从 0.9999 骤降至 0.99），然后具体定位问题算子所在。</li>
    </ol>
  </li>
  <li>如何对模型进行 Benchmark 确定统计学意义的差异评估？
    <ol>
      <li>使用 evalscope/lm-eval/opencompass 等评测框架在常见的评测数据集上从统计学角度分析精度差异</li>
      <li>推荐用 gsm8k、ceval、mmlu_redux、livebench</li>
      <li>理论来说，应该进行多轮评测后，从统计学角度判断差异是否显著。</li>
      <li>实际来说，相同模型的评测分数分布应该在相对 3% - 5% 以内就可以接受。</li>
    </ol>
  </li>
</ol>

<p>解决办法：</p>
<ol>
  <li>使用贪心解码（仅验证问题的时候使用，多数场景不推荐使用贪心解码）</li>
  <li>确保使用相同的模型精度（比如 bfloat16和float16 就有较大区别）</li>
  <li>更换硬件、推理框架后，重新进行提示词调优。</li>
</ol>

<p>延伸问题：</p>
<ol>
  <li>量化后的模型一定就比量化前的模型效果差么？
    <ol>
      <li>量化也可以视为一种误差，加入误差有时反而会让模型在某些场景下的效果变好。</li>
      <li>这是因为量化引入的噪声有时可以视为一种正则化的作用，类似于 Dropout，可以打破模型的一些过拟合特征（一个FP16的权重0.800001和0.800002在量化后可能都变成了同一个INT8值102，对精度的“扰动”打断了模型学到的一些“脆弱”或“过度拟合”的特征。）</li>
    </ol>
  </li>
  <li>大模型是天然这么不稳定的么？
    <ol>
      <li>对，大模型本身就是不稳定输出的，而且实践中很少使用贪心解码，也就是 temperature 设置为 &gt; 0，本身有极大的输出随机性。</li>
      <li>这也代表着所有的评测结果仅有统计学意义，就和相同的卷子人不会考相同分数一样。</li>
    </ol>
  </li>
  <li>效果不一致是否一定是硬件或算子差异？
    <ol>
      <li>不一定，很多时候是推理框架引入的 Bug，需要具体问题具体定位。</li>
    </ol>
  </li>
</ol>

<hr />

<blockquote>
  <p>原文发布于 <a href="https://github.com/ninehills/blog/issues/137">GitHub Issue #137</a><br />
创建于 2025-09-09T02:39:09Z，更新于 2025-09-10T19:57:19Z</p>
</blockquote>]]></content><author><name>ninehills</name></author><summary type="html"><![CDATA[不同硬件（GPU/NPU）和推理框架（vLLM/MindIE）下模型输出精度差异的根因分析。]]></summary></entry><entry><title type="html">免费 GPU 或廉价算力</title><link href="https://ninehills.tech/2025/09/03/133/" rel="alternate" type="text/html" title="免费 GPU 或廉价算力" /><published>2025-09-03T00:00:00+00:00</published><updated>2025-09-03T00:00:00+00:00</updated><id>https://ninehills.tech/2025/09/03/133</id><content type="html" xml:base="https://ninehills.tech/2025/09/03/133/"><![CDATA[<h1 id="免费-gpu-或廉价算力">免费 GPU 或廉价算力</h1>

<h2 id="1-显卡需求和推荐模型">1. 显卡需求和推荐模型</h2>

<p>使用 int4 + QLora 训练（效果并不会比Full-finetuning差多少，lora rank设置较大且应用到所有层）
8K 上下文时，显存16GB的显卡则可以训练 20B 以下模型，显存24GB的显卡则可以训练 32B（含）以下模型。</p>

<p>推荐微调 1-7B 模型。推荐性价比显卡：4090，计算能力和显存带宽都足够好，比L40等商业卡还好用。</p>

<h2 id="2-服务商">2. 服务商</h2>

<ul>
  <li>https://colab.research.google.com/
    <ul>
      <li>【需翻墙】</li>
      <li>免费提供 T4 等显卡，显存16GB</li>
    </ul>
  </li>
  <li>https://modelscope.cn/
    <ul>
      <li>新用户赠送 100h GPU 时间（16G、24G显卡）</li>
    </ul>
  </li>
  <li>https://aistudio.baidu.com/
    <ul>
      <li>每日签到可以领取免费 GPU 时间，但是限制框架只能使用 Paddle</li>
    </ul>
  </li>
  <li>https://console.ebcloud.com/
    <ul>
      <li>注册送 50元，4090显卡 2元/小时</li>
    </ul>
  </li>
  <li>https://www.autodl.com/
    <ul>
      <li>显卡型号众多（适合测试模型在不同显卡上的性能），4090 2-3元/小时</li>
    </ul>
  </li>
  <li>https://www.suanlix.cn/
    <ul>
      <li>4090 2-3 元/小时</li>
      <li>有香港节点，下载模型和安装环境比较方便</li>
    </ul>
  </li>
  <li>https://www.runpod.io/
    <ul>
      <li>国外较大服务商，下载模型和安装环境比较方便</li>
      <li>4090 折约 4元/小时</li>
    </ul>
  </li>
</ul>

<h2 id="3-其他">3. 其他</h2>

<p>建议开通对象存储服务（百度云、阿里云等），将打包好的 Docker 训练镜像、训练结果、数据集、工作目录等持久化到对象存储中。</p>

<p>国内节点配置要点：</p>

<ul>
  <li>pip源：https://mirrors.tuna.tsinghua.edu.cn/help/pypi/</li>
  <li>conda源：https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/</li>
  <li>Huggingface 代理：https://hf-mirror.com/</li>
</ul>

<hr />

<blockquote>
  <p>原文发布于 <a href="https://github.com/ninehills/blog/issues/133">GitHub Issue #133</a><br />
创建于 2025-09-03T14:00:33Z，更新于 2025-09-04T10:10:26Z</p>
</blockquote>]]></content><author><name>ninehills</name></author><summary type="html"><![CDATA[免费和廉价 GPU 算力资源汇总，包括 Google Colab、ModelScope 等平台的比较。]]></summary></entry><entry><title type="html">大语言模型高质量数据集汇总</title><link href="https://ninehills.tech/2025/07/10/129/" rel="alternate" type="text/html" title="大语言模型高质量数据集汇总" /><published>2025-07-10T00:00:00+00:00</published><updated>2025-07-10T00:00:00+00:00</updated><id>https://ninehills.tech/2025/07/10/129</id><content type="html" xml:base="https://ninehills.tech/2025/07/10/129/"><![CDATA[<h1 id="大语言模型高质量数据集汇总20258-更新">大语言模型高质量数据集汇总（2025.8 更新）</h1>

<blockquote>
  <p>注意：SFT数据集尤其是比较老的数据集质量其实低下，用 DeepSeek 等top模型重新回答下提问效果可能更好。</p>
</blockquote>

<h2 id="预训练数据集">预训练数据集</h2>

<table>
  <thead>
    <tr>
      <th>高质量数据集（有中文）</th>
      <th>大小</th>
      <th>特点</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>[IndustryCorpus2](https://huggingface.co/datasets/BAAI/IndustryCorpus2)</td>
      <td>1TB Chinese / 2.2TB English</td>
      <td>进行行业分类（31个行业），并对数据质量评级。</td>
    </tr>
    <tr>
      <td>[Fineweb-Edu-Chinese-V2.1](https://huggingface.co/datasets/opencsg/Fineweb-Edu-Chinese-V2.1)</td>
      <td>=1.5TBtokens</td>
      <td>有4.6B Tokens 高质量教育语料</td>
    </tr>
    <tr>
      <td>[m-a-p/Matrix](https://huggingface.co/datasets/m-a-p/Matrix)</td>
      <td>4.69T tokens</td>
      <td>训练 MAP-Neo 模型的预训练数据集</td>
    </tr>
    <tr>
      <td>[Ultra-FineWeb](https://huggingface.co/datasets/openbmb/Ultra-FineWeb)</td>
      <td>en 1T tokens / zh 120B tokens</td>
      <td>最新的，过滤的更好的数据集</td>
    </tr>
    <tr>
      <td>[opencsg/chinese-cosmopedia](https://huggingface.co/datasets/opencsg/chinese-cosmopedia)</td>
      <td>zh 60B tokens</td>
      <td>参考 CosMopedia 创建的中文合成预训练数据集</td>
    </tr>
  </tbody>
</table>

<p><strong>数据处理工具</strong>：</p>
<ul>
  <li>https://github.com/huggingface/datatrove</li>
  <li>https://github.com/modelscope/data-juicer</li>
  <li>https://github.com/multimodal-art-projection/MAP-NEO/tree/main/Matrix</li>
  <li>https://github.com/OpenDCAI/DataFlow</li>
</ul>

<h2 id="sft-数据集">SFT 数据集</h2>

<p>| SFT 数据集                                                                                                                 | 大小   | 语言       | 特点                             |
| ———————————————————————————————————————– | —- | ——– | —————————— |
| [m-a-p/neo_sft_phase2](https://huggingface.co/datasets/m-a-p/neo_sft_phase2)                                            | 109k | 中英       | MAP-Neo SFT 阶段2 Chat 数据，质量不错。  |
| [OpenCoder-LLM/opc-sft-stage1](https://huggingface.co/datasets/OpenCoder-LLM/opc-sft-stage1)                            | 3.2M | 中英（中文较少） | 从多个数据集中过滤和合成而来，有通用指令，更关注代码类数据。 |
| [OpenCoder-LLM/opc-sft-stage2](https://huggingface.co/datasets/OpenCoder-LLM/opc-sft-stage2)                            | 436k | 英        | 高质量的代码类数据。                     |
| [BAAI/Infinity-Instruct](https://huggingface.co/datasets/BAAI/Infinity-Instruct)                                        | 7M   | 中英（中文较少） | 多个尺寸的指令和对话数据。                  |
| [hfl/ruozhiba_gpt4](https://huggingface.co/datasets/hfl/ruozhiba_gpt4)                                                  | 4.9k | 中        | 著名的弱智吧+GPT4回答，对模型的能力有提升。       |
| [Mxode/Chinese-Instruct](https://huggingface.co/datasets/Mxode/Chinese-Instruct)                                        | 485k | 中        | 从多个数据集中筛选的中文指令数据集，价值较高。        |
| [SmolLM Instruct Datasets](https://huggingface.co/collections/HuggingFaceTB/instruct-datasets-66c12756198f9d79f2a60550) | -    | 英        | 多个开源数据集。其中自我认知部分值得参考。          |
| [Magpie-Qwen2-Pro-200K-Chinese](https://huggingface.co/datasets/Magpie-Align/Magpie-Qwen2-Pro-200K-Chinese)             | 200k | 中        | 使用 MagPie 从 Qwen2-72B 中提取的指令集。 |
| [lenML/longwriter-6k-filtered](https://huggingface.co/datasets/lenML/longwriter-6k-filtered)                            | 666  | 英        | 长文本输出（写作）                      |
| [THUDM/LongAlign-10k](https://huggingface.co/datasets/THUDM/LongAlign-10k)                                              | 10k  | 中英       | 长文本输入                          |
| [opencsg/smoltalk-chinese](https://huggingface.co/datasets/opencsg/smoltalk-chinese)                                    | 700k | 中        | 参考 SmolTalk 数据集创建的中文数据集        |</p>
<ul>
  <li>Yulan的<a href="https://docs.google.com/spreadsheets/d/1YP8-loVUxgxo36UEpOwflR3GRHLieBnLlCy8g10g8RU/edit?gid=0#gid=0">数据 Recipe</a> 不错，详细说明了其数据来源，可参考。</li>
</ul>

<h2 id="偏好数据集">偏好数据集</h2>

<table>
  <thead>
    <tr>
      <th>偏好数据集</th>
      <th>大小</th>
      <th>语言</th>
      <th>特点</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>[llamafactory/DPO-En-Zh-20k](https://huggingface.co/datasets/llamafactory/DPO-En-Zh-20k)</td>
      <td>20k</td>
      <td>中英</td>
      <td>多个来源整理，质量较高，中英各10k</td>
    </tr>
    <tr>
      <td>[unalignment-toxic-dpo-v0.2-zh_cn](https://huggingface.co/datasets/tastypear/unalignment-toxic-dpo-v0.2-zh_cn)</td>
      <td>541</td>
      <td>中</td>
      <td>去除模型安全逻辑</td>
    </tr>
    <tr>
      <td>[ultrafeedback_binarized](https://huggingface.co/datasets/HuggingFaceH4/ultrafeedback_binarized)</td>
      <td>187k</td>
      <td>英</td>
      <td>将 UltraFeedback改成二元偏好的数据集</td>
    </tr>
    <tr>
      <td>[opencsg/UltraFeedback-chinese](https://huggingface.co/datasets/opencsg/UltraFeedback-chinese)</td>
      <td>58k</td>
      <td>中</td>
      <td>多个中文资源库中收集了约58k条中文指令，使用DeepSeek V3 评分</td>
    </tr>
  </tbody>
</table>

<h2 id="推理数据集">推理数据集</h2>

<table>
  <thead>
    <tr>
      <th>推理数据集</th>
      <th>类型</th>
      <th>大小</th>
      <th>语言</th>
      <th>特点</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>[m-a-p/COIG-Writer](https://huggingface.co/datasets/m-a-p/COIG-Writer)</td>
      <td>SFT</td>
      <td>914</td>
      <td>中</td>
      <td>高质量中文创作与思考过程蒸馏数据集</td>
    </tr>
    <tr>
      <td>[INTELLECT-2-RL-Dataset](https://huggingface.co/datasets/PrimeIntellect/INTELLECT-2-RL-Dataset)</td>
      <td>RL</td>
      <td>285k</td>
      <td>英</td>
      <td>RL math/code 数据集带ground_truth</td>
    </tr>
    <tr>
      <td>[open-thoughts/OpenThoughts3-1.2M](https://huggingface.co/datasets/open-thoughts/OpenThoughts3-1.2M)</td>
      <td>SFT</td>
      <td>1M</td>
      <td>英</td>
      <td>DeepSeek 蒸馏出的大量数据</td>
    </tr>
    <tr>
      <td>[Chinese-DeepSeek-R1-Distill-data-110k](https://huggingface.co/datasets/Congliu/Chinese-DeepSeek-R1-Distill-data-110k)</td>
      <td>SFT</td>
      <td>110k</td>
      <td>中</td>
      <td>中文的 DeepSeek 蒸馏推理数据集</td>
    </tr>
  </tbody>
</table>

<h2 id="评测数据集">评测数据集</h2>

<blockquote>
  <p>根据 DeepSeek V3、Qwen3 等最新模型的评测数据集调整而来，选取最新、最流行、最具有代表性的评测数据集。</p>
</blockquote>

<table>
  <thead>
    <tr>
      <th>评测数据集</th>
      <th>类型</th>
      <th>大小</th>
      <th>语言</th>
      <th>特点</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>LiveBench</td>
      <td>综合（偏数学和代码）</td>
      <td> </td>
      <td>英</td>
      <td>定时更新的综合评测集，质量较高</td>
    </tr>
    <tr>
      <td>[AlignBench](https://github.com/THUDM/AlignBench) v1.1</td>
      <td>多轮对话</td>
      <td>683</td>
      <td>中</td>
      <td>中文对齐评测集，需要LLM作为裁判</td>
    </tr>
    <tr>
      <td>IFEval</td>
      <td>指令遵循</td>
      <td> </td>
      <td>英</td>
      <td>自动打分</td>
    </tr>
    <tr>
      <td>大海捞针</td>
      <td>长上下文</td>
      <td> </td>
      <td>英</td>
      <td>通过插入针的方法评测长上下文能力</td>
    </tr>
    <tr>
      <td>Arena-Hard</td>
      <td>多轮对话</td>
      <td> </td>
      <td>英</td>
      <td>Arena 中比较难的问题，需要 LLM 作为裁判</td>
    </tr>
    <tr>
      <td>BFCL v3</td>
      <td>函数调用</td>
      <td> </td>
      <td>英</td>
      <td>比较全面的函数调用评测集</td>
    </tr>
    <tr>
      <td>MMLU-Redux</td>
      <td>综合（世界知识）</td>
      <td> </td>
      <td>英</td>
      <td>MMLU的增强版本</td>
    </tr>
    <tr>
      <td>GPQA-Diamond</td>
      <td>综合（世界知识、复杂推理）</td>
      <td> </td>
      <td>英</td>
      <td>GPQA 中比较难的问题（博士级别）</td>
    </tr>
    <tr>
      <td>AIME’24</td>
      <td>数学推理</td>
      <td> </td>
      <td>英</td>
      <td>2024年的AIME数据集</td>
    </tr>
    <tr>
      <td>LiveCodeBench v5</td>
      <td>代码生成</td>
      <td> </td>
      <td>英</td>
      <td>定时更新的代码生成评测集</td>
    </tr>
    <tr>
      <td>C-Eval</td>
      <td>综合（世界知识）</td>
      <td> </td>
      <td>中</td>
      <td>中文场景下的综合评测集，目前模型多过拟合。</td>
    </tr>
    <tr>
      <td>CMMLU</td>
      <td>综合（世界知识）</td>
      <td> </td>
      <td>中</td>
      <td>中文场景下的综合评测集，目前模型多过拟合。</td>
    </tr>
    <tr>
      <td>MATH-500</td>
      <td>数学推理</td>
      <td> </td>
      <td>英</td>
      <td>OpenAI 的MATH数据集</td>
    </tr>
    <tr>
      <td>AIME’25</td>
      <td>数学推理</td>
      <td> </td>
      <td>英</td>
      <td>2025年的AIME数据</td>
    </tr>
    <tr>
      <td>RULER</td>
      <td>长上下文</td>
      <td> </td>
      <td>英</td>
      <td>评测模型上上下文的能力</td>
    </tr>
  </tbody>
</table>

<hr />

<blockquote>
  <p>原文发布于 <a href="https://github.com/ninehills/blog/issues/129">GitHub Issue #129</a><br />
创建于 2025-07-10T00:59:54Z，更新于 2025-12-06T17:12:29Z</p>
</blockquote>]]></content><author><name>ninehills</name></author><summary type="html"><![CDATA[大语言模型高质量数据集汇总，涵盖预训练、SFT 和偏好对齐各阶段的数据资源。]]></summary></entry><entry><title type="html">AI Tech Blog</title><link href="https://ninehills.tech/2025/07/08/128/" rel="alternate" type="text/html" title="AI Tech Blog" /><published>2025-07-08T00:00:00+00:00</published><updated>2025-07-08T00:00:00+00:00</updated><id>https://ninehills.tech/2025/07/08/128</id><content type="html" xml:base="https://ninehills.tech/2025/07/08/128/"><![CDATA[<p>AI Tech Blog</p>

<ul>
  <li><a href="https://eugeneyan.com/">Eugene Yan</a> ：大模型和应用的内容</li>
  <li>GPU Mode：GPU、模型推理和训练工程架构和算法 https://youtube.com/@gpumode?si=9BBmi4OwXDLwyWCI</li>
  <li>
    <table>
      <tbody>
        <tr>
          <td>[Simon Willison’s Newsletter</td>
          <td>Substack](https://simonw.substack.com/)</td>
        </tr>
      </tbody>
    </table>
  </li>
  <li>https://magazine.sebastianraschka.com/    《Build a Large Language Model (From Scratch)》作者，文章质量满分，基本分为两类：对大语言模型的某个技术方向做综述以及前沿技术解读。</li>
  <li>https://twitter.com/karpathy 大名鼎鼎，输出的质量可以说是天花板</li>
  <li><a href="https://www.philschmid.de/">Philschmid </a></li>
  <li>https://lilianweng.github.io/</li>
  <li>https://hamel.dev/</li>
</ul>

<hr />

<blockquote>
  <p>原文发布于 <a href="https://github.com/ninehills/blog/issues/128">GitHub Issue #128</a><br />
创建于 2025-07-08T00:42:09Z，更新于 2026-02-28T06:34:16Z</p>
</blockquote>]]></content><author><name>ninehills</name></author><summary type="html"><![CDATA[AI Tech Blog 建站和内容规划，面向中文读者的 AI 技术博客站点设计。]]></summary></entry></feed>