Skip to content

refactor(rollout): isolate rollout utilities and strengthen tests - #439

Merged
SigureMo merged 2 commits into
redai-studio:mainfrom
NINGBENZHE:main
Oct 14, 2026
Merged

SigureMo merged 2 commits into
redai-studio:mainfrom
NINGBENZHE:main

Conversation

@NINGBENZHE

@NINGBENZHE NINGBENZHE commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

What

Extract rollout metrics and scale request types, tighten KL configuration validation, and simplify tests.

Why

Reduce module coupling, catch conflicting YAML overrides, and replace redundant tests with meaningful regression coverage.

How

Preserve existing import paths, centralize KL checks, and test actual production logic—including enum rendering and colocate decisions.

Testing

268 regression tests and 4 enum/colocate cases passed. Full pre-commit passed. Runtime-dependent checks were skipped; broader testing reproduced 13 existing environment failures. Multi-node GPU integration was not run.

  • 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

Screenshots / Logs

Extract rollout metrics and scale request types into focused modules while
preserving existing public import paths. Reapply KL coefficient validation
and synchronous PPO normalization after custom YAML configuration overrides.

Remove redundant and self-contained tests, exercise the real SFT colocate
method and Bridge conversion path, and cover configuration conflicts,
metrics, state transitions, and import compatibility.

Validation: focused refactor regression suite: 268 passed, 38 skipped.
Test cleanup suite: 110 passed, 11 skipped; 13 environment-related failures
were also reproduced with the original tests (torchao/PyTorch mismatch and
missing TransferQueue interfaces). Multi-node GPU integration was not run.
@NINGBENZHE
NINGBENZHE requested a review from a team October 13, 2026 14:59
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T15:06:47.227647Z 24d35bd PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@rai-studio-bot

rai-studio-bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for contributing to Relax, @NINGBENZHE! 感谢你为 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 · 已审批:SigureMo
团队审批(relax-block-reviewers) ✅ 1/1 · 已审批:SigureMo
CI ✅ 已通过

@rai-studio-bot

rai-studio-bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Nyanpasu 审查看板

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

审查版本: a9681c2

目标分支: main

审查完成:无阻塞性问题。生产改动(两处纯搬迁抽取 + arguments.py YAML 覆盖后校验重跑)经实测验证无正确性缺陷;删除测试均有存活归属。唯一发现 F1(P2,colocate 测试用纯字符串模拟角色、str(角色) 渲染契约失去存活覆盖)已由作者在 a9681c2 修复:测试改为用 registry 源码中的真实枚举成员驱动门控(stdlib StrEnum 与 pre-3.11 fallback 双路径参数化),并补齐 _validate_gpu_resources 第三位置参数与 _actor_rollout_pg_roles 转发断言;经变异实验验证检出力(移除 fallback __str__ 后用例按预期失败)。另在 review 备注中说明 PR 勾选的「Refactoring (no functional changes)」与实际的 YAML 校验收紧不符。多节点 GPU 集成测试未运行(作者已说明)。

审查阶段进度范围与结果
常规审查 ✅ 已完成 已检查全部 22 个变更文件:抽取模块契约保全(身份、pickle、旧导入路径、无残留引用、无循环导入)、YAML 校验重跑的可达性与顺序一致性、离线路径交互;本地运行改动测试 222 通过;re-export 身份与 pickle 兼容直接实测通过。a9681c21 仅改动一个测试文件,生产代码与此前审查基线逐字节一致(git diff 确认)。
深度审查 ✅ 已完成 测试审计完成:删除用例逐条核对存活归属;重写用例经变异实验(colocate 门控还原、metrics 两处变异)与 arguments.py pre-PR 还原实验验证检出力;1 个 P2 检出力缺口(F1)发布为 inline 发现。a9681c21 修复 F1 后复审:4 个用例基线通过;变异实验(移除 fallback __str__)使 fallback-strenum 两个用例在渲染断言处按预期失败、stdlib 用例不受影响,证实修复有效。

审查发现

待处理
编号 严重性 问题状态规则来源
暂无待处理的记录。
已解决或已取代
编号 严重性 问题状态规则来源
F1 Medium severity 新增 colocate 判定测试用纯字符串模拟角色,str(角色) 渲染契约失去存活覆盖 ✅ 已解决 —
提交范围 · 接收 22 · 建议移出 0 · 待确认 0

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

文件结论仓库维护必要性依据替代去向或方案
relax/distributed/ray/rollout.py
relax/distributed/ray/rollout_scale_types.py
relax/utils/metrics/rollout_metrics.py
relax/utils/opd/opd_utils.py
relax/utils/misc.py
接收 纯搬迁抽取 rollout 指标与 scale 类型至独立模块,re-export 保留导入路径;此前 head 已审,a9681c21 未触碰。 PR 描述需求 1;re-export 消费方与 pickle 身份契约已在 24d35bd 实测验证。 保留在 rollout.py 不拆分——会失去新测试展示的 CPU 可测性与导入纯净性。
relax/utils/arguments.py
接收 YAML 覆盖合并后重跑 KL 校验与同步 PPO 归一化,关闭可达的绕过路径;调用顺序分析确认可达性。 PR 描述需求 2;slime_validate_args(4112/4334)先于 apply_custom_config_overrides(4579)。 合并后不再校验——YAML 可重新启用已拒绝的 KL 配置。
tests/algorithms/test_arguments_spec_driven.py
tests/core/test_controller_sft_colocate.py
tests/distributed/checkpoint_service/test_dcs_weight_conversion.py
tests/distributed/ray/test_rollout_engine_config.py
tests/distributed/ray/test_rollout_import_compatibility.py
tests/distributed/ray/test_state_machine.py
tests/utils/test_metric_utils_agentic.py
tests/utils/test_metric_utils_rloo.py
tests/utils/test_rollout_metrics.py
tests/utils/test_repetition_integration.py
接收 重写或新增用例经 AST-exec 真实方法体、BridgeConverter 真实转换路径与抽取后纯模块驱动;a9681c21 依审查发现 F1 进一步强化 colocate 用例。 PR 描述需求 3;测试审计子任务的必要性审计保留这些用例。 保留纯字符串 mock——生产以 str() 渲染枚举角色,mock 下静默通过。
tests/backends/megatron/test_mtp_only_training.py
tests/components/test_genrm_engine_pick.py
tests/components/test_sft.py
tests/core/test_registry_sft.py
tests/core/test_service_affinity.py
tests/engine/rollout/test_on_policy_distillation_routing.py
接收 删除或裁剪的用例契约均已在测试审计子任务中追踪到存活归属。 PR 描述需求 3;子任务审计证据(task 2146bd63)。 保留全部旧用例——与存活覆盖重复或断言不可达行为。
精简审查与验证依据
审查范围进度结论
生产代码 ✅ 已完成 抽取拆分、re-export 保留与校验重跑均有明确契约支撑,替代方案会失去已验证的收益。
测试 ✅ 已完成 删除用例均有存活归属;新增/重写用例的检出力经实验验证,保留全部新用例。

生产代码的必要性与替代方案

范围必须保留的契约更简单的方案结论依据与限制
relax/distributed/ray/rollout.py 的扩缩容请求类型与指标函数抽取为两个新模块 旧导入路径 relax.distributed.ray.rollout 下的类/函数对象身份不变,pickle 协议 0 反序列化解析到同一类;调用方为现存测试与本仓 re-export 使用者 保留在 rollout.py 不拆分 保留 拆分使 test_repetition_integration 删除 60 行 stub fixture、test_metric_utils_agentic 删除 45 行 monkeypatch stub;子进程测试证明新模块不引入 ray/sglang/tq/megatron;re-export 身份与 pickle 兼容已直接实测。
rollout.py 与 opd_utils.py 中 compute_mopd_metrics 的 noqa re-export 两个旧导入路径下的 compute_mopd_metrics 仍可用且为同一对象(测试锁定) 删除两处 re-export,消费方改为从新模块导入 保留 仓内 grep 未发现生产消费方,但 PR 明示契约是保留公开导入路径且有身份测试锁定,成本约 2 行;若确认无外部使用,可另开变更删除。
relax/utils/arguments.py 在 apply_custom_config_overrides 末尾重跑 _normalize_sync_ppo_kl_args YAML 合并后同步 PPO 的 KL 选项仍被禁用并告警;调用顺序(4112/4334 先于 4579)证实该路径可达 仅校验不重跑归一化,或把 YAML 合并提前到全部校验之前 保留 pre-PR 还原实验:4 个 yaml-source 参数用例在旧代码上按预期失败(DID NOT RAISE / assert 0.1 == 0.0);合并提前是文件注释已说明的更大改动。

测试的必要性与替代方案

范围必须保留的契约更简单的方案结论依据与限制
6 个测试文件的删除/裁剪(mtp 梯度机制、genrm 空列表 raise、sft 无 ray 导入、registry 两断言、affinity happy path、OPD 被否决替代方案) 每个被删契约仍有存活归属(test_genrm_engine_pick.py:194、test_optional_roles.py:10-46、test_registry_sft.py:39-40 与 :64-77 等) 保留全部旧用例 删除 逐条 grep 与阅读核对:mtp 三例仅测 torch autograd 语义(零 Relax 代码);genrm raise 同文件同 match 串仍在;registry/affinity 删除项与存活用例重复或更弱。
test_controller_sft_colocate.py 的 AST-exec 真实方法体测试 colocate 判定由真实 register_all_serve 执行,oracle 为被修复的 hasattr 缺陷 回退为静态镜像断言 保留 门控还原为 pre-fix 形态后 [True-True] 参数按预期失败;检出口径强于旧镜像测试;遗留枚举渲染缺口已发布为 F1。
test_dcs_weight_conversion.py 的 BridgeConverter 真实转换路径 专家权重后处理在生产 convert() 内执行(bridge_converter.py:609-646 与被删镜像逐行一致) 保留手写镜像 helper 保留 重写额外覆盖名称别名与量化路径并 pin 调用点;本地无 megatron.core 无法执行,由 CI 验证。
Powered by Nyanpasu with glm-5.3-flash max, 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.

审查结论:常规与深度审查完成,无阻塞性问题

本次范围覆盖全部 22 个变更文件。生产改动为两处纯搬迁抽取(rollout 扩缩容请求类型、rollout 指标统计)与 relax/utils/arguments.py 在 YAML 覆盖后重跑 KL 系数校验及同步 PPO 归一化:re-export 身份与 pickle 协议 0 兼容、旧导入路径、import 纯净性均已实测验证,未发现正确性缺陷;删除的测试经逐一核对与变异实验确认均有存活归属,重写用例对本次要堵的洞有实测检出力。唯一发现是新增 colocate 判定测试对枚举渲染契约的检出力缺口(P2,见行内评论)。分组索引与验证依据见审查看板。

非行级备注:PR 勾选的「Refactoring (no functional changes)」与实际行为不符——--custom-config-path 此前可绕过的校验现在会告警或直接报错,属于校验收紧,建议在描述中更正或说明。

Powered by Nyanpasu with glm-5.3-flash max, please check the suggestions carefully.

Drive the actual colocate gate with role enums from the registry source,
covering both standard StrEnum and the pre-3.11 fallback without loading
backend components. Assert placement-group role forwarding as well.

Validation: four test cases pass; mutation checks detect broken enum
rendering, missing fallback __str__, and incorrect placement-group roles.
@NINGBENZHE NINGBENZHE changed the title refactor: isolate rollout utilities and strengthen tests refactor(rollout): isolate rollout utilities and strengthen tests Oct 14, 2026

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

复审结论:a9681c21 已修复 F1,无阻塞性问题

本轮针对 synchronize 后的新提交 a9681c21 test(core): restore colocate enum rendering coverage 复审。生产代码与本轮此前审查的 24d35bd1 逐字节一致,此前的全部结论(抽取契约保全、YAML 覆盖后校验重跑可达且顺序一致、删除测试均有存活归属、必要性审计)原样成立。

F1(P2)已解决

新增 colocate 判定测试此前用纯字符串模拟角色,str(角色) 渲染契约失去存活覆盖。a9681c21 的修复已在 F1 线程中独立验证:

  • 用例改为从 relax/core/registry.py 源码经 AST 提取真实枚举定义执行(不导入 Ray Serve 组件),并参数化 stdlib StrEnum 与 pre-3.11 fallback 两条渲染路径;提取范围核对无误(顶层仅一个 Try + 一个 enum ImportFrom + 两个目标 ClassDef)。
  • 变异实验:移除 fallback __str__ 后,仅 fallback-strenum 两个用例在渲染断言处按预期失败,stdlib-strenum 不受影响——原缺口((str, Enum) 缺 __str__ 时静默关闭 colocate)现在可被检出。
  • 同时补齐了 _validate_gpu_resources 第三位置参数(pg_roles)与 _actor_rollout_pg_roles 转发断言。

F1 线程已由作者标记 resolved,本 Bot 已在原线程附上验证证据(讨论)。

其余范围

未变动,详见此前审查与状态板。两点既存备注仍然有效:PR 勾选的「Refactoring (no functional changes)」与实际的 YAML 校验收紧不符,建议更正;多节点 GPU 集成测试未运行(作者已说明),test_dcs_weight_conversion.py 与 test_rollout_import_compatibility.py 依赖 megatron.core,本地无法执行,由 CI 验证。

状态板已更新至第 4 版(F1 → resolved):#439 (comment)

Powered by Nyanpasu with glm-5.3-flash max, 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 🐾

import sys
from types import SimpleNamespace

class NoRuntimeImports(importlib.abc.MetaPathFinder):

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.

这个是为了让 CPU 单测能通过写的嘛?

@SigureMo
SigureMo merged commit fc7cd3c into redai-studio:main Oct 14, 2026
22 checks passed
leelingrui added a commit to leelingrui/Relax that referenced this pull request Oct 17, 2026
…rence

Resolve conflicts with upstream redai-studio#433 (managed PD), redai-studio#437 (native image OPD),
redai-studio#439 (rollout utility extraction), redai-studio#361 (multinode scale-out) and the
placement factory relocation, porting their intent onto InferenceManager.

- Managed static PD: start_servers defers the Router until P/D engines are
  ready and seeds it with them; replacements still join after weight sync.
- Recovery broadcasts rank-0 failures before weight sync; pool monitors stop
  within one shared 5s budget; Controller bounds shutdown_all to 35s.
- Teacher engines get SGLANG_MM_AVOID_RETOKENIZE in config_adapters; the
  removed RELAX_OPD_PREEXPANDED_PATCH reference is dropped.
- Drop RolloutManager/TeacherManager-only code and tests; adapt new upstream
  tests to EngineGroupSpec/InferenceModelSpec and the inference manager.
leelingrui added a commit to leelingrui/Relax that referenced this pull request Oct 19, 2026
…rence

Resolve conflicts with upstream redai-studio#433 (managed PD), redai-studio#437 (native image OPD),
redai-studio#439 (rollout utility extraction), redai-studio#361 (multinode scale-out) and the
placement factory relocation, porting their intent onto InferenceManager.

- Managed static PD: start_servers defers the Router until P/D engines are
  ready and seeds it with them; replacements still join after weight sync.
- Recovery broadcasts rank-0 failures before weight sync; pool monitors stop
  within one shared 5s budget; Controller bounds shutdown_all to 35s.
- Teacher engines get SGLANG_MM_AVOID_RETOKENIZE in config_adapters; the
  removed RELAX_OPD_PREEXPANDED_PATCH reference is dropped.
- Drop RolloutManager/TeacherManager-only code and tests; adapt new upstream
  tests to EngineGroupSpec/InferenceModelSpec and the inference manager.
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