Skip to content

refactor(attention): unify execution ownership and phase backends - #1723

Draft
sufubao wants to merge 11 commits into
mainfrom
refactor/attention-session-rewrite
Draft

sufubao wants to merge 11 commits into
mainfrom
refactor/attention-session-rewrite

Conversation

@sufubao

@sufubao sufubao commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

重写 #1721 的 attention 执行层,目标分支为 main。每个 backend 只实现一个 phase;ModelAttention 负责选型、分组和绑定,AttentionSession 统一执行校验和 workspace lease,State 保留存储、checkpoint、恢复及传输职责。

当前 head 为 68ac92e28,已合入 main 的 1a2a306d3 并解决 import 冲突。此次同步包含上游 logprobs 和 PD 参数检查变更,不计为 attention 重构收益。

执行必须处于 session scope 内,退出后拒绝 layer forward;数值探针使用同一入口,删除独立的 allocate/plan/build 路径。decode Graph 使用各模型声明的输入清单,校验存在性、shape、dtype、device 和同地址 view 的 stride,所有 lane 通过后才复制。图内生成的 DeepSeek-V4 C4 索引不属于重放输入。out 校验拒绝 strided view 行间的 padding 区域。

GDN/KDA/MLA 和稀疏 attention 的模型配置由 adapter 转为不可变 LayerSpec.config,backend 不再读取模型字典。State 返回存储视图,由 adapter 组装计算资源;ReplaySSM backend 只收到数据视图,cursor 由模型在所有层完成后推进一次。GLM indexer 改用模型持有的 SparseQueryMetadata。DeepSeek-V4 初始化从 spec 读取逻辑 head 数,并在模型侧处理 FlashMLA padding,修复启动时访问已删除属性的问题。

设计说明:English / 中文。DeepSeek3.2 仍有 ragged metadata 的 provider 依赖;辅助 capture hooks 的测试只验证协议顺序,尚无真实 provider 的故障恢复验证。workspace lease 负责完成顺序,不是并发锁。

本次修订 674f11ebb 的验证:

检查 结果
CPU 契约、初始化和绑定回归 227 passed,71 项需要 CUDA 的用例跳过
H200 attention、State、DSV4、GLM、GDN/KDA、Graph/MTP 回归 1659 passed,3 skipped,2 deselected
Qwen3.5-0.8B BF16 TP1/DP1,MTP1,native / ReplaySSM 各 64 次主模型及 draft 恢复比较,最大 logits 误差 0,allocator 回收通过
固定版本 Black/Flake8、diff 检查、中英文文档构建 通过;设计页无构建警告

最终合并提交 68ac92e28 的 logprobs、采样参数和结构化输出集成测试为 304 passed,0 skipped,包括 MTP/overlap 用例。首次运行因未显式加载 AnyIO 插件跳过了 71 项异步测试;启用插件后的上述结果取代该次结果。针对当前 main 的整份 PR 固定版本格式检查通过。已逐文件核对:attention、State、模型实现和设计文档与 674f11ebb 相同;相关公共模型目录中变化的 logprobs_capture.py 与上游 main 一致。前述主要 GPU/真实模型结果来自 674f11ebb,并非全部在合并提交上重跑。

GPU 测试使用 torch 2.11/cu130、sglang-kernel 0.4.5、FlashInfer 0.6.18,限定 GPU 7、PyTorch 显存上限 8 GiB。3 项双 GPU 测试跳过,2 项未修改的大地址测试因单个张量超过显存上限未完成验证。GLM 的 410 项本地 PD/状态迁移组合分批在独立进程运行。真实模型启用 prefill/decode CUDA Graph,使用 64-token 前缀、512-token 缓存池、8 步交替 MTP 接受长度;验证本地 GPU/CPU/DP/PD buffer 恢复,不代表跨机 PD、HTTP 服务、全模型覆盖或吞吐验证。

实验命令、失败记录和 JUnit 保留在 /data6/exp_logs/runs/261114-163004-*、261114-163339-*、261114-163439-*;修订提交 674f11ebb 的两组真实模型报告在 261114-163835-*、261114-164039-*。合并验证在 261114-165127-*;最终源码与证据核对记录为 /data6/exp_logs/runs/261114-165250-python3-tmp-attention-review-merge-receipt-py/verification.json。此前的测试数字属于旧版本,此处仅列本次修订的结果。

@sufubao
sufubao changed the base branch from refactor/attention-04-varlen to refactor/attention-05-runtime November 13, 2026 08:05
@sufubao
sufubao marked this pull request as draft November 13, 2026 08:11
@sufubao
sufubao changed the base branch from refactor/attention-05-runtime to main November 13, 2026 08:12
@sufubao
sufubao force-pushed the refactor/attention-session-rewrite branch 2 times, most recently from 50c5c0c to d7c97eb Compare November 13, 2026 08:44
@sufubao
sufubao changed the base branch from main to refactor/attention-05-runtime November 13, 2026 08:48
@sufubao
sufubao force-pushed the refactor/attention-session-rewrite branch from d7c97eb to 72a2951 Compare November 13, 2026 09:42
@sufubao sufubao changed the title refactor(attention): separate phase backends and execution sessions refactor(attention): unify execution ownership and phase backends Nov 13, 2026
@sufubao
sufubao changed the base branch from refactor/attention-05-runtime to main November 13, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant