docs(perf-attn): KV-0冗余 prefix sharing attention mask 方案设计与分析 - #50
Open
Jackie2049 wants to merge 3 commits into
Open
Jackie2049 wants to merge 3 commits into
Jackie2049 wants to merge 3 commits into
Conversation
Complete research analysis and design draft (890 lines): §1 研究分析: - Problem definition: build_kv KV expansion bottleneck - Three-backend mask mechanism comparison (TorchRef/GPU FA/NPU) - Full build_kv/PackedBatchLayout/Store/Plan code analysis - Key insight: per-sample mask vs batch-level mask architectural gap - Industry survey: FlexAttention, MagiAttention FFA, TE arbitrary, DTA, PrefixGrouper - RFC #6401 / PR #6689 comparison with cost/benefit table §2 方案设计: - Core transition: data redundancy → metadata (mask) redundancy - Mask construction algorithms for flat GRPO and chain/multi-level trees - Kernel recommendation: FlexAttention (PyTorch ≥2.5) as primary GPU path - NPU npu_fusion_attention with batch-level mask for NPU path - MagiAttention FFA as CP/fallback option - Full module change list with status §3 测试验证 and §4 开发计划: framework with placeholder details Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Actual code uses .copy_() not clone+detach. Gradient flows through copy_ backward, not disconnected.
Jackie2049
force-pushed
the
open-source_refactor
branch
from
July 27, 2026 08:52
e959d74 to
7d84e9f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
新增
docs/developer-docs/impr-perf-attn.md(892 行)—— PrefixSharing 性能优化的下一阶段方向文档:从当前「物理 KV 展开(流派 C)」迁移到「扁平打包 + attention mask(流派 D)」实现 KV-0冗余。文档涵盖完整的研究分析、方案设计、测试验证路径和分阶段开发计划。本 PR 含 3 个 commit(初稿 + 文件改名 + build_kv 梯度描述修正),纯文档新增,不涉及任何代码改动。设计简介
build_kv把 provider prefix 在 KV 张量中物理复制 N 份(N = reuser 数),KV 尺寸从P+S膨胀到P+N*S,带宽随 rollout group size 线性增长。attention_mask(Megatron 原型)、NPUnpu_fusion_attention。关键变更
docs/developer-docs/impr-perf-attn.md(+892 行),包含四大章节:37d57367:修正 build_kv 梯度描述——实际代码用.copy_()而非clone+detach,梯度通过copy_回流,原文档表述有误。测试结果
遗留问题
open-source_perf-attn相对open-source_refactorbehind_by=87,合并会产生 merge commit 或需先 rebase。由于本 PR 只新增一个docs/文件,与 refactor 侧 87 个 commit 产生路径冲突的概率极低。open-source_attention分支上正在进行的 FlexAttention PoC)的实测结果。