Skip to content

feat(qwen38): add full-length 32K MoK MXFP8 Muon SFT - #813

Merged
Lemon-412 merged 11 commits into
redai-studio:mainfrom
Lemon-412:feat/qwen38-32k-mok-muon
Nov 27, 2026
Merged

Lemon-412 merged 11 commits into
redai-studio:mainfrom
Lemon-412:feat/qwen38-32k-mok-muon

Conversation

@Lemon-412

@Lemon-412 Lemon-412 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

feat(qwen38): add full-length 32K MoK MXFP8 Muon SFT

为 Qwen38 Flash Next 新增 32 卡满长 32K 文本 SFT recipe,使用 Muon 和 MoK MXFP8 路由专家。满长 32K 的 QSA 由 DoSA boundary 选块、CuTe 执行稀疏 attention,GDN 使用 grouped FlashQLA。

Add a 32-GPU recipe for full-length 32K text SFT on Qwen38 Flash Next with Muon and MoK MXFP8 routed experts. For full-length documents, QSA uses DoSA boundary selection and CuTe sparse attention. GDN uses grouped FlashQLA.

What

  • 新增 Qwen38 Flash Next 满长 32K 文本 SFT 启动脚本,提供 TP1/PP1/CP1/EP8、Muon 和 MXFP8 的 32 卡 recipe。
  • 在 Qwen38 Flash Next 的 Bridge 模型构造和精度配置中接入 MoK 路由专家的 MXFP8 权重初始化,支持分层分布式 Muon 和参数收集重叠。
  • 为 mixed QSA 增加 DoSA 选择器入口,并在 Blackwell 镜像的 Megatron 补丁中接入 GDN 的 grouped FlashQLA 路径。

Why

Qwen38 Flash Next 在满长 32K 文本 SFT 中需要同时使用分布式 Muon、MoK MXFP8 和参数收集重叠。主干的 FP8 精度检查会拒绝这一组合,mixed QSA 入口也无法选择已有的 DoSA 实现。长序列 GDN 在调用 gated delta rule kernel 前还会显式复制 Q/K heads。这个 PR 补齐三处接入,并提供一个可直接启动的 32 卡 recipe。

How

  • 专家和投影精度。Bridge 在构造模型前将 MXFP8 参数收集配置传给 MoK。MoK 初始化路由专家权重,原生 TE 投影继承全局 MXFP8。Megatron 解析参数时会把 Muon 的分布式优化器开关转换成 layer-wise 标志,因此用转换后的标志判断该路径。
  • QSA 选择器。在 CP1 的 mixed selector 中接入已有的 DoSA。recipe 为满长文档选择 CuTe 稀疏 attention,可直接消费 DoSA boundary 返回的无序 block ID。
  • GDN。标准 headwise 路径向 FLA 传入分组 Q/K,由 FLA 按设备、形状与环境开关选择 FlashQLA 或回退实现。例如 2 个 Q/K 头对应 6 个 V 头时,索引为 [0, 0, 0, 1, 1, 1],与显式 repeat_interleave 一致。启用归一化时,FlashQLA 的 autograd wrapper 先调用 l2norm_fwd,再执行 grouped GDN。Qwen3.5 专用路径沿用自己的预处理。
  • 训练配置。4 节点 × 8 卡,TP1/PP1/CP1/EP8/ETP1,GBS128/MBS1,48 层、MTP0,每两层全量重算。每步 4,194,304 个输入 tokens。短跑沿用 2023 步的学习率计划,避免改变前 20 步的学习率。

Testing

c2b405fb 在 32 卡上完成 20 个满长 32K 更新。与上一版 7c20557a 使用相同的模型权重、输入、逻辑 packing、种子和学习率计划。每步 4,194,304 tokens,20 步共 83,886,080 tokens。逐步 loss、梯度范数和 4 组学习率全部一致。目标设备日志确认 FLA 将 GDN 分发给 FlashQLA。Ray 作业最终状态为 SUCCEEDED。最后一个更新的 checkpoint 已落盘,包含 32 个分片与分布式元数据,latest 指针为 19。本轮未执行断点续训。

满长 32K,第 3–19 步 上一版 7c20557a 当前 c2b405fb
整步吞吐(tokens/s/卡) 5463.25 5534.81
整步 MFU 10.257% 10.391%

整步吞吐按该窗口的总输入 tokens 除以总耗时及 32 张卡。此次实测较上一版高 1.31%。此前独立实验在相同窗口为 5568.06 tokens/s/卡。

  • 本地全量 pre-commit 和 139 项相关 CPU 回归通过。按镜像顺序从固定版本源码应用 common、cu13 和 blackwell 三段 Megatron 补丁,各段均通过 git apply --check 并成功应用。
  • 给提交环境设置互相冲突的 Ray 地址,验证节点发现和作业提交均使用 RAY_JOBS_ADDRESS。启动脚本默认等待终态,driver 和训练 actor 均收到入口补齐的动态库路径。
  • GitHub pre-commit、CPU 单测、单卡与四卡 GPU 单测、两项 GPU 集成、一项 NPU 集成及文档构建全部通过。PR 检查记录

Type of Change

  • 缺陷修复
  • 新功能
  • 破坏性变更
  • 文档更新
  • 重构
  • 性能优化
  • 构建变更

Initialize native MoK MXFP8 weights through Bridge and route mixed QSA through the DoSA boundary selector. Enable grouped FlashQLA on Blackwell and keep the standard BF16 vocabulary projection.
Megatron normalizes the distributed optimizer flag for Muon before the model is constructed. Validate that normalized mode for native MXFP8 weights and cover the startup failure with a regression test.
@Lemon-412
Lemon-412 requested review from a team and RexFlux November 26, 2026 16:14
@rai-studio-bot

rai-studio-bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for contributing to Relax, @Lemon-412! 感谢你为 Relax 做出贡献!

📚 Contribution guide / 贡献指南

Describe the problem, your changes, and how you validated them. Keep each PR focused and run pre-commit run --all-files before submitting.

请说明问题、改动和验证方式,保持 PR 聚焦,并在提交前运行 pre-commit run --all-files。

English contribution guide · 中文贡献指南

🛠️ CI commands / CI 指令
Command / 指令 Usage / 用途
/rerun Retry failed CI / 重跑失败的 CI
/rerun <target> Rerun a workflow or check / 重跑指定 workflow 或检查
/cancel <workflow> Cancel an entire workflow / 取消整个 workflow
/help Show commands and targets / 查看指令和 target
/review Request a code review / 请求代码 review

Put one command on the first line of a new PR comment. Rerun/cancel require PR authorship or repository write access.

在新 PR 评论的首行写一条指令。PR 作者或有仓库写权限的贡献者可以重跑、取消 CI。

CI usage and targets · CI 用法与 target

🔎 Merge requirements / 合入条件

GitHub:✅ 满足合入条件

Requirement / 条件 Status / 状态
审批人数 ✅ 1/1 · 至少 1 位有仓库 write 或更高权限的人 Approve · 已审批:NINGBENZHE
团队审批(relax-block-reviewers) ✅ 1/1 · 已审批:NINGBENZHE
CI ✅ 已通过

@rai-studio-bot

rai-studio-bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Nyanpasu 审查看板

审查状态: ✅ 已通过

审查版本: 8e5b76e

目标分支: main

F16 已解决。新版测试从 CP1 生产入口覆盖回退分块上限,H20 单卡 CI 通过。

审查阶段进度范围与结果
常规审查 ✅ 已完成 复核了唯一变动文件及对应的生产调用。测试使用真实 radix,并独立推导全等分数下的预期选块结果。
深度审查 ✅ 已完成 Codenip 五项通过。已核对 H20 单卡日志中本用例的通过记录。

审查发现

待处理
编号 严重性 问题状态规则来源
暂无待处理的记录。
已解决或已取代
编号 严重性 问题状态规则来源
F1 Medium severity 默认等待 Ray job 的终态 ✅ 已解决 Ray 提交默认阻塞
F2 Medium severity 写入可供同一实验恢复的 checkpoint ✅ 已解决 可恢复的训练 checkpoint
F3 Medium severity 保留 Ray 入口组装的动态库搜索路径 ✅ 已解决 —
F4 Medium severity 将文档指定的 Ray Jobs 地址传给提交命令 ✅ 已解决 Ray 2.56.1 Job 地址选项
F5 Low severity 移除 MoK 默认路径对 HybridEP 的强制检查
精简建议(非阻塞)
✅ 已解决 —
F6 Medium severity 复用 FLA 的 FlashQLA 调度和回退
精简建议(非阻塞)
✅ 已解决 FLA 0.5.2 的 FlashQLA 适用条件
F7 Medium severity 为 Qwen3.5 优化路径保留原有归一化约定 ✅ 已解决 Qwen3.5 GDN wrapper 的归一化约定
F8 Low severity [experimental · TST005] 保留 Muon 配置的行为断言
精简建议(非阻塞)
✅ 已解决 —
F9 Low severity [experimental · DOC005] 将两组对照的说明放到 PR 验证记录 ✅ 已解决 —
F10 Low severity [experimental · PR001] 在 PR 说明中交代分组映射和归一化位置 ✅ 已解决 —
F11 Low severity [experimental · REF007] 直接读取 TransformerConfig 声明的字段
精简建议(非阻塞)
✅ 已解决 —
F12 Medium severity 核实集群一致后再执行显式清理 ✅ 已解决 —
F13 Medium severity 将清理用的 Serve 地址解析为 HTTP(S) ✅ 已解决 —
F14 Medium severity 保留先调用共享入口时的 API 地址优先级 ✅ 已解决 —
F15 Medium severity 让布尔开关的校验和读取采用同一规则 ✅ 已解决 环境变量的类型、默认值和读取方式
F16 Low severity [experimental · TST005] 从 CP1 入口验证回退分块上限 ✅ 已解决 测试质量与验证准则

改进建议(非阻塞)

相关 PR

💡 实现与合入建议

#815 可复用本 PR 的 MoK 精度校验和 Ray 库路径保留方式。两个训练配方可独立合入。

https://github.com/redai-studio/Relax/pull/815 · 04c263fd312925bd2877fd449b04f7d09b89a94a · 目标分支 main

实现取舍: 构造前传递 MoK 权重配置,并在通用精度校验后仅为 MoK、MXFP8、Muon 和 layer-wise 优化器组合跳过重复的模块配置。运行时动态库路径优先读取 ray-job.sh 已补齐的值。

当前 PR 调整: 本 PR 保留现有的精度校验与路径合并。#815 可复用这两处逻辑,并根据长上下文配置保留各自的 CP 对齐、MoK 容量及 DoSA 参数。

合入顺序: 两个配方可按各自准备情况合入。后合入的一方应整合同一 model_provider.py 中的 MoK 初始化分支,保留精度冲突检查。

依据与验证范围: 对照固定版本的源码与讨论 https://github.com/redai-studio/Relax/pull/815#discussion_r4715523649 和 https://github.com/redai-studio/Relax/pull/815#discussion_r4715523017 。本 PR 的库路径合并经脚本 dry-run 核对。跨配方合并后的 GPU 行为仍待验证。

Powered by Nyanpasu with gpt-6.2-sol high, please check the suggestions carefully.

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

初步审查意见

已核对 7c20557a 的启动脚本、模型初始化、QSA 选择器及 GDN 补丁。启动脚本的提交与恢复行为需要调整。上游内核与优化器的兼容性仍在核查,当前提交尚缺完整的 32 卡训练步验证。

审查看板

Powered by Nyanpasu with gpt-6.2-sol high, please check the suggestions carefully.

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

补充审查意见

进一步核对了固定版本的 FLA 和 FlashQLA。新增开关需要保留 FLA 对输入形状的检查和回退,并与已有 Qwen3.5 优化路径的归一化约定兼容。两个触发条件均已标在补丁对应行。

审查看板

Powered by Nyanpasu with gpt-6.2-sol high, please check the suggestions carefully.

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

审查完成,有补充意见

已完成 7c20557a 的审查,并补充了测试断言、实验注释和 GDN 说明的行内意见。该提交的必需 CI 已通过。32 卡 MoK、MXFP8、Muon、DoSA 和 FlashQLA 组合仍缺完整训练步及数值对照结果。

审查看板

Powered by Nyanpasu with gpt-6.2-sol high, please check the suggestions carefully.

@rai-studio-bot rai-studio-bot mentioned this pull request Nov 27, 2026
7 of 13 tasks
Lemon-412 and others added 2 commits November 27, 2026 13:47
Wait for Ray's terminal status by default, honor the Jobs address, keep
the launcher library paths for the driver and actors, and save to the
resume directory. The MoK path has no HybridEP installation dependency.

Let FLA select the grouped GDN backend. For two Q/K heads and six V
heads the indices are [0, 0, 0, 1, 1, 1], matching repeat_interleave.
With normalization enabled the FlashQLA wrapper applies l2norm_fwd
before grouped GDN. Keep the Qwen3.5 preprocessing contract intact.

20-step comparison on 7c20557 used identical logical packing, model,
seed, data and LR. Max absolute loss delta was 0.01440. Steps 3–19
averaged 5463.25 vs 5568.06 tokens/s/GPU. This measurement predates
the FLA dispatch change.

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

复核完成,有补充意见

已核对 8d43b845 的修订并确认 8 项既有问题已修复。Ray 地址和 GDN 的 PR 说明仍待完善,本轮补充了一条配置读取建议。提交说明记录的 20 步对照使用上一版本,当前 GDN 调度路径仍缺目标 Blackwell 验证。

审查看板

Powered by Nyanpasu with gpt-6.2-sol high, please check the suggestions carefully.

+ and self.config.linear_cp_mode == "headwise"
+ and not self.gdn_pre_gated_delta_rule_fusion
+ and not self.config.deterministic_mode
+ and not getattr(self.config, "_relax_qwen35_optimized", False)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Low severity P3 · [experimental · REF007] 直接读取 TransformerConfig 声明的字段

Blackwell 段应用前,镜像已应用 common 段。该段为 TransformerConfig 声明了 _relax_qwen35_optimized: bool = False,这里可直接读取该字段,沿用同一处默认值。字段声明 · 镜像应用顺序

Suggested change
+ and not getattr(self.config, "_relax_qwen35_optimized", False)
+ and not self.config._relax_qwen35_optimized
Powered by Nyanpasu with gpt-6.2-sol high, please check the suggestions carefully.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已核对 c2b405fb,这里已改为直接读取字段。将镜像的 common、cu13 和 Blackwell 段依次应用于固定版 Megatron 后,TransformerConfig 的默认值和 GDN 调用处均通过语法检查。

Powered by Nyanpasu with gpt-6.2-sol high, please check the suggestions carefully.

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

复核完成,有补充意见

已确认 c2b405fb 修复默认 Ray 启动路径和 GDN 字段读取。补充指出显式启用清理时的集群寻址问题。隔离启动和定向补丁检查已通过,尚未连接真实 Ray 集群或在目标 Blackwell 上运行新版训练。

审查看板

Powered by Nyanpasu with gpt-6.2-sol high, please check the suggestions carefully.

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

复核意见

43621560 已在原先的地址冲突场景下阻止清理。共享入口仍需兼容 Ray Jobs 接受的 GCS 地址,相关问题已标注在地址导出行。隔离脚本验证了清理顺序,未访问真实集群。

审查看板

Powered by Nyanpasu with gpt-6.2-sol high, please check the suggestions carefully.

Comment thread scripts/entrypoint/ray-job.sh Resolved

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

复核完成,有补充意见

43621560 已在 F12 报告的地址冲突场景下阻止清理。共享入口还有两处兼容问题,分别涉及 Serve 的 HTTP(S) 地址和显式 API 地址的优先级。已在 Serve 原讨论中更正其影响。隔离验证使用了桩,无需连接真实集群。

审查看板

Powered by Nyanpasu with gpt-6.2-sol high, please check the suggestions carefully.

Comment thread scripts/entrypoint/ray-job.sh Resolved

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

复核通过

e1ea8b4 已修复 Serve 地址解析(F13)和显式 API 地址优先级(F14)。隔离对照覆盖了两种原始触发场景,并确认集群不一致仍会在清理前退出。Codenip 复核无新增问题。隔离验证使用了桩,未连接真实 Ray 集群。

审查看板

Powered by Nyanpasu with gpt-6.2-sol high, please check the suggestions carefully.

@NINGBENZHE NINGBENZHE left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

在 e1ea8b4c 上补两条非阻塞建议,分别涉及 recipe 的环境变量和 DoSA 回退的临时显存开销。

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

增量复核意见

21b76d7 补全了配方环境变量注册,并限制了 CP1 DoSA 回退的单次评分行数。新注册的布尔开关仍有一处校验与实际读取不一致,已标注在注册处。

审查看板

Powered by Nyanpasu with gpt-6.2-sol high, please check the suggestions carefully.

Comment thread relax/utils/env.py Resolved

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

增量复核意见

20acec33 已让 F15 涉及的布尔值在校验和读取时含义一致。CP1 回退用例还有一条非阻塞覆盖建议,已标注在测试中。

审查看板

Powered by Nyanpasu with gpt-6.2-sol high, please check the suggestions carefully.

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

复核通过

8e5b76ec 的测试已通过 CP1 生产入口覆盖 DoSA 回退分块上限和选块结果,F16 已解决。H20 单卡 CI 上该用例通过,Codenip 无新增问题。H20 单卡 CI

审查看板

Powered by Nyanpasu with gpt-6.2-sol high, please check the suggestions carefully.

@NINGBENZHE NINGBENZHE left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

已复查 8e5b76ec。严格环境校验与 CP1 DoSA 回退分块两项均已修复,并确认相关 CPU 和 H20 CI 用例通过。

@Lemon-412
Lemon-412 merged commit f642ddb into redai-studio:main Nov 27, 2026
17 checks passed
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.

3 participants