Merged
feat: add mixed quantized DeepSeek V4.1 sparse attention #861
feat: add mixed quantized DeepSeek V4.1 sparse attention #861
Merged
zx1029Add on Sep 20
zx1029
zx1029
Sep 20

主要改动:

  • 为 DeepSeek V4.1 新增混合量化稀疏注意力实现。

    • 使用 kv_compress_epilog 打包 BF16 KV。
    • 通过 sparse_flash_mla 执行稀疏注意力。
    • 支持窗口注意力及压缩比例 1/2。
    • 支持文档级索引、本地化 top-k 索引和 attention sinks。
    • 由于混合量化 kernel 暂无 backward,训练反向使用原始 BF16 KV,属于近似梯度。
  • 新增 QuantV41SparseAttentionConfig 模块替换配置。

  • 新增 enable_sparse_attention_quantization 配置项,并接入 TorchAO-NPU converter。

  • 重构量化模块转换逻辑,保留模型特定的模块子类和配置字段。

自验结果:

运行 examples/deepseek_v4_1/debug/deepseek_v4_1_flash_8p_qat_4k_a5.sh 脚本,低精训练功能正常,训练 loss 可稳定下降。

图片1_1.jpg

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for zx1029's contribution.)
zx1029zx1029
Sep 20 Created pull request, commit 80006a4e
CANN-robotCANN-robotCollaborators
Sep 20 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 20 Comments:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-cann/torchtitan-npu ✅ xuyujun, wanghui0 (2/2) ✅ wanghui0 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

zhaoxi1029, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robot
CANN-robotCollaborators
Sep 20 Comments:

CLA Signature Pass

zhaoxi1029, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
zx1029
zx1029
Sep 20 Comments:

compile

likedislike
207 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Sep 20 Added label: lgtm
CANN-robotCANN-robotCollaborators
Sep 20 Merged pull request
CANN-robot
CANN-robotCollaborators
Sep 20 Comments:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
wanghui0wanghui0Collaborators
26 days ago Associated issue: [RFC] DeepSeek V4.1 支持 compress KV C4 和 swa KV C8
CANN-robot
CANN-robotCollaborators
26 days ago Comments:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike