Open
feat(benchmarks,examples): 归档 MXFP8 量化训练基准与 Qwen3-235B 剪枝示例 #201
feat(benchmarks,examples): 归档 MXFP8 量化训练基准与 Qwen3-235B 剪枝示例 #201
Open
wanglijun55Add on 1 day ago
wanglijun55
wanglijun55Collaborators
1 day ago

【合入来源】

无关联社区 issue(量化训练资料两级基准规范归档任务,含两轮自检修复)。

【修改方案】

按量化训练资料的两级基准规范归档 MXFP8 实测资产:模块级训练基准(benchmarks/ 下 dense/分组 GEMM 脚本实测单模块 GEMM)与端到端训练基准(examples/ 下整网脚本实测)。基准组织遵循仓内判定链:上游 torchao 的 benchmarks/mx_formats/ 仅有 cast_bench.py(无 mxfp8 训练 GEMM 基准),故扩展仓内 benchmarks/prototype/hifloat8/ 的既有模式(timer/utils + configs 文件夹驱动 shapes/recipes)。

  • benchmarks/prototype/mxfp8/(与 hifloat8 同布局):benchmark_mxfp8_linear.py(BF16 nn.Linear vs quantize_(MXFP8LinearConfig),plain / jit_quant 两种 recipe,Qwen3-235B-A22B 投影形状)、benchmark_mxfp8_grouped_mm.py(BF16 torch._grouped_mm vs mx_quant_group_gemm 全链,96 专家)、configs/{shapes,recipes}_{linear,grouped}.yaml(--shapes-file/--recipes-file 驱动)、timer.py/utils.py(与 hifloat8 同源副本)。
  • examples/qwen3_5/qwen3_5_moe_mxfp8_train.py + qwen3_5_moe_mxfp8_train_config.yaml + moe_mxfp8_train.sh(单文件示例,对齐 fp8 rowwise example):
    • --prune-src/--prune-dst/--prune-layers/--prune-experts 一键等效剪枝(前 4 个 decoder 层、每层前 96 个路由专家真实权重切片,router gate 第一维随专家数截断,embedding/lm_head/norm 保留,17.6GB BF16);
    • 内联 Qwen3MoeExperts 的 jagged torch._grouped_mm 前向改写(镜像 modeling_qwen3_5_moe.py,Qwen3Moe 同签名/成员)——BF16 对照不被 HF 逐专家循环 launch 主导,量化收益不失真;
    • quantize_ + MXFP8LinearConfig/MXFP8GMMConfig.from_linear(dense mx_mm patch forward + MXFP8GMM 类交换),数据缺省降级合成 token。
  • docs/zh/workflows/quantized_training.md:在 MXFP8 小节内按既有 per-type 格式新增「模块级训练基准」(grouped GEMM 在前、Linear 在后,与 hifloat8 小节顺序一致;加速比表)与「端到端训练基准」(tokens/second 吞吐表 + kernel 分解 + 复现步骤);模块级分组 GEMM 与端到端 +49.4% 的差异为计时口径并给出定量换算(kernel-only ≈2.0× 两口径自洽),形状/recipe 已完整覆盖端到端场景。
  • 共享 patch modeling_qwen3_5_moe.apply_grouped_mm_forward 参数化 experts_cls(缺省保持 Qwen3_5MoeExperts 行为,fp8 rowwise 示例零改动):mxfp8 示例直接调用 apply_grouped_mm_forward(model, experts_cls=Qwen3MoeExperts)——fp8 与 mxfp8 两个示例共用同一 patch 入口。CPU 对照验证 grouped 前向与 HF 原生逐专家前向 allclose=True。

【资料变更】

  • docs/zh/workflows/quantized_training.md:MXFP8 小节新增两个基准子节,格式与 HiFloat8/Float8 小节一致。

【接口变更】

接口 变更
无 本 PR 不改任何 __init__.py 导出、features/ops 公开 API(纯基准脚本/示例/文档归档)

【功能验证】

  • python benchmarks/prototype/mxfp8/benchmark_mxfp8_linear.py(--shapes/--recipes-file 驱动):NPU 实跑,q/o 投影 jit_quant fwd+bwd 1.69-1.72×、方形 1.58×、k/v 小投影 1.00×(plain 0.77×,如实归档);
  • python benchmarks/prototype/mxfp8/benchmark_mxfp8_grouped_mm.py:NPU 实跑,gate_up/down fwd+bwd 1.14-1.18×(fwd 口径 0.96-1.09×,含 jit 双轴权重量化前置成本,口径已在文档说明);
  • python examples/qwen3_5/qwen3_5_moe_mxfp8_train.py --prune-src ... --steps 3:剪枝 → grouped 前向改写(4 个专家容器)→ MXFP8 转换(16 Linear + 4 GMM)→ 训练 smoke 全链通过;
  • 8 卡 FSDP2 端到端(FSDPTurbo 驱动,100 步,五模式 loss 逐位一致):MoE GEMM kernel +49.4%、Dense 量化投影 +49.5%(达 FP8:BF16 = 2:1 理论的 99%),整网吞吐 +21.5%(jit_quant);
  • flake8(仓内 .flake8 配置)与 codespell 通过。

【CheckList】

likedislike
Merge blocked
wanglijun55wanglijun55Collaborators
1 day ago Created pull request, commit 9db225dd
ascend-robotascend-robotCollaborators
1 day ago Added label: ascend-cla/yes
ascend-robot
ascend-robotCollaborators
1 day 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: sylvia_wei, culechan, 楚浩田, ll-pen, weixin_38374194) ❌ (0/1)(You can also ask: chujinjin, chengpeng25, li_jing_hw, liangsongwei, 褚博宁)

💡 Tip:

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

CLA Signature Pass

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

likedislike
wanglijun55wanglijun55Collaborators
1 day ago Pre merge succeeded (commit_id: 13b07045781c0376d8c9273badc2ffe1386049c0)
38 event messages are collapsed here。 See more
wanglijun55wanglijun55Collaborators
21 hours ago Modify description of pull request