Skip to content

feat(opd): support multi-node teacher and rollout engines in MultiEngineManager - #450

Merged
SigureMo merged 1 commit into
mainfrom
yiyou/feat/opd-multinode-teacher
Oct 18, 2026
Merged

SigureMo merged 1 commit into
mainfrom
yiyou/feat/opd-multinode-teacher

Conversation

@DrRyanHuang

@DrRyanHuang DrRyanHuang commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

What

  • 支持 MultiEngineManager 与 TeacherManager 管理跨物理节点的多机模型实例(nodes_per_engine >= 1,如 TP=16+ 跨 2 台 8 卡机器)。
  • 实现了多机 Teacher 的 Dedicated Placement Group 共享:由每个 Replica 的 Head 节点统一创建并持有 PG,Follower 节点借用同一 PG。
  • 实现了多机节点地址聚合分配:按 rank // nodes_per_engine 分组,确保从节点正确定位并连接到本 Replica Head 的 dist_init_addr。
  • 规范多机暴露与显存生命周期:get_urls()、health_check()、onload()、offload() 仅下发给各 Replica 的 Head 节点,不对内部 Follower 暴露。
  • 完善多机异常清理机制:任一节点故障时成组下线整台多机实例;销毁时先停止 Follower Actor 再释放 Placement Group;初始化异常自动回滚。

Why

在使用大模型作为 Teacher(如 72B / 397B 等需要多机 TP=16+ 部署)进行 On-Policy Distillation (OPD) 时,之前的MultiEngineManager 假定 1 个 Slot 等于 1 个单机 Engine。这会导致:

  1. Follower 节点无法共享 Head 节点的 Placement Group 和分布式初始化端口;
  2. 外部 HTTP 路由将无法提供服务的 Follower 节点暴露给训练端导致 404 / 连接超时;
  3. 单节点故障无法级联清理该模型的其它节点,导致资源泄漏和死锁。

How

1.MultiEngineManager:

  • 增加 nodes_per_engine 属性,self.engines 属性切片为 [::nodes_per_engine](仅返回 Head 节点)。
  • _fanout 仅向各个 Head 节点广播显存操作(release_memory_occupation / resume_memory_occupation)。
  • _retire_engines 计算各 slot 对应 logical engine 的 head 并批量下线整组节点。
  • shutdown 确保先清理 Follower slots 避免 Actor 悬空,再清理 owned PG。

2.TeacherManager:

  • 增加多机 GPU 参数整除校验(gpus_per_replica % num_gpus_per_node == 0)。
  • _resolve_placement 中仅 rank % nodes_per_engine == 0 的 Head 槽位创建并持有 PG,Follower 槽位借用。
  • _allocate_engine_addr_and_ports 按 Replica 分组调用地址分配器,保证同一模型下的所有节点使用同一个 Head 地址及连续端口。

3.SGLangEngine:

  • _start_server 支持传入 worker_type 及对应的 dist_init_addr,以便 Follower 节点连接 Head。

Testing

  • pre-commit run --all-files passes
  • Tests pass (pytest tests/)
  • New tests added (if applicable)
  • Documentation updated (if applicable)

测试命令及结果:

pytest tests/backends/sglang/test_sglang_engine.py tests/distributed/ray/test_multi_engine_manager.py tests/distributed/ray/test_teacher_manager.py
# 47 passed in 0.89s

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

@DrRyanHuang
DrRyanHuang requested review from a team and SigureMo October 17, 2026 18:13
@rai-studio-bot

rai-studio-bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for contributing to Relax, @DrRyanHuang! 感谢你为 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 / 状态
审批人数 ⏳ 0/1 · 至少 1 位有仓库 write 或更高权限的人 Approve
团队审批(relax-block-reviewers) ⏳ 0/1 · 可联系:Aurelius84, Yangruipis, yuanlehome, SigureMo, NINGBENZHE
CI ✅ 已通过

@rai-studio-bot

rai-studio-bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Nyanpasu 审查看板

审查状态: ✅ 已通过

审查版本: 7213496

目标分支: main

复审通过:72134963 相对已审 6b35b53 只更改两个测试文件,原可选 SGLang 依赖问题已修复,未发现新增问题。Python 3.12.3 下选取两项地址分配测试及 node_rank=1 的启动测试,共 3 项通过;本地环境已安装 SGLang,该结果仅验证模拟调用与 fixture 注册,未复现完整 CPU CI 环境。新 head 的格式检查已通过,其他 CI 尚未全部完成。真实多节点 GPU/Ray/NCCL 启动与恢复未经本次验证。

审查阶段进度范围与结果
常规审查 ✅ 已完成 复核本轮两个测试文件的全部差异;生产代码及第三个测试文件与上次已完成审查的版本一致,复用其调用链、PG 所有权、地址分配和生命周期契约证据。
深度审查 ✅ 已完成 核查 allocator 替身的验证边界:仍断言真实 TeacherManager 的分组、参数与 rank_offset,但不再验证真实 allocator;本地 3 个选定用例通过。原线程已解决,未追加宽范围测试。

审查发现

待处理
编号 严重性 问题状态规则来源
暂无待处理的记录。
已解决或已取代
编号 严重性 问题状态规则来源
F1 Medium severity 为地址分配测试处理可选 SGLang 依赖 ✅ 已解决 —
提交范围 · 接收 6 · 建议移出 0 · 待确认 0

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

文件结论仓库维护必要性依据替代去向或方案
relax/backends/sglang/sglang_engine.py
relax/distributed/ray/multi_engine_manager.py
relax/distributed/ray/teacher_manager.py
接收 实现跨节点 teacher 的 placement、地址分配和整组生命周期管理,属于现有推理管理模块。 PR #450 的 What/Why:支持跨节点 teacher 和 rollout 模型实例。 沿用现有 SGLangEngine 与 manager 模块,当前位置适合其职责。
tests/backends/sglang/test_sglang_engine.py
tests/distributed/ray/test_multi_engine_manager.py
tests/distributed/ray/test_teacher_manager.py
接收 为跨节点分组、PG 所有权和进程清理提供持久回归覆盖。 PR #450 多节点启动及异常清理需求;tests 按生产模块组织。 保持在对应模块测试目录中,便于维护行为回归。
Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

…ineManager

✨ Feature

- Support multi-node logical engines (`nodes_per_engine >= 1`) across MultiEngineManager and TeacherManager for large teacher models (e.g., TP=16+ across multiple nodes).
- Dedicated Placement Groups: Create one multi-node PG per replica owned by the head slot, shared across follower slots.
- Grouped Address Allocation: Group ranks by replica (`rank // nodes_per_engine`) so all nodes in a replica share the head node's IP for distributed initialization (`dist_init_addr`).
- Route & Lifecycle Isolation: Restrict external HTTP endpoints (`get_urls()`), health checks (`health_check()`), and memory offload/onload (`_fanout`) to head nodes only, preventing direct requests to internal follower nodes.
- Atomic Retirement & Safe Rollback: Retire all slots of a multi-node replica together on failure; ensure follower actors are stopped before removing owned placement groups.

✅ Tests

- tests/backends/sglang/test_sglang_engine.py: Verify multi-node dist_init_addr and worker init.
- tests/distributed/ray/test_multi_engine_manager.py: Verify multi-node engine lifecycle, fanout, retirement, and graceful rollback.
- tests/distributed/ray/test_teacher_manager.py: Verify multi-node PG sharing, replica address bundling, head-only routing/memory ops, and single-node separation.

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

评审结论

已完成 6b35b538 的节点放置、地址分配、整组回收与恢复、进程生命周期及对应测试审查;保留一项测试兼容性意见。未确认生产代码的阻塞缺陷;本次依据源码和现有 CI 日志,未执行真实多节点 GPU/NCCL 集成验证。

完整结论与 CI 诊断

This comment is replied by codex (gpt-6.1-sol xhigh)
Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

@DrRyanHuang
DrRyanHuang force-pushed the yiyou/feat/opd-multinode-teacher branch from 6b35b53 to 7213496 Compare October 17, 2026 18:26

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

复审通过

已复核 72134963 相对上次评审的全部改动,原测试依赖问题已修复,未发现新增问题。选取的 3 个测试在 Python 3.12.3 下通过;格式检查已通过,其余 CI 尚未全部完成。生产代码未变化,沿用上次源码及契约核查结论;真实多节点 GPU/NCCL 启动与恢复仍未经本次验证。

审查看板与验证范围

This comment is replied by codex (gpt-6.1-sol xhigh)
Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

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

LGTMeow 🐾

@SigureMo
SigureMo merged commit c6a86dc into main Oct 18, 2026
17 checks passed
@SigureMo
SigureMo deleted the yiyou/feat/opd-multinode-teacher branch October 18, 2026 07:51
leelingrui added a commit to leelingrui/Relax that referenced this pull request Oct 19, 2026
…rence

Conflicts (modify/delete) with redai-studio#450, which extended MultiEngineManager and
TeacherManager for multi-node teacher replicas. This branch removed both:
Teacher and GenRM engines now start through start_servers/EngineGroup on
the InferenceManager, which already covers redai-studio#450's requirements:

- multi-node replicas must use whole nodes (InferenceModelSpec.resolved,
  teacher_role_model);
- URLs, health probes and memory operations reach replica heads only
  (EngineGroup.engines, RolloutServer._call_heads; followers answer
  health_generate locally);
- a dead replica is retired as a whole (RolloutServer._retire);
- one placement group per model, with the planner checking each node slot.

The deletions are kept. redai-studio#450's SGLangEngine change (parent-death guard,
follower process handle) merged cleanly. Its behaviours are re-covered by
tests against the unified pool in test_rollout_inference_pool.py.
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