Merged
feat(w4a16): 支持 Qwen3 Dense 和 MoE 权重量化推理 #145
feat(w4a16): 支持 Qwen3 Dense 和 MoE 权重量化推理 #145
Merged
chen_pengyuAdd on 7 days ago
chen_pengyu
chen_pengyu
7 days ago

【合入来源】

基于当前 main 更新 PR #130 的 W4A16 推理实现。

【修改方案】

  1. 特性实现 ee79318。实现 Dense 和融合 MoE 的 W4A16 Tensor,以及对应的 NPU 推理路径。Dense 导出直接保留沿 K 轴打包的原生 MXFP4 权重和 E8M0 scale,加载时搬运连续张量,前向使用转置视图调用 npu_weight_quant_batchmatmul。MoE 保留 QAT 的输出轴量化,首次使用时反量化并缓存 BF16 权重,两组投影分别执行 grouped matmul。
  2. 训练侧适配。保留 W4A16 QAT 的 prepare 入口。配对推断 MoE 专家布局,并在训练后独立打包推理权重。Dense 和 MoE Tensor 注册到通用 safetensors 编解码。
  3. 回归测试 9c1029d。覆盖 QAT、Dense 和 MoE 推理、权重布局、导出字节检查和 safetensors 往返。

【资料变更】

增加了推理代码使用文档

【接口变更】

  • W4A16LinearConfig 和 W4A16GMMConfig 新增仅限关键字的 step,默认且支持 prepare。训练结束后通过 pack_checkpoint_weights() 导出供推理使用的权重。
  • torchao_ascend.features.inference.w4a16 提供 Dense 和 GMM 推理 Tensor。Dense checkpoint 使用原生 K 轴打包格式。

【功能验证】

  • 开发者测试共 80 项通过,覆盖 QAT、推理、导出和 safetensors 的单元及 Ascend NPU 测试。

【CheckList】

likedislike
Pull Request has been successfully merged by ascend-robot.
(Thank you for chen_pengyu's contribution.)
chen_pengyuchen_pengyu
7 days ago Created pull request, commit 9c540037
chen_pengyuchen_pengyu
7 days ago Associated issue: [Feature]: 支持 W4A16 QAT 权重转换及 Dense/MoE 推理
ascend-robotascend-robotCollaborators
7 days ago Added label: stat/needs-squash
ascend-robotascend-robotCollaborators
7 days ago Added label: ascend-cla/yes
ascend-robot
ascend-robotCollaborators
7 days ago 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.


PR Approval Progress

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

Module Approval Details

module lgtm status approve status
repo-Ascend/torchao-ascend ✅ wanglijun55, 褚博宁 (2/2) ✅ wanglijun55 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
158 messages are collapsed here。 See more
ascend-robotascend-robotCollaborators
1 day ago Merged pull request
ascend-robot
ascend-robotCollaborators
1 day ago Comments:

Pull Request 已合并或已关闭。

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

likedislike
chen_pengyuchen_pengyu
1 day ago Modify description of pull request
ascend-robot
ascend-robotCollaborators
1 day ago Comments:

Pull Request 已合并或已关闭。

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

likedislike
ascend-robot
ascend-robotCollaborators
1 day ago Comments:

Pull Request 已合并或已关闭。

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

likedislike