Merged
[feat]add dsv4 kv cache fake-quantization support #881
[feat]add dsv4 kv cache fake-quantization support #881
Merged
caoshuyangAdd on Sep 20
caoshuyang
caoshuyangCollaborators
Sep 20

描述

增加DSV4模型kv cache的MXFP8(block size=64)伪量化支持。数学上,伪量化需要加在norm和rope之间。在不修改高精模型的约束下,选择将norm与伪量化合并,在模型中打包为FakeQuantizedNorm。接入方式不影响在override机制中通过类型匹配替换norm的融合算子。

通过在脚本中添加一下参数使能。

QUANTIZATION_ARGS=(
    # 其他量化参数
    --extension.quantization.kv-norm-quantization.format mxfp8    # 伪量化格式,目前仅支持mxfp8。kv cache伪量化的总开关,不设置时默认不启用伪量化。
    --extension.quantization.kv-norm-quantization.fqns .attention.kv_norm,.attention.compressor.norm   # 需要增加伪量化的Norm模块的fqn
    --extension.quantization.kv-norm-quantization.block-size 64     # 伪量化时使用的块大小
    # 其他量化参数
)

类型

Checklist:

如何测试

伪量化在RMSNorm和inplace rope之间执行。override正常换入了RMSNorm的融合算子。
563BA659-A8F1-4672-8E1B-91FA7F5747E6.png

E230539D-8B33-4F26-C5ED-7968BA225DE9.png

伪量化执行次数与预期一致。
B66CED99-3FBA-4D73-D614-98B330B84165.png

loss 和 grad norm正常。
21C91276-6745-4237-D533-B84F60731A71.png

其他信息

在这里可以添加任何与这个 Pull Request 相关的其他说明。

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for caoshuyang's contribution.)
caoshuyangcaoshuyangCollaborators
Sep 20 Created pull request, commit 3f24b35e
caoshuyangcaoshuyangCollaborators
Sep 20 Modify description of pull request
zx1029
zx1029Sep 21Start code review2
examples/deepseek_v4/deepseek_v4_flash_cpt_4k_a5.sh
@@ -38,0 +38,2 @@
38+ --extension.quantization.kv-norm-quantization.format mxfp8
39+ --extension.quantization.kv-norm-quantization.fqns .attention.kv_norm,.attention.compressor.norm
40+ --extension.quantization.kv-norm-quantization.block-size 64
zx1029
zx1029Sep 21Comments:

This code comment section is from+38To+46

当前 deepseek v4 KV 的量化方式是否固定,固定的话可以使用一个传参控制 kv 量化,fqns 建议写到 torchao_converter.py 的 _DSV4_CONFIG_FILTERS 中

likedislike
caoshuyang
caoshuyangCollaborators
Sep 21 Comments:

讨论后决定待torchao_converter.py重构的时候统一设计接口。

likedislike
caoshuyangcaoshuyangCollaborators
Sep 21 virtual merging failed, update merge request[project_id: 9028822, iid: 881, target_commit_sha: 3f24b35ed83be17c012207400984bf1917cd05f8], message: Conflict detected
caoshuyangcaoshuyangCollaborators
Sep 21 Pushed 1 commits:1548e5db-add kv cache quantization in examples/deepseek_v4/debug/deepseek_v4_flash_8p_cpt_4k_a5.sh
148 messages are collapsed here。 See more
wanghui0wanghui0Collaborators
27 days ago Deleted associated issue: [RFC] DeepSeek V4 支持 win/compress KV C8
wanghui0wanghui0Collaborators
27 days ago Associated issue: [RFC] DeepSeek V4 支持 win/compress KV C8
CANN-robot
CANN-robotCollaborators
27 days ago Comments:

Pull Request 已合并或已关闭。

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

likedislike
CANN-robot
CANN-robotCollaborators
27 days ago Comments:

Pull Request 已合并或已关闭。

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

likedislike
CANN-robot
CANN-robotCollaborators
27 days ago Comments:

Pull Request 已合并或已关闭。

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

likedislike