Skip to content

2025年昇腾AI创新大赛-昇思模型开发挑战赛(S1赛季)--MoE赛题--emmm队提交#116

Open
VikingDeng wants to merge 3 commits intomindspore-lab:devfrom
VikingDeng:emmm-dev
Open

2025年昇腾AI创新大赛-昇思模型开发挑战赛(S1赛季)--MoE赛题--emmm队提交#116
VikingDeng wants to merge 3 commits intomindspore-lab:devfrom
VikingDeng:emmm-dev

Conversation

@VikingDeng
Copy link
Copy Markdown

No description provided.

@@ -0,0 +1,201 @@
# README
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为你列出详细的心路历程表示点赞, 这个的价值极大.
为了更便于其他开发者学习, 有一些格式问题需要注意.我列在相应的地方了.
首先就是把所有的patch都跟踪起来实在没啥必要感觉, 10个patch也不方便看,直接打成zip吧


在无精度误差的情况下提速这两个模型的prefill,decode和显存峰值

![img](https://kxqaj5kr937.feishu.cn/space/api/box/stream/download/asynccode/?code=NWIwMTIzNjY4NDhkMTI4ZmYxNTFmMWNhOWIyNWRlYzZfeldtbk84b3lhUWVNYjJCZlRtT05TZ0JubU1hMzB0S3RfVG9rZW46WU10NmJsWXFab01CaER4NFlHT2NZRzJHbjJuXzE3NjQ3NTAyNDg6MTc2NDc1Mzg0OF9WNA)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我在github上view file的时候无法加载这个图片, 点击开链接也是显示Error Fetching Resource 可以直接把这个图片也提交一下. 放到当前目录的images下面


## 最终成绩

![img](https://kxqaj5kr937.feishu.cn/space/api/box/stream/download/asynccode/?code=Zjk2MzEzNmNhYWUxODQ5NzI1NTNhODRmMjhmMDljMGZfeWNuZ0tzT3JBcHBlY0Z1ZnFJWHRNczRGWnd1UWFOaGdfVG9rZW46QVRXVWJGeUpGb2k5R094WmxuVGM5TUdEbmxmXzE3NjQ3NTAyNDg6MTc2NDc1Mzg0OF9WNA)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个链接同上

- 官方接口 `mindspore.ops.flash_attention_score`会带来一定的精度误差,具体而言qwen的prompt2会mismatch
- 算子融合
- F.rms_norm 不仅没加速还带来了精度误差(应该是qwen的prompt1会mismatch),遂直接放弃
- 但是我没太理解会议里面讲的要比较下放损耗和融合算子加速效果,我个人仍然觉得这应该要work,但是却没有
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没看懂这句, 融合算子精度对齐的话应该是没有缺陷的.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我猜测可能是进入F.rms_norm前所必须做的精度转化操作导致的,虽然我当时尝试了float32也还是有mismatch

- 一开始打算用分桶填充策略,设置 `seq_len = [1,2,4,8,..,128]`的桶来多次调用模型生成来生成这些尺寸的图,为输入的prompt寻找恰好不小于他的桶进行padding触发图复用,但是毫无效果,于是开始探索图复用的条件,网上有说法是需要 `@mindspore.jit`即时编译/`Graph mode`静态图模式才能生成可以复用的图,于是进入下一步测试
- @mindspore.jit:基本用不了,对于网络模型底层的try-except控制流,jit不支持这种低效分支,而我们又不大可能去修改底层的控制流(太多),遂放弃
- Graph mode:经过我用简单网络的多次测试(充分预热,多次测试取平均),Graph模式比Pynative模式慢10倍左右,匪夷所思,初步怀疑是没触发图复用所以编译开销也算里面了(也就是单纯用Graph跑一次不会建立图?要显性调用什么函数或者装饰器吗),遂半放弃
- static-cache :没做成功,因为需要把动态cache 换成 static cache,bug较多,时间上不允许,而且直播的时候说提升不大。
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只是我在llama上试了下感觉提升不大. static cache本质还是为了静态图跑, 你上面静态图没加static cache 每次都重新编译的话, 可能就会很慢了

Copy link
Copy Markdown
Author

@VikingDeng VikingDeng Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graph模式是必须配合static-cache一起用吗,我还以为启用这个模式之后他会自己做图和编译的复用

- Profiler
- 这是一个很好的工具(疑似),但是直到最后都不知道如何使用,一方面是断点设置和信息收集的问题,但这个问题不大
- ![img](https://kxqaj5kr937.feishu.cn/space/api/box/stream/download/asynccode/?code=ODNmOTFhMDg2NjZjYmJmODgwMjBlNzVjYTE1MWFiMzRfTTh1S1pnUVZXbWdPRGU0MGhSREh5TU05ZkRaNEJCMGZfVG9rZW46VmFIRWJnMDlob1FUV294YktYZGNTNklqbnlmXzE3NjQ3NTAyNDg6MTc2NDc1Mzg0OF9WNA)
- 最重要的是这个页面我只看到NPU的free/compute比值很大,除此之外不知道如何分析来调优了,要是能看**别人实际调优一遍肯定会好很多,求教程!!**
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试代码的计算负载太低了, host瓶颈严重, 因此free的比例就很大. 怎么优化, 就得一点点放大然后看对应的是代码什么操作了, 说实话我也没有很明白.


## 收益点

| DeepseekMoe + Qwen moe都进行MoE模块前向优化,decode直接遍历激活专家 | 总分的具体收益估计是从100->120 |
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你这个标题是不是错了? 这一某一行的内容吧, 建议改一下标题, 另外这个表现在可读性比较差, 建议优化下增加几列

Image

## 总结

- 对于精度优化比赛,不应该一上来就花费大量时间在框架本身优化、常用优化等上,应该先通过充分测试找到**主要矛盾**,因为一般这种比赛都会有侧重点,比如这个比赛就是moe部分,如果第一天我就能测试出moe的时间占比如此浮夸,我想我就不会把时间放在细枝末节上面
- 对于调试工具(如Profiler等),这是辅助完成第一步的,很有学习的必要,这种可视化工具分析的能力或者输出、断点分析能力将是打比赛的重要能力,说是最重要也不为过,这样才能有的放矢 No newline at end of file
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最后, 感谢你对比赛经历和优化过程的详细记录, 非常感谢你对本仓的贡献!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants