Skip to content

[2/n] attention backend refactoring: all attention paths (GQA, MLA, sparse MLA, GDN, KDA) and removal of the model-side adapters - #1735

Open
sufubao wants to merge 90 commits into
mainfrom
refactor/attention-backend-2-dense-triton
Open

sufubao wants to merge 90 commits into
mainfrom
refactor/attention-backend-2-dense-triton

Conversation

@sufubao

@sufubao sufubao commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

概述

所有 attention 路径(GQA、MLA、稀疏 MLA、GDN、KDA)改由 lightllm/common/attention/ 下的 backend 层执行,原 lightllm/common/basemodel/attention/ 中的模型侧 adapter 全部删除。模型层只声明每层的静态配置、组装本层张量并调用 backend,不再直接调用 attention kernel(由 test_attention_call_sites.py 检查)。

改动规模:生产代码 138 个文件(+5856/−6584),测试 86 个文件(+8220/−2515)。完整设计见 docs/CN/source/framework/attention_backend_design.md。

设计

每步由 AttentionBackendManager.create_att_metadata_by_group 生成按组索引的元数据;各组执行 InferStateInfo → backend.create_att_metadata → att_metadata → backend.forward。

类型 生命周期 作用
*LayerConfig 模型加载时 一层的静态配置(head 数、维度、dtype、scale、因果性、滑窗、sinks、KV 量化方式等),frozen 且构造时校验
AttentionBackend 模型加载时 持有 layer config;声明 name、phase、metadata_config_key,实现 init_runtime、build_att_metadata、forward
InferStateInfo 每个 microbatch 当前请求布局、模型容量和 manager 引用,供 init_runtime 与 build_att_metadata 读取
att_metadata 每个 microbatch 同组各层共用的页表、索引、调度计划或 wrapper
*LayerInputs 每次层调用 本层的 q、KV cache 视图、量化 scale、状态视图、稀疏索引等
  • 选择:selector.py 按 layer config 类型找到算法族,按名称或 auto 优先级构造 backend。backend 在构造时拒绝不支持的配置(NotImplementedError),auto 跳过它,显式指定则在模型加载时报错并列出原因。各 backend 用 phase 声明运行阶段,选择器只把它绑定到该阶段。
  • 登记与分组:AttentionBackendManager 与 AttentionStateManager 组织方式一致:主模型创建、草稿模型共用,按模型角色(main、draft0 …)登记。register_backends(model) 显式遍历每层的 prefill/decode 配置,将选择规则和实例复用交给本次注册独有的 BackendSelector(args);selector 统一处理层指定名称、CLI、MTP 优先级和 EP 的 auto 排除规则,manager 保存层绑定与状态分组。层每次调用时用 get_backend(角色, 阶段, 逻辑层号) 取用,与 get_state(角色, 类型, 逻辑层号) 对应。同一角色内阶段、配置和最终请求名称相同的层共用实例,不同角色不共用(实例持有本角色的跨步与 graph 存储)。每个阶段按 (backend 类, metadata_config_key) 分组,组内第一个实例在首次 create_att_metadata 时调用 init_runtime(infer_state) 初始化跨步存储,之后每个 microbatch build_att_metadata 一次状态,组内各层共用。metadata_config_key 是参与准备的配置子集,metadata_group_key 是包含 backend 类的完整键;manager 的 group_backends 保存各组代表实例,_layer_backends 保存层绑定,selector 的 _selection_cache 复用选择结果。
  • 模型输入:_create_inferstate 直接从 MtpManager、模型参数和当前角色的 recurrent State 准备 page size、模型序列容量、graph batch 容量、最大 decode 行数和 diverse 开关,以及本步的 decode 行数、dynamic verify 标记、投机状态索引和 graph KV 长度容量,删除 step_configs 与 configure_attention_step。manager 只按角色和阶段构建 attention 状态;循环状态唯一性在模型初始化时检查,纯 FFN 草稿与 KV-only 步骤跳过 attention 准备。backend 选择日志在登记结束后输出。
  • 运行时资源:移除 AttentionBuildResources,create_att_metadata 只接收 infer_state。backend 首次初始化只保留需要的标量和缓冲区,不持有整份推理状态。AttentionBackendManager.get_workspace(name, numel, dtype) 管理缓存,替代独立的 workspace_utils.py;main 与 draft 共用,同名同尺寸请求地址固定,独立 manager 之间隔离。FlashInfer GQA 自行读取并校验 flashinfer_workspace_size,私有配置不放入通用状态。
  • CUDA graph:graph 步的派生张量通过 update_graph_tensor 按 (microbatch, batch size) 固定地址并原地改写;第三方有状态对象(FlashInfer wrapper、FlashMLA scheduler metadata)同样按该键保存,replay 时原地重新规划。
  • 命名与坐标:每步的页表、索引和 wrapper 统一称为 *Metadata,与 KV/SSM 持久状态区分。use_ssm_replay、state_draft_capacity、max_draft_tokens 和 max_decode_rows_per_request 明确模式与容量;logical_layer_id、head 维度、卷积宽度、sink 字段及测试辅助函数同步统一。稀疏输入拆分物理缓存槽位 topk_cache_indices、请求内位置 topk_token_positions 和拼接位置 topk_ragged_indices;SWA 压缩缓存使用 compressed_indices / compressed_lengths。
  • 输出:forward 写入调用方提供的 out,只有 kernel 不接受 out、需要补齐 head 或需要 FP32 合并时才复制。
  • 模型侧 GQA:GQATransformerLayerInferTpl(Llama、Bloom 的基类)提供 GQA 的 attention_config 与 prefill/decode 调用,通用的 TransformerLayerInferTpl 不假定 attention 类型;模型只通过 _gqa_config(model, **fields)、_gqa_sinks、_gqa_alibi_slopes、_gqa_kv_cache 提供自身差异。
  • 分层:lightllm/common/attention 在运行时不依赖模型代码;InferStateInfo 只在 TYPE_CHECKING 下用于注解,GraphMode 定义在 backend.py。

覆盖范围

算法族 layer config 实现 模型
gqa GQALayerConfig Triton(含 int8/int4 分组量化 KV)、FlashInfer、FA3 Llama 系、Qwen、Mistral/Mixtral、StarCoder、Bloom(ALiBi)、GPT-OSS(sinks、滑窗)、Gemma4 与 Neo(图像区间双向)、FP8 KV、MTP/DFlash 草稿
mla MLAPrefillLayerConfig、MLADecodeLayerConfig Triton、FlashInfer、FA3 DeepSeek V2/V3、GLM-4.7-Flash(256 维)
sparse_mla SparseMLALayerConfig、SWASparseMLALayerConfig FlashMLA、FA3(按 cache 格式),FlashMLA SWA DeepSeek V3.2、GLM-5、DeepSeek V4
gdn GDNLayerConfig Triton、FlashQLA(prefill),replay decode Qwen3-Next / Qwen3.5、SenseNova Loop
kda KDALayerConfig Triton(prefill 可按步使用 FlashKDA),replay GLM-5-Next 线性层

线性注意力的 backend 原地更新调用方的 conv/SSM 状态,replay 状态通过 LayerInputs.replay_state 追加历史。

用户可见的变化

  • 新参数 --att_backend FAMILY.PHASE=BACKEND,例如 --att_backend gqa.prefill=fa3 gqa.decode=flashinfer gdn.prefill=flashqla;算法族为 gqa、mla、sparse_mla、gdn、kda,未指定的项为 auto,解析时按注册表校验。--llm_prefill_att_backend / --llm_decode_att_backend 仍可使用但已弃用(启动时警告),--att_backend 的项优先。文档、cookbook 和启动脚本已改用新参数。
  • 稀疏实现可明确选择:sparse_mla.prefill/decode=flashmla 或 fa3,不支持该格式时直接报错;flashmla_sparse 和 auto 保留原来的按 cache 格式选择行为。GLM 层直接声明各阶段所需 provider。混合 Triton/FlashKDA 的 prefill 类命名为 KDAPrefillBackend,FP8 稀疏 decode(含小 graph 的 Triton 路径)命名为 FP8SparseMLADecodeBackend。
  • 不支持的配置在加载时报错,不再静默按默认行为计算,例如 FP16 模型配 FP8 FA3 KV cache、Triton GQA 的非默认 softmax scale、缺少 topk 的 FA3 稀疏 MLA decode。
  • 草稿模型复用主模型的 workspace:GLM-5 的 FP8 prefill 区域按 microbatch 命名(此前每个草稿模型各自预留最多 2 GiB),DeepSeek V4 的 SWA 暂存区按每层布局命名。
  • 输出直接写入调用方的缓冲区,减少一次拷贝。

修复

提交 修复
6cefb3054 Triton 256 维 MLA prefill 忽略 softmax_scale(YaRN mscale 下结果错误)
53b8776b3 Triton 投机解码 GQA decode 丢失滑窗
6ddbca4c1 Gemma4 滑窗层的图像区间注意力越过区间边界(新增 b_image_token_start)
b8585c12a FP16 模型使用 FP8 FA3 KV cache(FA3 只输出 BF16)
c882436da FlashKDA eager prefill 的 beta 不连续
254ebcb28 replay autotune 不接受 out;GDN gate 多一次拷贝
b3abf361d backend 几何参数未校验;稀疏 prefill 显存无上界
85cb10bbe FlashMLA 在 graph 捕获时复用 warm-up 的调度状态
1655e5f4d、c33728061 旧版 FlashMLA 接口(无 out 参数)的 FP8 与 BF16 prefill

测试

  • 各 backend 与独立的 torch 参考实现对比(量化路径对比反量化后的参考),覆盖 cached prefix、三种 decode 布局(固定、dynamic verify、diverse)和各 backend 声明支持的层属性;GDN/KDA 与逐 token 的顺序参考对比。
  • 每个 decode backend 的 CUDA graph 约定:同一 (microbatch, batch size) 的捕获与 replay 保持地址,值等于 eager 构造,不同 microbatch 不共享存储;并通过 CudaGraph.capture_decode / replay 在长度变化后验证。
  • 选择器、分组、阶段约束、--att_backend 解析、workspace 共享和分层规则各有单元测试。
  • 本次命名与索引接口整理在 H200 GPU6(PyTorch 2.11.0+cu130、FlashInfer 0.6.18、FlashMLA)上通过 1294 项相关回归,覆盖五类 attention、数值对比、CUDA graph replay、speculative decode、selector/CLI、模型层输入、稀疏索引和 FP8 layout;62 项因 FlashKDA 不可用跳过,已在基线上复现的 FP8 CPU/PD run_mode fixture 失败排除 1 项。实验记录:261128-002615-data6-exp-logs-artifacts-pr1735-attention-famili。扩展回归发现的另外 11 项旧 fixture 失败已在干净 c6b21fd78 复现并修正(workspace manager 与投影 mock 参数名),上述通过数包含修正后的用例。
  • 此前运行时初始化与 workspace 整理在 H200 GPU6(PyTorch 2.11.0+cu130、FlashInfer 0.6.18)上验证:876 项通过,覆盖 backend 数值、CUDA graph、模型输入、manager 隔离、workspace 共享及推理状态释放;62 项因 FlashKDA 不可用跳过。已在基线上复现的 FP8 CPU/PD run_mode fixture 失败排除 1 项。实验记录:261127-202124-data6-exp-logs-artifacts-pr1735-attention-famili。
  • 此前 selector 整理在 H200 GPU6(PyTorch 2.11.0+cu130、FlashInfer 0.6.18)上通过 180 项检查:169 项选择器、manager、角色隔离及模型输入测试,11 项 FA3、FlashInfer 和 Triton MLA 经由 manager 注册后的 CUDA graph 回归,包含固定与 dynamic MTP、长度变化和双 microbatch。
  • 此前模型输入调整在 H200 GPU6(PyTorch 2.11.0+cu130、FlashInfer 0.6.18)上验证:定向检查 205 项通过,backend 数值与 CUDA graph 回归 845 项通过(含两项 MLA graph 补齐测试输入后的复测),共 1050 项通过;62 项因 FlashKDA 不可用跳过。另有 1 项 FP8 CPU/PD 测试 test_fp8_state_preserves_kv_and_indexer_across_cpu_and_pd 因 fixture 缺少 run_mode 失败,已在未修改的 43c7613c9 上复现。
  • 此前在 H200 上完整运行 unit_tests/common、unit_tests/utils、unit_tests/models 与多级 KV cache 测试:common 18 项失败、5186 项通过,models 27 项失败、1622 项通过,各 1 项收集错误。剩余失败在 main(85ba752f0)上同样失败,属于环境(kernel 版本、数值容差、显存)或已有问题,例如 DeepSeek V4 kernel、GDN 数值、CPU cache 控制流,以及 deepseek_v4/test_kernels.py 与 glm5_next/test_kernels.py 同名导致的收集错误。
  • Black、Flake8 和 git diff --check 通过。

已知限制

  • 当前 main 新增的 DeepSeek V4.1 支持(Add DeepSeek V4.1 Flash model support #1758,58e18b323)尚未合入本分支,涉及 6 个文件冲突;更新前的 999283385 也有相同冲突。GitHub 当前显示 CONFLICTING,本次提交未触发远端 CI;上述验证为本地记录。
  • 本地没有模型权重,未做端到端服务验证与性能测量;workspace 共享节省的显存也未在真实 MTP 部署上测量。
  • InferStateInfo.copy_for_cuda_graph 仍按属性复制请求张量(跳过 req_to_mtp_state_index);GDN/KDA 共用 RecurrentDecodeMetadata 及其构造函数。

评审指南

提交按以下顺序分组,可逐组阅读:

  1. backend 与迁移(cf729774b … 58684eb86):接口、各算法族 backend,以及 GQA 变体、MLA、稀疏 MLA、GDN、KDA 的迁移。

  2. 修复与测试(830cd6146 … 5f2ec2857):见上表;backend 数值、graph 约定和调用位置测试。

  3. 移除 adapter(753837a19 … 24f9efbdc):选择器、模型侧绑定,删除 basemodel/attention。

  4. 状态准备收敛(2af81a98d … c33728061):每步状态在 _create_inferstate 中一次构建、输出写入 out、manager 与命名整理,以及 FlashMLA 兼容修复。

  5. 整理(4d099a87f … c6b21fd78):跨步存储放到 backend 实例上、统一模块写法、phase、--att_backend、workspace 共享、分层规则与测试修复,以及 GQA 层调用收敛到 GQATransformerLayerInferTpl(Llama、Bloom 不再各写一份),ALiBi kernel 移入 common/attention/kernels/gqa/alibi,backend manager 按角色共享并按逻辑层查找;每步输入在模型侧直接准备,移除中间配置字典和转发函数;选择策略和角色内的实例复用集中到 BackendSelector,注册循环只保留显式阶段遍历、层绑定和状态分组;模型容量直接放入 InferStateInfo,共享 workspace 归 manager 持有,首次初始化命名为 init_runtime。

  6. 命名统一(1f771ba30):统一 metadata 生命周期、分组键、配置字段、provider 与稀疏索引坐标;同步调用、测试和设计文档,移除残留的 StepBuilder 命名和测试包装。

@sufubao
sufubao force-pushed the refactor/attention-backend-2-dense-triton branch from 2716162 to 00592ad Compare November 17, 2026 07:27
@sufubao
sufubao force-pushed the refactor/attention-backend-1-kernel-layout branch from ce7e093 to 24a2f1e Compare November 17, 2026 07:27
@sufubao
sufubao force-pushed the refactor/attention-backend-1-kernel-layout branch from 24a2f1e to 33c5627 Compare November 18, 2026 09:24
@sufubao
sufubao force-pushed the refactor/attention-backend-2-dense-triton branch 2 times, most recently from 5bb04ad to 44f41a9 Compare November 18, 2026 10:09
@sufubao
sufubao force-pushed the refactor/attention-backend-1-kernel-layout branch from 33c5627 to 2861a14 Compare November 18, 2026 10:09
@sufubao
sufubao force-pushed the refactor/attention-backend-2-dense-triton branch from 44f41a9 to 7e3e005 Compare November 18, 2026 10:19
@sufubao
sufubao force-pushed the refactor/attention-backend-1-kernel-layout branch from 2861a14 to 4e8f3a1 Compare November 18, 2026 10:19
@sufubao
sufubao force-pushed the refactor/attention-backend-2-dense-triton branch from 7e3e005 to 55145d4 Compare November 20, 2026 07:19
@sufubao
sufubao force-pushed the refactor/attention-backend-1-kernel-layout branch from b5bcf3c to 4e8f3a1 Compare November 20, 2026 07:26
@sufubao
sufubao force-pushed the refactor/attention-backend-2-dense-triton branch from 55145d4 to 7e3e005 Compare November 20, 2026 07:26
Base automatically changed from refactor/attention-backend-1-kernel-layout to main November 20, 2026 08:09
@sufubao
sufubao force-pushed the refactor/attention-backend-2-dense-triton branch 2 times, most recently from 14a4fb7 to ee1e7ea Compare November 20, 2026 09:24
@sufubao sufubao changed the title [2/n] attention backend refactoring: introduce dense Triton backends [2/n] attention backend refactoring: GQA, MLA and sparse MLA Nov 20, 2026
sufubao added a commit that referenced this pull request Nov 20, 2026
The GQA FlashInfer backends now implement the plan/refresh lifecycle
from #1735. plan() builds and plans the prefill or CUDA-graph-capable
decode wrapper over caller-owned workspace and page buffers, and the
decode refresh() runs fast_decode_plan for graph replay. The adapter
derives page metadata, plans once in init_state and refreshes the
captured batch in copy_for_decode_cuda_graph.

refresh() accepts provider-specific keyword arguments, since FlashInfer
re-plans from the replay batch's maximum KV length. The adapter keeps
prefill_wrapper and decode_wrapper because the FP8 subclass still runs
the wrapper directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sufubao
sufubao force-pushed the refactor/attention-backend-2-dense-triton branch from 9f780d8 to f303ea4 Compare November 20, 2026 13:55
@sufubao
sufubao force-pushed the refactor/attention-backend-2-dense-triton branch from f303ea4 to 4605284 Compare November 20, 2026 15:29
@sufubao sufubao changed the title [2/n] attention backend refactoring: GQA, MLA and sparse MLA [2/n] attention backend refactoring: GQA (Triton, FlashInfer, FA3) and MLA Nov 20, 2026
@sufubao
sufubao force-pushed the refactor/attention-backend-2-dense-triton branch 2 times, most recently from b6d4ead to 0e710cf Compare November 21, 2026 07:57
@sufubao sufubao changed the title [2/n] attention backend refactoring: GQA (Triton, FlashInfer, FA3) and MLA [2/n] attention backend refactoring: all attention paths (GQA, MLA, sparse MLA, GDN, KDA) Nov 21, 2026
@sufubao
sufubao force-pushed the refactor/attention-backend-2-dense-triton branch 2 times, most recently from adad5b4 to 7126ab1 Compare November 23, 2026 02:21
@sufubao sufubao changed the title [2/n] attention backend refactoring: all attention paths (GQA, MLA, sparse MLA, GDN, KDA) [2/n] attention backend refactoring: all attention paths (GQA, MLA, sparse MLA, GDN, KDA) and removal of the model-side adapters Nov 23, 2026
sufubao and others added 14 commits November 30, 2026 08:35
--att_backend takes FAMILY.PHASE=BACKEND entries (gqa.prefill=fa3
gdn.prefill=flashqla kda.prefill=flashkda ...) for the families gqa,
mla, sparse_mla, gdn and kda. Omitted keys stay auto. The parser checks
keys and names against the selector registry, so a typo or a name the
family does not offer fails at startup with the valid choices.

Each registry Family now carries its name. selector.requested_backend
reads --att_backend first and falls back to the deprecated positional
--llm_{prefill,decode}_att_backend flags (first value for full
attention, second for linear attention), which keep working with a
warning. GLM-5's KDA prefill kernel and the EP-MoE flashinfer check use
the same lookup. The unused enable_triton_mtp_kernel helper is removed.
Docs, cookbooks and start scripts use the new flag; GLM-4.7-Flash uses
the mla keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
get_gpu_workspace_buffer now keys storage by (device, name, dtype): a
request no larger than a buffer the name already has gets a prefix view
of it. Main and draft models prefill one after the other, so a name may
be shared as long as it has one user at a time.

The model-side prefill workspaces were named per role, so every MTP
draft reserved its own copy (up to 2 GiB of FP8 gather space each for
GLM-5). GLM-5 now names its FP8 prefill regions per microbatch, which
keeps region i of every model on the same stream, and shares one
read-only cu_seqlens_q arange across regions. DeepSeek V4 names its SWA
staging buffer by its per-layer layout, so a one-layer draft stages into
the main model's first layer slice and a draft with another layout gets
its own buffer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…orts

The PR's own rule test (lightllm.common.attention must not depend on
models) failed: every backend imported InferStateInfo from
lightllm.common.basemodel at runtime. Backends now name InferStateInfo
only under TYPE_CHECKING, the one runtime need, GraphMode, is defined in
lightllm/common/attention/backend.py and re-exported by infer_struct, and
the rule test skips TYPE_CHECKING blocks, since annotations create no
runtime dependency. The caller-glob test no longer expects the deleted
layer_infer/gqa_attention.py.

The graph-storage helper is public as keep_for_graph: the shared FA3 and
recurrent decode builders call it on another backend, and backend authors
are meant to use it. The test helper no longer writes the private
set-up flag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The FlashKDA prefill tests built bare type(...)() stubs. Copying
InferStateInfo's instance fields onto them misses properties such as
uses_cuda_graph, which the KDA prefill backend reads, so 8 cases failed.
They now start from InferStateInfo().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…plate

Llama and Bloom each carried the same GQA wiring: the cache-state lookup,
the layer config, the GQALayerInputs assembly and the backend call. It now
lives once in TransformerLayerInferTpl, which already writes the layer's
full-attention KV cache, as the default attention_config and attention
kernels. Models override only what is theirs: extra config fields through
_gqa_config(model, **fields), per-layer sinks or ALiBi slopes, and the KV
view. Bloom keeps just its ALiBi config and slopes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
setup already runs on a phase's first prepare, so taking the workspace there
is as lazy as the deferred lookups it replaces: the MLA module's one-line
_workspace helper and the GQA backend's stored lambda. Each backend now keeps
the tensor as self.workspace, and MLA no longer keeps the resources.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- requires_cpu_cache_sync is a backend class attribute again; the FA3
  backends set it from FA3_CPU_CACHE_SYNC instead of three classmethods
  calling a one-line env wrapper. The manager exposes it as a property and
  the CPU cache module reads it there, without a model-level alias.
- The manager's backends(phase) only re-listed state_groups[phase]; callers
  read state_groups directly.
- The selector imports the library validator instead of wrapping it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nels

The ALiBi prefill and decode kernels were the last attention kernels outside
lightllm/common/attention/kernels. They now live in kernels/gqa/alibi next to
the int8kv and int4kv variants, so the call-site rule needs no special case
for basemodel/triton_kernel/alibi_att.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…plate

803f899 made TransformerLayerInferTpl default to GQA, but DeepSeek V4 and
GLM-5-Next also derive from it and are not GQA. The generic template is
back to declaring no attention type (it keeps only the prefill_backend and
decode_backend slots every layer gets), and the shared GQA wiring lives in
GQATransformerLayerInferTpl, which Llama and Bloom derive from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tion_state does

The main model now creates one AttentionBackendManager next to its
AttentionStateManager and its drafts share it. Backends are registered
per model role (register_backends(model)), and layers look theirs up on
each call with get_backend(role, phase, logical_layer_id), mirroring
get_state(role, type, logical_layer_id). Layer configs still come from
each layer's attention_config(model).

Backend instances are shared within a role but never across roles,
since each owns its role's cross-step and CUDA graph storage. The
bound prefill_backend / decode_backend slots on the layer template are
gone, prepare is renamed create_att_state on both the manager and the
backends, has_attention takes the role, and requires_cpu_cache_sync
covers every registered role. GDN/KDA layers always pass replay_state,
which only replay backends read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hiworldwzj
hiworldwzj force-pushed the refactor/attention-backend-2-dense-triton branch from 1f771ba to b060935 Compare November 30, 2026 10:12
hiworldwzj and others added 15 commits November 30, 2026 13:02
These types describe one attention call, separate from the transformer layer that invokes it.

Co-authored-by: Cursor <cursoragent@cursor.com>
Docs and helpers still called the same object "att config" or "config" after the rename.

Co-authored-by: Cursor <cursoragent@cursor.com>
Give each state layout its own directory so replay prefill inherits the native class, and register FlashKDA as its own prefill backend.

Co-authored-by: Cursor <cursoragent@cursor.com>
Machine and config checks decide the implementation at load time, so a selected FlashKDA prefill always runs FlashKDA and an explicit backend fails before the first step.

Co-authored-by: Cursor <cursoragent@cursor.com>
The selected FlashKDA prefill loads its kernel directly. Availability stays in the machine check instead of a second loader that could still return no kernel.

Co-authored-by: Cursor <cursoragent@cursor.com>
KDA prefill metadata no longer chooses a kernel. Each backend calls its own prefill function, and the selected FlashKDA kernel stays on the backend.

Co-authored-by: Cursor <cursoragent@cursor.com>
Triton and FlashKDA pack the same state slots. Each backend still supplies its own attn_cu_seqlens dtype.

Co-authored-by: Cursor <cursoragent@cursor.com>
Prefill and decode both reject an AttConfig whose native or replay layout does not match the backend, through one check.

Co-authored-by: Cursor <cursoragent@cursor.com>
Selection and cache sync read these from the backend itself, so each
implementation sets them as instance properties and keeps the base method order.

Co-authored-by: Cursor <cursoragent@cursor.com>
The step mode belongs with the infer state. Drop the allocator protocol and
keep alloc_func as the forward argument it already was.

Co-authored-by: Cursor <cursoragent@cursor.com>
Layers no longer pin an implementation. metadata_config_key reads the
backend's own config, and the command line plus config checks select it.

Co-authored-by: Cursor <cursoragent@cursor.com>
Each distinct config gets one backend and one metadata entry, so the
backend no longer publishes a separate grouping key.

Co-authored-by: Cursor <cursoragent@cursor.com>
Pass the model's fixed capacities when a backend is constructed, and keep only the scalars that backend uses. One shared scratch buffer is reserved at registration and handed to create_att_metadata.

Co-authored-by: Cursor <cursoragent@cursor.com>
Registration of a model's backends belongs with the attention component, next to the selector and the backend interface.

Co-authored-by: Cursor <cursoragent@cursor.com>
Move the backend manager to attention/manager.py. Register every role before warmup, then allocate the shared scratch once so CUDA graph capture keeps that address.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

2 participants