Open
feat(mxfp8_qat): checkpoint convert with serializable MXFP8 weights #192
weixuanAdd on 2 days ago
feat(mxfp8_qat): checkpoint convert with serializable MXFP8 weights #192
Open
Merge blocked
2 days ago Associated issue: [Feature] 新增 W8A8 MXFP8 Linear QAT + 统一 MXFP8LinearQAT 类(weight_only 选模式)
2 days ago Associated issue: [Feature] 新增 W8A8 MXFP8 Linear QAT + 统一 MXFP8LinearQAT 类(weight_only 选模式)
2 days ago Added label: stat/needs-squash
2 days ago Added label: ascend-cla/yes
ascend-robot
2 days ago Comments:
2 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
⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-Ascend/torchao-ascend | ❌ (0/2)(You can also ask: xuyun15, lizhihai137, wangzhenwu, 楚浩田, chujinjin) | ❌ (0/1)(You can also ask: liangsongwei, xuyun15, ffmh, wanglijun55, chujinjin) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
sylvia_wei, thanks for your pull request. All authors of the commits have signed the CLA. 👍


55 messages are collapsed here。 See more
9 hours ago Pre merge succeeded (commit_id: b67dd4d72b780b8a0af1c0fe2ae54fe9d0804576)
9 hours ago Removed label: ascend-cla/yes
9 hours ago Added label: ascend-cla/yes
9 hours ago Change title to "feat(mxfp8_qat): checkpoint convert with serializable MXFP8 weights", originally titled "feat(mxfp8_qat): add read-only weight export (MXFP8 qdata + E8M0 scale)".
9 hours ago Change title to "feat(mxfp8_qat): checkpoint convert with serializable MXFP8 weights", originally titled "feat(mxfp8_qat): add read-only weight export (MXFP8 qdata + E8M0 scale)".
9 hours ago Modify description of pull request
【合入来源】
关联 issue: #70
本 PR 是已合入 #142(W8A8 MXFP8 Linear QAT)的后续:补齐训练后的 checkpoint convert——把训练产出的 BF16 master weight 打包为可序列化、可恢复的 MXFP8 推理权重。Dense/MoE 的低精推理 forward 在后续 PR 交付。
【修改方案】
训练后调用链:
state = {k: v.detach().cpu() for k, v in qat_model.state_dict().items()} pack_checkpoint_weights(state, model=qat_model, dense_names=["model.linear"], expert_names=["model.experts"], device=npu_device) save_safetensors(state, output_dir)pack_checkpoint_weights以待保存的 state 为唯一量化数据源(model 仅提供 prepared 模块的配置与参数名),原位替换选中权重,未选中的键原样保留。1. 打包入口与事务性
dense_names/expert_names为模块 FQN),未选中的 prepared 权重不打包;block_size=32(打包前拒绝其他值);state.update,任一失败 state 保持原状。2. 量化核心
quantize_native_grid:RCEIL(scale_alg=1,与训练一致)、块网格对齐、scale 以自然块序 uint8 保存;pack_one_projection:MoE 逐 expert 搬运到 NPU 量化、CPU 拼回(不一次性上卡生产规模权重);W8A8 在打包时补齐到 64 倍数(成对 scale 布局要求),追加零值 FP8 byte 与填充 scale byte;3. 序列化权重对象
MXFP8DenseTensor/MXFP8GMMTensor(TorchAOBaseTensor):qdata/scale均为 uint8(E4M3FN 值编码 / E8M0 byte),不依赖 safetensors 对 float8 dtype 的支持;NPU 加载时按位 view 构造算子视图;orig_shape/orig_dtype/weight_only/block_size随 checkpoint 往返;两种激活模式共用同一存储格式,加载端按weight_only分叉;from_packed校验:native vs 64 对齐网格(按模式)、scale 块数、dtype、前导形状;4. 配置 prepare-only
MXFP8LinearQATConfig/MXFP8GMMQATConfig构造期拒绝step='convert',报错指向pack_checkpoint_weights;quantize_handler 只做 prepare。原 Dense 冻结分支(convert_mxfp8_linear_qat_/freeze_weight_inplace/冻结标记)与 MoE convert 占位函数移除;先前试做的公开导出(convert_mxfp8_qat_weights/MXFP8Weight/quantize_mxfp8_weight)均未发布,直接删除、无迁移期。【资料变更】
不涉及
【接口变更】
pack_checkpoint_weightsMXFP8DenseTensor/MXFP8GMMTensorMXFP8LinearQATConfig/MXFP8GMMQATConfigstep='convert'并指向新入口quantize_(..., step='convert')【功能验证】
test/unit/全量 396 passed, 2 skipped(1 个与本项目无关的既有失败已单独确认)。python -m pytest test/unit/ -q ASCEND_RT_VISIBLE_DEVICES=<free card> python -m pytest \ test/npu/test_mxfp8_qat_weight_conversion_npu.py \ test/npu/test_mxfp8_qat_pack_entry_npu.py \ test/npu/test_w8a16_qat_npu.py test/npu/test_w8a8_mxfp8_qat_npu.py \ test/npu/test_w8a8_qat_npu.py -q【CheckList】