diff --git a/基于AI Agent开发范式的国产GPU大模型推理算子库优化/FlashInfer Benchmark实战:从性能基线到XPU-OJ冒烟提交.md b/基于AI Agent开发范式的国产GPU大模型推理算子库优化/FlashInfer Benchmark实战:从性能基线到XPU-OJ冒烟提交.md index 54b1c60..bfdc174 100644 --- a/基于AI Agent开发范式的国产GPU大模型推理算子库优化/FlashInfer Benchmark实战:从性能基线到XPU-OJ冒烟提交.md +++ b/基于AI Agent开发范式的国产GPU大模型推理算子库优化/FlashInfer Benchmark实战:从性能基线到XPU-OJ冒烟提交.md @@ -67,7 +67,7 @@ #### 4.1.1 获取算力代金券 -[点击获取算力代金券](https://developer.metax-tech.com/activities/6),首次登录需要使用邮箱或者手机号进行注册。登录成功后提交申请获得兑换码。 +[*点击获取算力代金券*](https://developer.metax-tech.com/activities/6),首次登录需要使用邮箱或者手机号进行注册。登录成功后提交申请获得兑换码。 ![apply](https://origin.picgo.net/2026/06/23/Screenshot_23-6-2026_161623_developer.metax-tech.com18419e10315b3d89.jpeg) @@ -75,7 +75,7 @@ 使用兑换码兑换 GPU 租用余额: -访问[模力方舟官网](https://ai.gitee.com/),在左侧边栏进入 “费用中心”,点击右上角 “兑换” 使用兑换码兑换代金券; +访问 [*模力方舟官网*](https://ai.gitee.com/),在左侧边栏进入 “费用中心”,点击右上角 “兑换” 使用兑换码兑换代金券; ![quote](https://origin.picgo.net/2026/06/23/-2026-06-23-1515027374ed9083ad0aea.png) @@ -84,7 +84,7 @@ 1. 左侧边栏进入 “算力容器”,点击右上角 “租用算力”,在新打开页面中的筛选选项中选择 “沐曦”,选择可租的 GPU 点击 “立即租用”。建议优先选择 16GB / 32GB 显存; - ![Weixin-Image_20260617180029](https://origin.picgo.net/2026/06/17/Weixin-Image_20260617180029_15_100c1e1fecb298bac54.png) + ![rent](https://origin.picgo.net/2026/06/17/Weixin-Image_20260617180029_15_100c1e1fecb298bac54.png) 2. 进入 “创建实例” 页面,确认计费方式为 “按量收费”,预装镜像选择:基础镜像 - **PyTorch-Agent / 2.8.0 / Python 3.12 / maca 3.7.2.1**,点击下一步; @@ -126,7 +126,7 @@ ![tools](https://origin.picgo.net/2026/06/23/-2026-06-23-1554030c167f9883fb1d79.png) - > 此部分内容以教程 [模力方舟快速使用SOP](https://www.gitlink.org.cn/metax-maca/op_optimization/tree/master/%E6%A8%A1%E5%8A%9B%E6%96%B9%E8%88%9F%E5%BF%AB%E9%80%9F%E4%BD%BF%E7%94%A8SOP.md) 为准 + 此部分内容可参考教程:[*模力方舟快速使用SOP*](../模力方舟快速使用SOP.md) #### 4.1.4 深度学习环境配置 @@ -161,7 +161,7 @@ which mxcc && mxcc --version || echo "mxcc 未找到,请确认 MACA 工具链 | 问题 | 解决方法 | | --- | --- | -| `mxcc: command not found` | MACA 工具链未安装或 `PATH` 未配置,检查镜像是否预装或参考 [模力方舟快速使用SOP](https://www.gitlink.org.cn/metax-maca/op_optimization) | +| `mxcc: command not found` | MACA 工具链未安装或 `PATH` 未配置,检查镜像是否预装或参考 [*模力方舟快速使用SOP*](../模力方舟快速使用SOP.md) | ### 4.2 工具准备 @@ -171,7 +171,7 @@ which mxcc && mxcc --version || echo "mxcc 未找到,请确认 MACA 工具链 - 已确认 Agent 可以正常调用模型。 -配置过程可参考 [模力方舟Agent部署准备教程](https://www.gitlink.org.cn/metax-maca/op_optimization/tree/master/%E5%9F%BA%E4%BA%8EAI%20Agent%E5%BC%80%E5%8F%91%E8%8C%83%E5%BC%8F%E7%9A%84%E5%9B%BD%E4%BA%A7GPU%E5%A4%A7%E6%A8%A1%E5%9E%8B%E6%8E%A8%E7%90%86%E7%AE%97%E5%AD%90%E5%BA%93%E4%BC%98%E5%8C%96%2F%E6%A8%A1%E5%8A%9B%E6%96%B9%E8%88%9FAgent%E9%83%A8%E7%BD%B2%E5%87%86%E5%A4%87%E6%95%99%E7%A8%8B.md)。 +配置过程可参考 [*模力方舟Agent部署准备教程*](模力方舟Agent部署准备教程.md)。 **以配置 OpenCode 为例** @@ -183,7 +183,7 @@ curl -fsSL https://opencode.ai/install | bash opencode ``` -后续配置教程可参考 [OpenCode 官方文档](https://opencode.ai/docs/)。 +后续配置教程可参考 [*OpenCode 官方文档*](https://opencode.ai/docs/)。 ### 4.3 代码准备 @@ -194,7 +194,7 @@ opencode - 已获取测试脚本和 Benchmark 脚本。 -> 具体操作可见章节 [6.1 在赛事镜像中运行 FlashInfer Benchmark](#run-flashinfer-bench) +> 具体操作可见章节 [*6.1 在赛事镜像中运行 FlashInfer Benchmark*](#run-flashinfer-bench) ### 4.4 账号准备 @@ -239,7 +239,7 @@ XPU-OJ 账号由组委会统一发放,参赛者无需自行注册。 ### 5.3 开源仓库参考 -[GitHub - MetaX-MACA/McFlashInfer](https://github.com/MetaX-MACA/McFlashInfer) +[*GitHub - MetaX-MACA/McFlashInfer*](https://github.com/MetaX-MACA/McFlashInfer) > 链接内容可供用于学习 API、算子实现思路、benchmark 方法和优化策略。选手仍需根据 XPU-OJ 题包接口**自行实现**可提交的 `run_kernel(...)` @@ -256,7 +256,7 @@ XPU-OJ 账号由组委会统一发放,参赛者无需自行注册。 **操作:** 进入 Terminal 检查 GPU、Python、编译工具和依赖版本。 -![giteeai 实例 12](https://origin.picgo.net/2026/06/04/giteeai--12c1772b12867f6be0.png) +![terminal](https://origin.picgo.net/2026/06/04/giteeai--12c1772b12867f6be0.png) **命令示例:** @@ -281,21 +281,21 @@ pip install pandas - `mx-smi` 显示沐曦 GPU 信息 - ![](https://origin.picgo.net/2026/06/18/-2026-06-18-164201---f51bf784081acbc6.png) + ![mx-smi-2](https://origin.picgo.net/2026/06/18/-2026-06-18-164201---f51bf784081acbc6.png) - Python 环境正常 - ![](https://origin.picgo.net/2026/06/18/-2026-06-18-164201----26f188cca92241bd2.png) + ![python](https://origin.picgo.net/2026/06/18/-2026-06-18-164201----26f188cca92241bd2.png) - `torch.cuda.is_available()` 返回 `True` - ![](https://origin.picgo.net/2026/06/18/-2026-06-18-164201----360b71aedf7b90b21.png) + ![torch](https://origin.picgo.net/2026/06/18/-2026-06-18-164201----360b71aedf7b90b21.png) - 所有依赖版本符合要求 - ![](https://origin.picgo.net/2026/06/18/-2026-06-18-164201----4ffb68bf433f690a8.png) + ![dependence](https://origin.picgo.net/2026/06/18/-2026-06-18-164201----4ffb68bf433f690a8.png) - ![](https://origin.picgo.net/2026/06/18/-2026-06-18-164201----5fed48dda82423727.png) + ![dependance-2](https://origin.picgo.net/2026/06/18/-2026-06-18-164201----5fed48dda82423727.png) **常见问题:** @@ -308,7 +308,7 @@ pip install pandas #### Step 2:进入项目目录 -**目标:** 进入本模块所需的源码目录 [benchmark](https://www.gitlink.org.cn/metax-maca/op_optimization/tree/master/%E5%9F%BA%E4%BA%8EAI%20Agent%E5%BC%80%E5%8F%91%E8%8C%83%E5%BC%8F%E7%9A%84%E5%9B%BD%E4%BA%A7GPU%E5%A4%A7%E6%A8%A1%E5%9E%8B%E6%8E%A8%E7%90%86%E7%AE%97%E5%AD%90%E5%BA%93%E4%BC%98%E5%8C%96%2Foperator_task_package%2Fflashinfer_task_package%2Fbenchmark)。 +**目标:** 进入本模块所需的源码目录 [*benchmark*](https://gitlink.org.cn/metax-maca/op_optimization/tree/master/%E5%9F%BA%E4%BA%8EAI%20Agent%E5%BC%80%E5%8F%91%E8%8C%83%E5%BC%8F%E7%9A%84%E5%9B%BD%E4%BA%A7GPU%E5%A4%A7%E6%A8%A1%E5%9E%8B%E6%8E%A8%E7%90%86%E7%AE%97%E5%AD%90%E5%BA%93%E4%BC%98%E5%8C%96%2Foperator_task_package%2Fflashinfer_task_package%2Fbenchmark)。 1. 克隆代码仓库 @@ -367,7 +367,7 @@ python -c "from bench_common import setup_workspace, get_csv_path; print('脚本 **操作:** 运行基准测试脚本 (以 Ragged Prefill Benchmark 为例),读取生成的 CSV 结果文件。 -> 每个算子优化题目都对应一个 Benchmark(见 [5.2 查看性能基线](#benchmark-baseline)) +> 每个算子优化题目都对应一个 Benchmark(见 [*5.2 查看性能基线*](#benchmark-baseline)) **运行算子 Benchmark(以 Ragged Prefill 为例):** @@ -480,7 +480,7 @@ FlashInfer 方向包含 **4 个可选算子题目**,每个对应独立的 benc **每个子题的接口参数、数据范围和精度要求以对应 XPU-OJ 题包为准。** 下文以题目 **20001 Flashinfer Ragged Prefill** 为例演示从 benchmark 到 XPU-OJ 提交的完整流程。 -题目的更多信息可参考 [20001 Flashinfer Ragged Prefill 题目说明](https://www.gitlink.org.cn/metax-maca/op_optimization/tree/master/%E5%9F%BA%E4%BA%8EAI%20Agent%E5%BC%80%E5%8F%91%E8%8C%83%E5%BC%8F%E7%9A%84%E5%9B%BD%E4%BA%A7GPU%E5%A4%A7%E6%A8%A1%E5%9E%8B%E6%8E%A8%E7%90%86%E7%AE%97%E5%AD%90%E5%BA%93%E4%BC%98%E5%8C%96%2Foperator_task_package%2Fflashinfer_task_package%2Fxpuoj_problem%2Fproblem_20001%2Fzh_CN)。 +题目的更多信息可参考 [*20001 Flashinfer Ragged Prefill 题目说明*](https://gitlink.org.cn/metax-maca/op_optimization/tree/master/%E5%9F%BA%E4%BA%8EAI%20Agent%E5%BC%80%E5%8F%91%E8%8C%83%E5%BC%8F%E7%9A%84%E5%9B%BD%E4%BA%A7GPU%E5%A4%A7%E6%A8%A1%E5%9E%8B%E6%8E%A8%E7%90%86%E7%AE%97%E5%AD%90%E5%BA%93%E4%BC%98%E5%8C%96%2Foperator_task_package%2Fflashinfer_task_package%2Fxpuoj_problem%2Fproblem_20001%2Fzh_CN)。 #### Step 6:理解 XPU-OJ 评测接口与精度要求 **目标:** 明确 Benchmark 与最终评测提交之间的关系,理解选手需要实现的内容。 @@ -607,17 +607,21 @@ FlashInfer 方向包含 **4 个可选算子题目**,每个对应独立的 benc 使用组委会统一发放的账号登录 XPU-OJ,并进入对应赛题页面。 -1. 打开 [XPU-OJ](https://xpuoj.com/) 平台,使用组委会统一发放的账号和初始密码登录 **【后续发布】**; -![image 20260616152804368](https://origin.picgo.net/2026/06/16/image-20260616152804368aa0d44b72c4f9572.png) +1. 打开 [*XPU-OJ*](https://xpuoj.com/) 平台,使用组委会统一发放的账号和初始密码登录 **【后续发布】**; + + ![OJ](https://origin.picgo.net/2026/06/16/image-20260616152804368aa0d44b72c4f9572.png) 2. 登录后进入比赛 / 题目列表页面; -![image 20260616152953345](https://origin.picgo.net/2026/06/16/image-20260616152953345986ce39fda69da55.png) + + ![OJ-2](https://origin.picgo.net/2026/06/16/image-20260616152953345986ce39fda69da55.png) 3. 找到对应题目,例如 `20001 FlashInfer Ragged Prefill`; -![image 20260616153142383](https://origin.picgo.net/2026/06/16/image-202606161531423833b0f0428edf2e35e.png) + + ![OJ-3](https://origin.picgo.net/2026/06/16/image-202606161531423833b0f0428edf2e35e.png) 4. 点击进入题目详情页,查看题目描述、接口约定、数据范围和提交入口。 -![Screenshot_17-6-2026_165526_xpuoj](https://origin.picgo.net/2026/06/17/Screenshot_17-6-2026_165526_xpuoj.com9a82c272c8ea5699.jpeg) + + ![OJ-4](https://origin.picgo.net/2026/06/17/Screenshot_17-6-2026_165526_xpuoj.com9a82c272c8ea5699.jpeg) #### Step 8:提交 OJ 冒烟代码 **目标**:完成一次最小提交,确认 OJ 提交链路、语言环境和 `run_kernel(...)` 接口可用。 @@ -1326,11 +1330,11 @@ FlashInfer 方向包含 **4 个可选算子题目**,每个对应独立的 benc 4. 点击提交,等待评测结果返回; - ![image 20260616155023443](https://origin.picgo.net/2026/06/16/image-202606161550234433e54d703d581f858.png) + ![OJ-5](https://origin.picgo.net/2026/06/16/image-202606161550234433e54d703d581f858.png) 评测时间与题目测试点数量、队列状态和平台负载有关,通常需要等待**数十秒到数分钟**,以平台实际返回为准。 - ![image iwEcAqNwbmcDAQTRBt8F0QOu](https://origin.picgo.net/2026/06/17/iwEcAqNwbmcDAQTRBt8F0QOuBrA3mrGf2xJ4fgoGfxH9GVsAB9MAAAABijZ-PQgACaJpbQoAC9IAAlPf771f660d13b07471.png) + ![OJ-6](https://origin.picgo.net/2026/06/17/iwEcAqNwbmcDAQTRBt8F0QOuBrA3mrGf2xJ4fgoGfxH9GVsAB9MAAAABijZ-PQgACaJpbQoAC9IAAlPf771f660d13b07471.png) **OJ 评测流程**: @@ -1360,7 +1364,7 @@ FlashInfer 方向包含 **4 个可选算子题目**,每个对应独立的 benc 提交后,OJ 平台对每个测试用例独立评测并返回结果。以下是一份优化后的真实评测输出(来自 20001 FlashInfer Ragged Prefill 第 1 个测试点): - ![sample output](https://origin.picgo.net/2026/06/24/Screenshot-2026-06-24-at-5.57.34PMbe24088f85c638ca.png) + ![OJ-7](https://origin.picgo.net/2026/06/24/Screenshot-2026-06-24-at-5.57.34PMbe24088f85c638ca.png) ```plaintext Testcase #1 @@ -1686,22 +1690,21 @@ mv *.csv results/ ### 9.2 深入理解 FlashInfer 核心概念 -- 阅读 [FlashInfer 官方文档](https://docs.flashinfer.ai/index.html) 及 [源码](https://github.com/flashinfer-ai/flashinfer),理解 Paged KV Cache、Ragged KV Cache 的设计理念; +- 阅读 [*FlashInfer 官方文档*](https://docs.flashinfer.ai/index.html) 及 [*源码*](https://github.com/flashinfer-ai/flashinfer),理解 Paged KV Cache、Ragged KV Cache 的设计理念; - 参考文档:[KV-Cache Layout in FlashInfer](https://docs.flashinfer.ai/tutorials/kv_layout.html) +- 学习 MLA (Multi-head Latent Attention) 的原理,了解 DeepSeek 的注意力优化方案; + +- 理解 `plan()` 和 `run()` 两阶段设计的作用。 -- 学习 MLA (Multi-head Latent Attention) 的原理,了解 DeepSeek 的注意力优化方案; +**参考文档:** - 参考文档: +- [*KV-Cache Layout in FlashInfer*](https://docs.flashinfer.ai/tutorials/kv_layout.html) - - [DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model](https://arxiv.org/abs/2405.04434) +- [*DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model*](https://arxiv.org/abs/2405.04434) - - [DeepSeek-V3 Technical Report](https://arxiv.org/abs/2412.19437) +- [*DeepSeek-V3 Technical Report*](https://arxiv.org/abs/2412.19437) - - [GitHub - deepseek-ai/DeepSeek-V3](https://github.com/deepseek-ai/deepseek-v3) - -- 理解 `plan()` 和 `run()` 两阶段设计的作用。 - +- [*GitHub - deepseek-ai/DeepSeek-V3*](https://github.com/deepseek-ai/deepseek-v3) ### 9.3 进入算子优化模块 @@ -1724,7 +1727,7 @@ mv *.csv results/ 完成优化后,再次运行本模块的 Benchmark 脚本,对比前后性能变化。 -> 使用 Agent 整理优化日志,可形成可复现的 Agent/Skill 优化流程 +> 使用 Agent 整理优化日志,可形成可复现的 Agent / Skill 优化流程 ### 9.5 使用多语言完成算子优化加速