Closed
[Feature] 新增 W8A8 MXFP8 Linear QAT + 统一 MXFP8LinearQAT 类(weight_only 选模式) #70
weixuanAdd on  10 days agoClosed at  4 hours ago
weixuan
weixuan
10 days ago Create

需求背景

torchao_npu 已有 W8A16 Linear QAT(仅权重伪量化到 MXFP8 grid,激活保持 BF16)。GMM 侧已通过 MXFP8GMMQATConfig.weight_only 支持 W8A16/W8A8 双模式。Linear 侧需要补齐 W8A8 模式(激活和权重均伪量化),并统一命名与 GMM 侧对齐。

目标

  1. 新增 W8A8 Linear QAT:通过 MXFP8LinearQATConfig(weight_only=False) 启用,与 W8A16(weight_only=True,默认)共用同一 MXFP8LinearQAT 模块类。
  2. 命名中性化:W8A16Linear → MXFP8LinearQAT、W8A16LinearConfig → MXFP8LinearQATConfig、w8a16_module_filter_fn → mxfp8_linear_qat_filter_fn、文件 w8a16_linear.py → linear.py。
  3. convert 配置一致性校验:block_size / weight_only 与 prepare 不一致时报错。

方案

  1. 改 linear.py(原 w8a16_linear.py):MXFP8LinearQAT 类,forward 读 self.config.weight_only 决定是否对激活做 FQ(FQ8(X) × FQ8(W)^T → BF16 F.linear)。
  2. 改 config.py:MXFP8LinearQATConfig 加 weight_only: bool(默认 True,bool 类型校验),GMM config 基类改为 MXFP8LinearQATConfig。
  3. convert:复用 freeze_weight_inplace;显式传入 block_size 或 config 时都先校验与 prepare 时一致,不传时使用 module.config.block_size;重复 convert 幂等。
  4. 改 filters.py:w8a16_module_filter_fn → mxfp8_linear_qat_filter_fn。
  5. UT 覆盖:新增 W8A8 Linear 用例(forward 与 F.linear(FQ8(X), FQ8(W), bias) 对齐、dX 相同/dW 不同、convert 后仍在线 FQ、配置不一致报错)。

验收标准

  1. API 层:MXFP8LinearQATConfig(weight_only=False) 的 prepare → forward → backward → convert 全链路无报错;W8A16 回归行为不变。
  2. 数值层:W8A8 forward 输出与 W8A16 不同(激活 FQ 改变数值);dX 相同(都用 FQ8(W),STE 恒等)、dW 不同(raw X vs FQ8(X));convert 后新输入仍在线 FQ。
  3. 防护:非 bool 的 weight_only、prepare/convert 的 block_size/weight_only 不一致、非 nn.Linear 目标均明确报错。
  4. UT:全量 pass(含 W8A16 回归 + W8A8 新增 + GMM 回归)。
likedislike
TorchNPU-BotTorchNPU-BotCollaborators
10 days ago Added label: triage-review
TorchNPU-Bot
TorchNPU-BotCollaborators
10 days ago Comments:

issue待分派,添加triage-review标签

likedislike
ascend-robotascend-robotCollaborators
10 days ago Added label: feature
weixuanweixuan
10 days ago changed custom category from Bug-Report to 需求
weixuanweixuan
10 days ago Associated pull request
TorchNPU-BotTorchNPU-BotCollaborators
10 days ago Assign sylvia_wei as responsible person
TorchNPU-BotTorchNPU-BotCollaborators
10 days ago Added label: bot-triaged; Removed label: triage-review
TorchNPU-Bot
TorchNPU-BotCollaborators
10 days ago Comments:

检测到当前 issue 已关联 PR,自动添加标签:bot-triaged
自动设置issue责任人为PR提出人

likedislike
weixuanweixuan
3 days ago Associated pull request
weixuanweixuan
4 hours ago changed custom state from TODO to DONE
weixuanweixuan
4 hours ago Close issue
ascend-robotascend-robotCollaborators
4 hours ago Added label: resolved