Conversation
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.
概述
本 PR 优化 MetaX 平台上
head_dim=64、GQA Ratio 为 8 的 Paged Attention Decode 路径。在满足条件的场景下,将共享同一 K/V Head 的 Query Head 按每组 4 个进行分组,通过 CTA 内的线程协作加载 K/V tile,并在共享内存中复用,从而减少 Query Head 之间重复的 K/V 数据读取。
优化路径保留原有逐 token 的计算方式及 Split-KV 合并逻辑。不满足条件时继续使用原有实现,不修改公共 API 和默认 split 选择策略。
优化动机
原有实现中,不同 Query Head 由独立 CTA 处理。在 GQA 场景下,多个 Query Head 共享同一个 K/V Head,这会导致相同 K/V 数据被多个 CTA 重复加载。
本 PR 通过 Query Head 分组和共享内存复用,减少冗余 K/V 读取,改善目标 Decode workload 的执行性能。
主要修改
涉及文件:
src/infiniop/ops/paged_attention/metax/paged_attention_hd64.macasrc/infiniop/ops/paged_attention/metax/paged_attention_metax.macatest/infiniop/paged_attention.py优化路径适用条件
优化路径仅在 Split-KV 路径内、满足以下条件时启用:
不满足条件时,继续执行原有 kernel。
正确性验证
git diff --check其中,282 项为
test/infiniop/paged_attention.py中的测试用例,不代表全项目测试数量。框架测试与专项验证共同覆盖:
每个实现的 97 项专项验证包含:
本 PR 未修改原有框架测试的误差阈值。独立专项验证脚本使用明确设置的容差,分别检查 CPU 参考结果、原实现与优化实现的输出及中间结果。
上述测试未穷举所有不满足优化条件的参数、地址对齐和布局组合。
模型集成验证
使用 TinyLlama BF16,在固定输入及后续 token 序列的条件下进行了模型集成验证:
[3, 1, 32000][3, 8, 32000]保存的 logits 均为有限值。Profiler trace 同时确认:原实现运行触发 legacy kernel,优化实现运行触发 grouped kernel。
该结果限于上述模型和测试配置,不代表对任意模型、输入或长序列自由生成的一致性保证。
性能测试
测试环境:
以下为算子微基准结果,计时包含 Split-KV 主 kernel 和 combine kernel,不代表完整 API 调用开销或模型端到端加速比。
执行模式说明:
torch.cuda.CUDAGraph接口捕获并重放 kernel 调用。每个实现预热 50 次,随后交替测量 10 组,每组执行 100 次调用。通过 GPU event 记录整组耗时并计算平均单次延迟,表中报告 10 组平均单次延迟的中位数。计时运行未启用 profiler。
以上绝对延迟来自 C500 25% 算力切片环境,主要用于比较同一环境下新旧 kernel 的相对性能,不代表完整 C500 的绝对性能。
上述结果在相同 Split 数量下比较原实现与优化实现,不包含调整 Split 数量带来的收益。FP16 已纳入正确性验证,本表仅列出最终记录中的 BF16 性能数据。
兼容性
其他说明
框架回归测试包含在本 PR 中;97 项专项验证、性能微基准和模型集成验证使用独立实验脚本,结果来自留档记录,这些脚本未包含在本次提交中。
本 PR 仅包含两份 MetaX 算子实现文件和一份已有测试文件的修改,不包含实验日志、模型文件或构建产物。