Repository navigation
[1/n] attention backend refactoring: relocate kernels - #1731
Merged
Merged
Conversation
sufubao
force-pushed
the
refactor/attention-backend-1-kernel-layout
branch
2 times, most recently
from
November 16, 2026 09:15
247af76 to
ce7e093
Compare
sufubao
force-pushed
the
refactor/attention-backend-1-kernel-layout
branch
3 times, most recently
from
November 18, 2026 10:09
33c5627 to
2861a14
Compare
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sufubao
force-pushed
the
refactor/attention-backend-1-kernel-layout
branch
from
November 18, 2026 10:19
2861a14 to
4e8f3a1
Compare
sufubao
force-pushed
the
refactor/attention-backend-1-kernel-layout
branch
from
November 20, 2026 07:26
b5bcf3c to
4e8f3a1
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.
attention backend 重构的第 1 个 PR。将原
basemodel/triton_kernel/{att,mla_att,linear_att}三个完整子树中的 58 个 kernel 模块搬到attention/kernels/,包括 6 个多阶段入口;同步搬迁 27 个测试文件,更新所有 caller,删除旧包和 re-export shim。单一提交,识别 rename 后为 +157/-168。本 PR 的实际目录:
卷积和 MTP 参数计算位于
linear/,vendored FLA 的 16 个文件完整保留在linear/fla/,与基线逐字节一致。kernel 按计算类型和原有源码来源组织,不按当前 caller 数量决定位置。入口与 stage 放在一起,去掉flash、stage3_decode_att、int8kv/normal这些额外层级;最长 kernel 路径从 123 缩短到 93 个字符,空 package marker 从 31 减少到 16 个。测试位于对应的unit_tests/common/attention/kernels/。后续 provider 使用
backends/<family>/<impl>.py,随真实 caller 一起加入。本 PR 尚不创建backends/。选型 family 仍是dense / mla / sparse_mla / gdn / kda;linear是 kernel 的算法类别,GDN、KDA 保持独立选型。现有 kernel 入口仍接受
infer_state或state参数,本 PR 不重写这些接口。两处 INT8 入口删除仅用于注解的InferStateInfo导入及参数注解,调用参数和计算保持不变;kernel 树没有对basemodel、attention_state或 backend 的 import。replay_gdn_decode.py和replay_kda_decode.py调优适配暂留原 backend 目录,其中 GDN 的rebuild_inputs会构建 scratch State,随后续 provider 接口迁移处理。本次搬迁边界是上述三个完整 kernel 子树。其余文件的后续归属:
alibi_attfa3_utils、flashinfer_mla_plandiverse_utils、mtp_utilskv_copybasemodel/attention/nsa/拆分路线如下。provider、dtype 和模型变体分别提交,总数保持为
n。forward接口与普通 dense Triton provider,通过现有 adapter 接入真实 Llama prefill/decode2/n、3/n 先通过现有 factory/attention state 适配层接入 Triton、FlashInfer backend,复用当前 allocator 和 graph 生命周期。后续 session 路径依赖初始化和提交生命周期,再迁移 decode graph 和分段 prefill 的所有权机制。各 provider/model 分别迁移,过渡适配集中在现有 factory/State 接口。MTP generation/verification-step 正确性、vision/audio varlen、实测显存准入分别提交;recurrent 迁移依赖的接受正确性修复先合入。
当前提交
24a2f1ed7已 rebase 到 upstream/main39cc51eb2。保留 main 新增的 FlashKDA 路径:kda_state_io.py搬入linear/kda/,chunk-index 测试搬入linear/fla/ops/,更新新 caller 的 import。KDA 和 Replay KDA 的冲突按 main 的实现解决,只改变 import 路径。#1735 的两个提交已同步 restack,range-diff 无内容变化。本次 rebase 后的验证:
39cc51eb2上重跑,失败用例、断言和最大误差全部一致,没有新增失败。flash_kda扩展,未将这些用例计为通过。qwen3next.layer_weights缺少 package marker 失败,也已在当前 main 的 wheel 上复现。这些检查覆盖搬迁及相关数值路径,没有进行完整 serving、分布式或性能验证。旧提交
ce7e0932e5a3上的 120 项 INT8 入口对照及 4 项 MHA/MLA 独立 reference 对照是历史验证,本次未重跑。本次 rebase 前的两条分支保存在
backup/pr1731-before-main-rebase-20261117T071249Z和backup/pr1735-before-main-rebase-20261117T071249Z。完整重构仍保存在backup/pr1723-before-pr-split-20261116T061237Z。