Skip to content

perf: accelerate Qwen3.5 OpenR1MM training - #454

Draft
yuanlehome wants to merge 5 commits into
redai-studio:mainfrom
yuanlehome:perf/qwen35-openr1mm-e2e
Draft

yuanlehome wants to merge 5 commits into
redai-studio:mainfrom
yuanlehome:perf/qwen35-openr1mm-e2e

Conversation

@yuanlehome

@yuanlehome yuanlehome commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What

优化 run-qwen35-35B-A3B-8xgpu-openr1mm-r3 的端到端训练性能,并将权重更新优化改为根据模型布局、训练拓扑和接收端能力自动选择。

  • Qwen3.5 历史配对实验中,包含卸载和通信组生命周期的权重同步中位耗时 12.17 → 8.60 秒,降低 29.3%;同边界下比 Miles 原生同步核心低 31.2%。
  • 当前提交 f3b4246 补测了 12 组单层装载组件:收益随专家数量、MoE TP/EP/DP 和 runner 布局变化,结果及适用范围见下表。组件加速不等于完整同步或训练吞吐加速。
  • Recipe 保持 batch512、packing8192、Rust sgl-router,保留训练状态卸载/恢复、通信组销毁/重建和每轮完整权重更新。

Why

Qwen3.5-35B 的 40 层、每层 256 个 gated experts 会产生 30720 个 gate/up/down 专家条目。旧路径在转换后的细粒度元数据、flatten/repack、逐专家接收装载与切片上花费较多时间。仅调整 collective 或 batch,无法消除这些固定开销。

How

  • BF16 expert gather:Bridge 在实际 owner 上转换专家权重,按 owner 合并 payload,缓存 CPU 布局描述;每轮仍使用当前 EP 通信组和独立 GPU 缓冲区。
  • 批量异步 TP gather:Bridge 非 expert 参数按桶发起 gather 后统一等待。GDN 的 conv/in-proj 分别从 3/6 次 component gather 合并为一次,再恢复正确分量顺序;普通参数的有效字节量不因此减少。
  • Packed expert + native loading:满足条件时,每层输出两张专家投影,40 层专家条目由 30720 → 80。发送端按接收端真实 EP/MoETP/MoEDP 生成本地分片,直接原位写入 w13_weight / w2_weight,避开逐专家 HF loader 和中间 flatten。
  • 通用能力选择:按 canonical Bridge mapping、BF16 dtype、实际 scheduler 参数、runner 布局和 buffer 预算判断;支持 Triton、DeepGEMM、FlashInfer CUTLASS,后者保留其 [up, gate] 顺序。A2A backend 不再作为权重布局白名单;组合是否可运行仍由 SGLang 校验。条件不满足时回退兼容路径,不新增环境变量开关。
  • 更新完整性与配置精简:IPC reader 完成前保留 backing storage;保留 pause/flush/version/resume 流程。默认关闭 shared-expert fusion;SGLang flush_cache 清理视觉 embedding cache,删除 recipe 的 VLM cache=0 覆盖。移除无效 reference 前向,符合条件时复用训练前向 logprob;保留 DeepEP 和 packing 调整。已移除本分支的 CUTLASS grouped-GEMM opt-in 修改。

已有的两 chunk IPC overlap、raw iterator 的批量异步 gather 不计为本 PR 新增收益;本次也没有消除 Gloo/Ray/HTTP 控制通道或 EP 完整权重收集。

Testing

  • 当前提交相关测试 432 passed、2 skipped;跳过项为 CPU 环境下的 CUDA-only MXFP4 检查及安装版本缺少 LoRAMerge。

  • 既有 GPU 正确性矩阵通过 8 个场景,覆盖 Triton / DeepGEMM / CUTLASS、EP、MoETP、MoEDP 和 DeepEP normal/low-latency:60 次 rank 级权重更新、234 次输出检查、54 次 CUDA Graph 检查通过。DeepEP normal 的另外 6 次因动态接收计数未执行 CUDA Graph 检查,仅验证 eager 路径。

  • 本次新增 12 组装载性能测量全部完成,正确性检查通过,逐位比较接收权重并检查参数地址不变。

  • FlashInfer A2A 在当前 Linux 5.4 主机初始化时遇到 pidfd_getfd: ENOSYS,未形成可运行性能结论。DeepEP 的正确性通过不代表已测得其完整同步加速。

  • 通用化重构曾在 batch512 / packing8192 / sgl-router 下完成冻结输入和完整周期回归。当前最终提交未重跑完整训练、长期收敛或正式健康分验收;本次补测范围是下面明确列出的装载组件。

  • pre-commit run --all-files passes

  • Tests pass (pytest tests/) — 本轮执行针对性测试,未执行整个测试目录

  • New tests added (if applicable)

  • Documentation updated (if applicable)

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • CI/CD or build changes

Reduce colocated GRPO overhead with a guarded inline-logprob path and
BF16 expert gathering, asynchronous TP/GDN gathers, packed experts and
TP-local direct loading.

Enable DeepEP, CUTLASS grouped GEMM and Rust sgl-router for OpenR1MM;
set global batch 512 and packing 8192. Avoid the intermediate ASCII
copy when decoding R3 routing data.

Preserve trainer offload/reload, process-group reconstruction and full
weight synchronization. Add regression coverage for the optimized paths.

Validation:
- Full pre-commit checks; targeted CPU tests: 259 passed, 2 skipped
- Five full batch512/packing8192 cycles without OOM or allocation retries
- Packing8192 numerical differences accepted after frozen-input replay
@yuanlehome
yuanlehome requested review from a team and a balanced review from Copilot October 19, 2026 09:07
@yuanlehome
yuanlehome marked this pull request as draft October 19, 2026 09:07
@rai-studio-bot

rai-studio-bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for contributing to Relax, @yuanlehome! 感谢你为 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:📝 请转为 Ready for review

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

An unresolved training blocker needs correction, and distributed GPU weight-transfer changes require final human review.

1 open issue
What changed in this PR

Accelerates Qwen3.5 OpenR1MM training through guarded inline log-probabilities and optimized weight synchronization.

Changes:

  • Adds asynchronous gathers, packed BF16 experts, and TP-local loading.
  • Tunes the launcher for batch 512, packing 8192, and DeepEP.
  • Adds regression coverage and reduces routing-data decoding overhead.
File Description
tests/​backends/​megatron/​weight_update/​test_qwen35_packed_experts.py Tests packed expert ordering and lifetime.
tests/​backends/​megatron/​weight_update/​test_qwen35_direct_experts.py Tests direct shards and receiver guards.
tests/​backends/​megatron/​weight_update/​test_expert_routing.py Updates iterator fixtures.
tests/​backends/​megatron/​weight_update/​test_bf16_expert_gather.py Tests gather layouts and group replacement.
tests/​backends/​megatron/​weight_update/​test_async_gdn_weight_gather.py Tests asynchronous tensor reconstruction.
tests/​backends/​megatron/​test_colocate_inline_log_probs.py Tests eligibility and zero-KL inputs.
scripts/​training/​multimodal/​run-qwen35-35B-A3B-8xgpu-openr1mm-r3.sh Enables optimized training settings.
relax/​engine/​rollout/​sglang_rollout.py Removes intermediate ASCII encoding.
relax/​backends/​megatron/​weight_update/​update_weight_from_tensor.py Integrates validated direct expert loading.
relax/​backends/​megatron/​weight_update/​qwen35_packed_experts.py Adds packed expert export.
relax/​backends/​megatron/​weight_update/​qwen35_direct_experts.py Adds TP-local shards and typed dispatch.
relax/​backends/​megatron/​weight_update/​hf_weight_iterator_bridge.py Integrates optimized gathers.
relax/​backends/​megatron/​weight_update/​common.py Preserves GDN component ordering.
relax/​backends/​megatron/​weight_update/​bf16_expert_gather.py Adds owner-balanced BF16 gathering.
relax/​backends/​megatron/​loss.py Supports zero-KL shapes without actor log-probabilities.
relax/​backends/​megatron/​actor.py Guards skipping the old-policy forward pass.

Review effort: Balanced

Comment thread relax/backends/megatron/actor.py Outdated
"max_staleness": 0,
"update_weights_interval": 1,
"partial_rollout": False,
"rl_partial_rollouts": 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.

Medium severity P2 · 移除不存在的参数门槛,让自动复用实际生效

在 7c216d3 中,这个条件移到了 inline_log_probs.py:32,问题仍未解决:真实 Namespace 不含 rl_partial_rollouts(SGLang 参数统一加 sglang_ 前缀),所以第 74 行总会将其判为不匹配。现在结果是静默返回 False,更新后的 Qwen 配方仍每轮执行本应跳过的 actor 前向。

请移除这项冗余检查,并增加字段缺省的回归用例;现有 partial_rollout=False 检查已覆盖 Relax 的开关。当前测试手工设置 rl_partial_rollouts=False,掩盖了真实入口的失败。

Select expert gathering, TP-local loading and inline log-prob reuse from
runtime configuration and receiver capabilities. Consolidate expert layout
and IPC handling, remove experiment-only switches, and retain bounded
Bridge fallbacks for unsupported layouts.

Preserve the accepted batch512, packing8192 and sgl-router configuration
with regression coverage for loading, fallback and process-group reuse.
Use importorskip for weight-sync tests that require Megatron Core,
Megatron Bridge or SGLang. Guard only the backend-dependent inline
log-prob test so its pure CPU eligibility coverage still runs.

Keep the full regression coverage active in training environments
with the optional backends installed.
@yuanlehome
yuanlehome marked this pull request as ready for review October 19, 2026 12:38
@rai-studio-bot

rai-studio-bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Nyanpasu 审查看板

审查状态: 💬 已完成 · 有补充意见

审查版本: 0af6420

目标分支: main

已完成 0af6420 相对新基线的 25 文件范围及增量交互审查,未确认新缺陷。原 P2(不存在的参数使自动 logprob 复用失效)尚未修改,继续保留。

审查阶段进度范围与结果
常规审查 ✅ 已完成 已核对新基线、依赖、相关调用及可复用范围;补丁适配与差异检查通过。当前提交 Python 单测、pre-commit 和三项集成 CI 已通过,读取时 H20 检查仍进行中:https://github.com/redai-studio/Relax/actions/runs/39385310701 。
深度审查 ✅ 已完成 已核查分块预算及全专家覆盖、Bridge 输出、EP/TP/MoEDP 范围交集、custom loader 契约、空 chunk 格式及 IPC storage/ACK 生命周期。Python 3.12.3、PyTorch 2.11.0+cu129、无 CUDA 环境下,4 个精确用例通过:partial_projection_empty_owners_and_uneven_gather(9-14 与 22-24)、owner_balanced_ranges_share_one_storage_and_one_collective(1 owner)及 large_experts_can_use_an_entire_round_budget。仅建立 CPU 分块与模拟 collective 契约;真实分块 CUDA IPC、Bridge 端到端、卸载恢复及峰值显存/性能未独立验证。旧提交作者实验不作为当前分块路径的实机证据。

审查发现

待处理
编号 严重性 问题状态规则来源
F1 Medium severity 移除不存在的 rl_partial_rollouts 门槛,让自动 logprob 复用实际生效 🚧 未解决 —
已解决或已取代
编号 严重性 问题状态规则来源
暂无已解决或已取代的记录。
提交范围 · 接收 25 · 建议移出 0 · 待确认 0

接收 25 个文件 · 建议移出 0 个文件 · 待确认 0 个文件。移出与待确认部分暂停深审,不代表审查通过。

文件结论仓库维护必要性依据替代去向或方案
relax/backends/megatron/actor.py
relax/backends/megatron/loss.py
relax/backends/megatron/weight_update/bridge_converter.py
relax/backends/megatron/weight_update/common.py
relax/backends/megatron/weight_update/expert_gather.py
relax/backends/megatron/weight_update/expert_layout.py
relax/backends/megatron/weight_update/hf_weight_iterator_bridge.py
relax/backends/megatron/weight_update/ipc.py
relax/backends/megatron/weight_update/update_weight_from_tensor.py
relax/backends/sglang/sglang_engine.py
relax/backends/sglang/weight_loader.py
relax/engine/rollout/sglang_rollout.py
relax/utils/training/inline_log_probs.py
接收 既有同步与 logprob 优化;新增分块专家传输和接收端范围装载位于对应生产模块。 PR #454 优化权重更新并保持完整更新、回退与训练语义。 沿用 backend 与 training 工具目录,新增 loader 与 SGLang 接入相邻。
tests/backends/megatron/test_colocate_inline_log_probs.py
tests/backends/megatron/weight_update/test_async_gdn_weight_gather.py
tests/backends/megatron/weight_update/test_auto_weight_sync.py
tests/backends/megatron/weight_update/test_bf16_expert_gather.py
tests/backends/megatron/weight_update/test_expert_capabilities.py
tests/backends/megatron/weight_update/test_expert_layout.py
tests/backends/megatron/weight_update/test_expert_routing.py
tests/backends/megatron/weight_update/test_expert_slices.py
tests/backends/megatron/weight_update/test_packed_experts.py
tests/backends/sglang/test_sglang_engine.py
接收 针对实际生产 gather、范围切片与装载协议的持久回归覆盖。 PR #454 正确性、并行布局和兼容回退契约。 对应模块测试目录适合维护这些回归。
scripts/training/multimodal/run-qwen35-35B-A3B-8xgpu-openr1mm-r3.sh
接收 既有 Qwen3.5 OpenR1MM 训练配方是明确优化目标。 PR #454 What/Why。 保持现有入口位置。
docker/patch/sglang/v0.5.17.patch
接收 固定 SGLang 版本缓存清理补丁,延续已审查职责。 PR #454 多模态训练的完整权重更新契约。 保留既有版本补丁机制。
Powered by Nyanpasu with gpt-6.1-sol xhigh, 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.

审查完成 · 有补充意见

已完成 7c216d3 的变更及相关调用契约审查,原线程中的性能问题仍待处理。当前 CI 检查均通过;本次未运行本地测试,也未独立复现 Qwen3.5 配方的端到端数值、显存、性能及故障恢复。

审查看板

Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

Derive native BF16 expert shards from receiver MoE TP, EP and DP, and support
Triton, DeepGEMM and FlashInfer CUTLASS independently of the A2A dispatcher.
Preserve native gate/up order and fall back for unsupported weight layouts.

Use scheduler-resolved defaults, disable shared-expert fusion by default,
and clear visual embeddings during cache flush. Remove redundant recipe
overrides and the opt-in CUTLASS grouped-GEMM setting.

Validation: all-files pre-commit; 432 tests passed, 2 environment skips;
8 multi-GPU cases passed, including DeepEP normal and low-latency.
The Qwen3.5 TP2 packing/copy microbenchmark showed no regression.
FlashInfer A2A initialization remains blocked by the host Linux 5.4 kernel.

@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.

增量审查完成 · 保留原意见

已完成 f3b4246 的 MoE 布局扩展、运行时配置识别及缓存清理改动审查,未确认新缺陷;原问题仍待处理。补丁适配检查通过,新提交尚无单测/GPU 回归结果,本轮未运行本地测试。

审查看板

Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

Split large BF16 expert projections into owner-balanced chunks within the
sync buffer budget. Negotiate SGLang expert-slice loading automatically
and copy into existing parameters while preserving the small-layer path.

Merge main and retain both server lifecycle and expert-sync regression
tests. Keep existing offload, process-group and IPC reader lifetimes.

Validation: all-files pre-commit; 877 tests passed and
18 environment-dependent tests skipped after merging main.
Prior multi-GPU validation covered Triton, DeepGEMM, CUTLASS, DeepEP,
cross-process CUDA IPC and repeated updates with exact reference outputs.

@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.

增量审查完成 · 保留原意见

已完成 0af6420 的分块专家传输、范围装载及基线合入交互审查,未确认新缺陷;原问题仍待处理。4 个精确 CPU 用例通过,Python 单测和集成 CI 已通过;真实分块 CUDA IPC、卸载恢复及性能仍未独立验证。

审查看板

Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

@yuanlehome
yuanlehome marked this pull request as draft October 20, 2026 09:27

This branch has not been deployed

No deployments
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