已合并
修正qwen3.5-0.8b资料 #1188
修正qwen3.5-0.8b资料 #1188
已合并
xiongpan创建于 9月1日
xiongpan成员
9月1日

What type of PR is this?

/kind bug


What does this PR do / why do we need it:

背景

Qwen3.5-0.8B 示例原本强依赖 CANN 的 PromptFlashAttention(PFA) 与 IncreFlashAttention(IFA) 自定义算子,但这两个算子在 Atlas 300I Duo 与 Atlas 800I A2 上的支持情况不同,导致跨硬件部署时精度/可用性有问题。本提交将自定义算子改为可开关、并补齐了若干正确性修正,使同一套导出/推理代码能在两块卡上都正确跑通。

改动点

  1. export_qwen3_5_0_8b_onnx.py (核心)
  • 新增 --use-pfa / --use-ifa 两个开关 ( BooleanOptionalAction ,默认关闭),分别控制 prefill 全注意力是否用 PromptFlashAttention、decode 全注意力是否用 IncreFlashAttention。关闭时各自回落到标准算子实现的手动注意力(matmul + boolean mask + softmax),不依赖 CANN 自定义算子、也不受 IFA 在 300I Duo 上 headDim≤128 的限制。
  • 修正 PFA 输入索引 : _CustomPromptFlashAttention 的 input_index_i 由 [0,1,2,4] 改为 [0,1,2,3] ,修正算子输入映射错位。
  • 修正 prefill 取 last token :原来直接取 hidden_states[:, -1:, :] (最后一个 padded 位置),但运行时会把 prefill 输入向上对齐到 16,末位可能是 padding( attention_mask==0 )。改为按 attention_mask 求有效长度后 gather 最后一个有效 token,保证 next_token 预测正确。
  • export_llm_prefill_decode / Qwen35LlmPrefill / Qwen35LlmDecode 透传 use_pfa / use_ifa 。
  1. configs/config_prefill.ini
  • input_format 引号由单引号 'ND' 改为双引号 "ND" ,与同文件其它配置项保持一致,避免转换器解析问题。
  1. README.md
  • 导出命令按硬件分列(300I Duo 不开 IFA/PFA;800I A2 开 --use-ifa --use-pfa ),参数表与注释同步说明两个开关"各自独立、仅影响对应算子",并补充性能数据等。

Which issue(s) this PR fixes:

Fixes #449


Test Plan and Test result:What scenarios were tested, and what were the verification results(Function, performance, reliability, etc.):
使用用例代码,无需新增用例


Self-checklist:(请自检,在[ ]内打上x,我们将检视你的完成情况,否则会导致pr无法合入)

likedislike
Pull Request已成功合入, 合并人@MindSpore-Bot
(感谢 xiongpan 的贡献)
Xxiongpan成员
9月1日 创建了 pull request,commit d63372d7
Xxiongpan成员
9月1日 关联了issue:[Bug]: Qwen3.5-0.8B中qwen3_5_llm_decode.onnx模型在300iduo上转换报错和README.md部分资料描述不清晰
atomgit-bot
atomgit-bot
9月1日 评论:

变更摘要

本 PR 修正 Qwen3.5-0.8B 示例在 Atlas 300I Duo 与 Atlas 800I A2 上跨硬件部署的精度/可用性问题:此前 prefill 与 decode 强依赖 CANN 自定义算子(PromptFlashAttention、IncreFlashAttention),而这两类算子在两块卡上的支持情况不同(如 IFA 在 300I Duo 上受 headDim≤128 限制)。本次改动将自定义算子改为可开关,并补齐若干正确性修正,使同一套导出/推理代码可在两块卡上均正确运行。

主要改动

  • 新增 --use-pfa / --use-ifa 开关:在 export_qwen3_5_0_8b_onnx.py 的 main() 中新增两个 argparse.BooleanOptionalAction 参数(默认关闭),分别控制 prefill 全注意力是否使用 PromptFlashAttention、decode 是否使用 IncreFlashAttention;关闭时回落到标准算子实现的手动注意力(matmul + masked_fill 布尔掩码 + softmax),不依赖 CANN 自定义算子。
  • 修正 PFA 输入索引:_CustomPromptFlashAttention 的 input_index_i 由 [0, 1, 2, 4] 改为 [0, 1, 2, 3],修正算子输入映射错位。
  • 修正 prefill 取 last token 逻辑:Qwen35LlmPrefill.forward 不再直接取 hidden_states[:, -1:, :](该位置可能是运行时向上对齐 16 产生的 padding),改为按 attention_mask 求有效长度后用 torch.gather 取最后一个有效 token,保证 next_token 预测正确。
  • 透传开关参数:export_llm_prefill_decode、Qwen35LlmPrefill、Qwen35LlmDecode 新增并透传 use_pfa / use_ifa,其中 Qwen35LlmDecode 在 use_ifa=False 时走手写注意力路径(含 GQA 的 repeat_interleave 展开与掩码 masked_fill)。
  • 配置与文档同步:configs/config_prefill.ini 中 input_format 引号由单引号 'ND' 改为双引号 "ND",与同文件其它配置项保持一致;README.md 按硬件分列导出命令并补充开关说明与性能数据。
likedislike
不准确?
atomgit-bot
atomgit-bot
9月1日 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
MindSpore-BotMindSpore-Bot成员
9月1日 添加了label:mindspore-cla/yes
此处折叠了66条消息 查看更多
司小南(机器人)司小南(机器人)成员
9月1日 删除了label:ci-pipeline-passed
司小南(机器人)司小南(机器人)成员
9月1日 添加了label:ci-pipeline-passed
xiongpan成员
9月1日 评论:

/can-review

likedislike
YeFeng_24YeFeng_24成员
9月1日 通过审查
MindSpore-BotMindSpore-Bot成员
9月1日 合入了pull request,合并节点 SHA:d9edcdbf4b130128d9f6696d317e8f61097e90cd