Skip to content

feat(recovery): add local recovery for Rollout and ActorFwd - #705

Merged
RexFlux merged 39 commits into
redai-studio:mainfrom
Yangruipis:refactor/inference-recovery-ownership
Nov 25, 2026
Merged

RexFlux merged 39 commits into
redai-studio:mainfrom
Yangruipis:refactor/inference-recovery-ownership

Conversation

@Yangruipis

@Yangruipis Yangruipis commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

What

#791 已合入 main。本 PR 以 main 为基线,Files changed 展示 Rollout 和 ActorFwd 局部恢复的增量。

这个 PR 让 Controller 在支持的训练配置下局部重建失败的 Rollout 或 ActorFwd,并保留原训练 Actor、优化器与调度器。恢复时先停止准入,等待旧操作结束,再清理未训练分区、重建推理资源、确认权重完整接收并继续训练。无法确认安全时转入全局重启。

Why

单个推理服务故障也可能触发整个训练作业重启。局部恢复需要确定旧服务已交还共享资源、训练进度可续接,以及替换实例拿到了完整权重。

How

  • Controller 仲裁局部恢复与全局重启。各组件负责训练批次准入、权重发布和故障上报。
  • Rollout 负责在重建前排空评估、关闭旧引擎和路由进程。训练侧检查每个流水线阶段的接收者。评估插件明确上报的评分错误在恢复期间仍会终止作业。
  • 默认的 Rollout 缓冲数据源清空待处理样本并保留读取游标。自定义 --data-source-path 需实现 discard_pending(),清空待处理样本并保留游标。缺少该方法或调用抛错时,Controller 会转入全局重启。
  • 包含相应的 CPU 回归和中英文恢复指南。生产代码相对新基线为 25 个文件,新增 1,678 行、删除 262 行。

Testing

在单机 H800、CUDA 12 上,用 Qwen2.5-1.5B-Instruct 和 GSM8K 跑 Megatron + SGLang 的 GRPO 训练。前三组从 a091790c 的干净归档启动,第四组直接从 PR 最新提交 1e6e9c09 的干净归档启动。两版只差中英文指南,relax/ 的 Git tree 均为 02e41bd1。

真实运行中注入的故障 实际恢复结果
Colocate、4 张卡。完成前两步后让 Rollout 生成调用抛出异常 115 秒完成一次局部恢复。原 4 个训练 rank 各跑完第 0–5 步,模型、优化器和调度器对象均保留。4 个新 SGLang 引擎的权重版本均为发送端的 4。
Fully async、6 张卡。让两个 ActorFwd rank 在第 2 步抛出异常并保持存活 79 秒完成一次局部恢复。原训练进程跑完第 0–7 步。恢复放行前,分别比较每个 TP 分片的全部 198 个具名参数,每个分片 1,543,801,856 字节,发送方与新 ActorFwd 的 SHA-256 逐分片一致。
Fully async、6 张卡。让两个 ActorFwd rank 在第 2 步通过 os._exit(86) 退出 Ray 报告 ActorDiedError,Controller 判定局部恢复不安全,执行一次全局重启。此配置未保存 checkpoint,新训练进程从初始模型重跑第 0–7 步。
Hybrid、6 张卡。重建 Rollout 后,从实际权重广播组中移除两个替代引擎中的一台 一台引擎收到更新并升至版本 3,另一台没有收到更新。4 个原训练 rank 各自上报缺少同一接收方,Ray 独立记录了 4 个失败任务。局部恢复被拒,原训练 rank 停在第 1 步。全局重启一次,4 个新 rank 均重跑完第 0–5 步。

四组训练作业的退出码均为 0。本轮故障注入使用单机。

另在 1e6e9c09 的隔离 CPU Ray/Serve 作业中加载了缺少 discard_pending() 的自定义数据源。第 0 步训练结束后杀掉推理子进程,生产 Rollout 清理待处理样本时抛出 AttributeError,Controller 进入第 1 次全局重启。本组用轻量训练和队列替身,观察至全局重启入口。

  • a091790c 基于 main@7354e4fa。在指定 CU12 镜像上从该提交导出的干净代码复跑了 13 个相关文件,393 项全部通过。切换前后的完整 Git 补丁经逐字节比对相同,共 69 个文件,新增 5,676 行、删除 403 行。

  • 在 CU12 镜像中隐藏 GPU,在拆分时运行 14 个文件的定向测试,337 项通过。涵盖 Controller 局部与全局重启、Rollout/ActorFwd 重建、权重接收确认和评估异常传播。

  • 拆分完成时的 b3a8059e 与将原获批版本 051bb106 合到 main@b9142f93 的文件树相同。之后的前置复审修复已同步到 d48ea79a。此提交在 CU12 运行 13 个 CPU 文件,393 项通过,覆盖故障恢复、权重同步、评估和计时。此次未重跑多节点 GPU 故障注入。

  • 双 rank 真实 Ray 实验覆盖两种权重更新入口。两个 rank 都结束后才开始评估。一个 rank 明确失败时等待其余 rank 结束,再返回原始错误;另一个 rank 超时未结束时返回 UnsafeInferenceError。

  • pre-commit run --all-files passes

  • Tests pass (targeted suite above)

  • 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

前置编排及该版本的独立验证见 #791。下方保留此前 #705 的完整范围、复跑命令与逐版验证记录。

拆分前的背景与验证记录(截至 051bb10)

What

基于 #548 的独立实现修订稿,面向 main。保留局部推理恢复功能与中英文文档,重新划分恢复、同步和训练职责。

  • Rollout 或独立 ActorFwd 明确失败时,在共享累计预算内局部重建;保留原训练 Actor、optimizer 和 scheduler。排空旧工作后丢弃未训练半成品,输入 cursor 不回退;无法安全恢复时转全局重启。
  • Controller 直接编排跨服务恢复,删除无状态的 core/inference_recovery_executor.py 包装层。组件拥有恢复准入与训练/推理阶段边界,Ray 组级协调负责服务握手和权重派发,训练 rank 不读取共享恢复状态或决定恢复策略。
  • Rollout 管理恢复窗口及替换实例的 router 地址;Megatron 保留本地训练状态和 CPU 快照导出;updater、DCS 分别负责传输资源和完整接收确认。
  • 组件始终编排训练、同步和评估,删除后端 defer 参数与旧整步兼容路径;recovery 开关只控制准入和失败处理。hybrid 的训练指标在评估请求之后刷新,具体时序见下文。FSDP 实现保持原有行为。

仅包含 recovery 生产代码、测试和文档,不包含 agent、skill、加载配置或实验产物。

Why

原实现让训练 Actor 感知推理服务的恢复准入、生命周期与握手时序。只移动 helper 不能解除职责耦合;引入无实际职责的中间执行器也增加追踪成本。此次让既有资源所有者承担相应职责,并在真实训练中验证行为。

How

架构对照与范围

对照原作者 #548 接手时的 0ab3d29a 与当前实现 2ee4ffc,主要针对 Megatron。FSDP 实现保持原有契约;此次调整未扩展到整个后端体系。

原作者实现中,组件已有任务准入,但训练 rank 内仍包含同步准入、服务握手和 RL HTTP 评估:

Controller
    |
    +--> Actor 组件 -> RayTrainGroup -> Megatron Actor(每个 rank)
    |                                   |
    |                                   +-- 模型训练
    |                                   +-- 读取共享恢复状态
    |                                   +-- _begin_inference_sync()
    |                                   +-- 等待 eval、探测 Rollout / ActorFwd
    |                                   +-- 选择接收方、发送权重、请求 RL eval
    |                                   '-- _end_inference_sync()
    |
    '--> InferenceRecoveryExecutor
             +-- 清理 TQ、直接操作 Rollout 内部对象
             +-- 调用 Service 重建
             '--> 训练 Actor 的恢复方法
                      +-- 操作 updater 内部资源
                      '-- 调用 Rollout 权重 / KV onload

当前正常训练路径

组件决定阶段时序,训练后端执行持有模型与通信资源的具体操作:

Actor 组件
    |
    +-- 1. RayTrainGroup -> 所有 Megatron rank 执行训练
    |                         +-- 模型 / optimizer 更新
    |                         +-- 保存、备份、训练状态驻留管理
    |                         '-- 返回
    |
    +-- 2. RecoveryGate:决定是否允许进入同步
    |
    +-- 3. inference_sync:跨服务协调
    |          +-- 等待上一轮 eval
    |          +-- 与 Rollout / ActorFwd 握手、选择接收方
    |          +-- 派发各 rank 的权重发送操作
    |          '-- 请求 RL eval、结束握手
    |
    '-- 4. 完成指标收尾、保存及训练步提交

开启和关闭 recovery 都由组件编排这条正常路径;开关只控制准入、排空和失败处理,不再选择编排发生在哪一层。删除 defer_inference / defer_weight_receive 双路径。

Colocate 发送权重后刷新训练指标,再请求评估。full-async 在推理阶段之后刷新。主线 hybrid 在发送权重后、请求评估前刷新,本 PR 的 hybrid 在请求评估并完成 Rollout 释放握手后刷新,最后一步还会先等评估结束。已验证调用顺序和刷新所用的训练步编号;未在相同训练输入上逐项对比两版上报的指标值或上报时间。离线训练保留所有模型 rank 参与的本地评估/predict,不进入普通 RL 服务握手。ActorFwd 和 reference 均由组件显式调用:

前向组件 -> 后端 compute -> 后端 receive weights -> 后端 finish metrics

当前故障恢复路径

Rollout / ActorFwd 明确异常
              |
              v
         Controller
              +-- State:检查共享累计预算、暂停新准入
              +-- 等待旧操作结束
              +-- TQ 存储层:清理未训练分区
              +-- Rollout 组件:丢弃未完成生成窗口
              +-- Service:确认旧子进程退出、重建失败服务
              |
              +-- 同步替代实例
              |      +-- 训练后端:提供当前权重 / CPU 快照
              |      +-- updater / DCS:准备传输、确认接收完整
              |      '-- Colocate Manager:恢复权重和 KV 显存
              |
              '-- 恢复准入、启动并登记替代任务

预算耗尽 / 无法安全完成 -> Controller 原有全局重启

发送和接收两端使用明确且一致的 sync_step,避免从 checkpoint 启动时使用尚未对齐的组件 step 推导接收集合。保持原训练 Actor、optimizer 和 scheduler 的局部恢复语义;全局重启仍遵循原有重建路径。

职责归属变化及理由

职责 原作者 #548 当前 #705
同步阶段准入 训练 rank 读取恢复 State,再广播决定 组件层 RecoveryGate 决定
服务探测、等待、接收方选择 Megatron Actor 内 inference_sync
RL HTTP 评估 Megatron Actor 内 inference_sync
恢复窗口清理 Executor 直接访问 datasource、manager Rollout 组件封装自身清理
恢复时传输资源准备 Actor 操作 updater 内部字段 updater / DCS 处理
跨服务恢复流程 Controller → Executor Controller 直接编排
恢复策略与通用等待逻辑 混在 core/inference_recovery.py components/recovery.py 与 distributed/settlement.py 分别承担

Controller 已拥有服务集合、恢复任务和全局接管约束,因此将没有独立资源或生命周期的 Executor 收回其私有恢复流程。Rollout、Service、updater/DCS 管理自己的状态和资源,减少外部调用方穿透内部实现。

训练后端仍保留权重发送、CPU 快照、通信客户端重置和本地离线评估等操作,因为模型与相应资源实际驻留于各 rank。此次迁移的重点是服务级决策和编排;用户可观察的行为契约需要保持,旧私有调用形态不自动构成兼容要求。

容错配置

SFT、DPO、RM 等离线模式通过共享的 is_offline_mode() 判定排除组件级恢复,不创建 RecoveryGate 的恢复状态;保留用户的 use_fault_tolerance 配置及既有离线训练路径,避免等待 RL 的 train_<step> 分区。

统一使用 --use-fault-tolerance 开启容错,默认关闭。支持组件级恢复的配置使用 Controller 恢复流程,并停用旧引擎监控、自动重建和旧 CI 注入;其他配置保留原有引擎级容错。同步暂停握手保留,新旧恢复互斥。

删除 RELAX_ENABLE_INFERENCE_RECOVERY;保留 RELAX_INFERENCE_RECOVERY_MAX_ATTEMPTS 与 RELAX_INFERENCE_RECOVERY_DRAIN_TIMEOUT。局部尝试预算与 --max-global-restart 仍分别计数。

Testing

051bb106 的 8 项必需检查全部通过。CPU 和 H20 单卡、四卡单测中,CPU 为 10,948 项通过、115 项跳过,另有 31 个子用例通过。双卡 GPU 多模态、四卡 GPU 异步、四卡 NPU 异步集成、文档构建和静态检查均通过。本轮在指定 CU12 镜像单独运行 207 项相关回归,包含恢复排空、评分插件回退和数据集自定义生成器的显式评分异常。本轮没有运行多节点 GPU 故障注入。

自定义评分回退

复审 确认前次五项反馈已修复,并指出自定义 reward 内部回退成功后仍可能误报终止错误。b0ac3ca3 保留插件捕获的原始异常类型,只登记实际退出评估任务的评分失败。指定镜像中验证了普通打分和分组打分、内联和后台评分。插件返回有效分数时训练会保留该分数。同批另有生成失败时,训练收到原生成错误。插件未处理的评分失败仍以 EvalJudgeError 传回。

7828ff91 修复了任务组中未处理的评分错误在恢复排空时被丢弃的问题。051bb106 修复了复审发现的另一种包装方式。插件用 raise ... from exc 给同一评分失败补充说明时,Manager 的评估和恢复排空都会报告评分错误,并保留插件说明。插件已处理评分失败、后备生成请求自身失败时,评估仍报告生成错误。

自定义评分回退(CPU,验证镜像 qs-20261124-447fe38f-cu12)

  • 仓库回归。SGLang 的单样本内联用例在同批注入生成失败。自定义评分捕获 ValueError 后,评估报告生成的 ConnectionError。放行评分异常时,评估报告 EvalJudgeError。后台评分和同步评分各有一个单样本用例,在测试进程直接调用 EvalJudgeWorker.score 和 RewardWorker.compute_custom,均断言得分 4.5。
  • 分组评分。额外的同进程 RolloutManager.eval → SGLang → RewardExecutor 探针开启 group_rm=True,每个 prompt 生成一条。组评分捕获原始异常后得到 [4.5]。同批再注入一个生成失败时,Manager 抛出 ConnectionError,记录的评分错误数为 0。单独直接调用后台 EvalJudgeWorker.score,单样本和分组请求也都得到 [4.5]。
  • 真实 Ray RPC。额外启动本地 Ray,向独立进程中的同步 RewardWorker 发起单样本 compute_custom.remote。局部恢复关闭、开启各一次,插件均捕获原始 ValueError 并返回 4.5。仓库里另有两个 RPC 用例分别核对独立 worker PID,以及三条样本的批量返回顺序和数量。
从 checkout 根目录复跑仓库用例
T=tests/cpu/engine/rollout/test_weight_sync_499.py
R=tests/cpu/engine/rewards/test_custom_reward_worker.py::TestCustomRewardDispatch
python -m pytest -q \
  "$T::test_eval_only_prioritizes_unhandled_custom_reward_errors" \
  "$T::test_deferred_judge_records_custom_reward_fallback" \
  "$T::test_sync_reward_worker_preserves_custom_reward_fallback" \
  "$R::test_sync_reward_runs_in_worker_without_blocking_event_loop" \
  "$R::test_batched_sync_custom_reward_keeps_payload_contract"
复跑额外的 SGLang 分组评分和同步 RewardWorker RPC

第一条命令复用单样本用例的故障注入和断言,将评分切到 group_rm=True。同批含一条生成失败,分别检查评分回退成功和未回退时的错误。

probe_dir=$(mktemp -d)
cat > "$probe_dir/test_pr705_group.py" <<'PY'
import pytest
from test_weight_sync_499 import (
    _reward_with_fallback, native_eval, nested_eval_reward, sglang_rollout,
    test_eval_only_prioritizes_unhandled_custom_reward_errors as single_case,
)

async def group_reward(args, group, *, evaluation):
    assert isinstance(group, list)
    return [await _reward_with_fallback(args, s, evaluation=evaluation) for s in group]

@pytest.mark.asyncio
@pytest.mark.parametrize("fallback", [True, False])
async def test_group(monkeypatch, nested_eval_reward, fallback):
    args, _, _ = nested_eval_reward
    args.group_rm = True
    args.custom_rm_path = f"{__name__}.group_reward"
    sglang_rollout.GenerateState(args).aborted = False
    await single_case(monkeypatch, nested_eval_reward, fallback)
PY
PYTHONPATH="$PWD/tests/cpu/engine/rollout:$PWD:${PYTHONPATH:-}" \
    python -m pytest -q "$probe_dir/test_pr705_group.py"

第二条命令在独立的 Ray worker 注册故障评分器,调用仓库的同步回退插件。

PYTHONPATH="$PWD/tests/cpu/engine/rollout:$PWD:${PYTHONPATH:-}" python - <<'PY'
from argparse import Namespace
import ray
from relax.engine.rewards import RewardWorker
from relax.utils.types import Sample

def register_failing_reward():
    from relax.engine.rewards import register_reward
    async def fail(args, sample):
        raise ValueError("injected")
    register_reward("probe_invalid", fail, mode="async")

ray.init(address="local", num_cpus=2, num_gpus=0, include_dashboard=False,
         runtime_env={"worker_process_setup_hook": register_failing_reward})
try:
    worker = RewardWorker.remote()
    path = "test_weight_sync_499._sync_reward_with_fallback"
    for recovery in (False, True):
        args = Namespace(inference_recovery=recovery, custom_rm_path=path, rm_type="probe_invalid",
                         allow_reward_fallback=True, eval_reward_key="score")
        ref = worker.compute_custom.remote(path, args, Sample(prompt="x"), {"evaluation": True})
        assert ray.get(ref, timeout=60) == {"score": 4.5}
finally:
    ray.shutdown()
PY

健康回调与并发评估错误

修复提交 14fbf5d7 将同角色健康回调的检查放在认领重启的锁内。正常训练收尾时,已知的评分或上报错误优先。只有生成失败时,仍会及时报错。原生 SGLang 评估将缺少 reward 字段识别为评分失败,并在同一请求的并发数据集和样本间保留已观察到的评分错误。

指定 CU12 镜像的 127 项定向测试通过。真实 CPU Ray/Serve 对照中,同一个评分响应缺少配置字段时,前一提交清理了训练分区一次,修复后 Controller 收到带字段名的 EvalJudgeError,分区清理次数为零。另验证了后台评分卡住、指标写入失败与 RPC 延迟返回的情况。中英文站点构建通过。本机未运行多节点故障注入。

该提交的 8 项必需检查均已通过。CPU 为 10,941 项通过、115 项跳过,另有 31 个子用例通过。H20 单卡、四卡单测以及两项 GPU 和一项 NPU 集成均通过。单元测试 · 集成测试

并发评估与恢复

行为修复 b71dd88e 处理了 2 个 P1 和 2 个 P2。局部恢复等待旧操作、评估提交和评分共用同一截止时间。恢复线程在退出前记录终止性的评分错误,防止后续健康回调将其覆盖。旧 Rollout 在排空前关闭评估入口,并跟踪每个已受理请求的生成、评分和上报。

  • 在 CU12 训练镜像中,该提交通过 1,275 项 CPU 回归和 10 个子用例。
  • 后续修复 bda8ba65 修正 OpenAPI 构建时意外导入评分运行时依赖的问题,并修正 docstring 格式。该版本在镜像中复跑 59 项定向回归,全部通过。在仅安装 FastAPI、Pydantic 及其依赖的环境中,四份 OpenAPI 和中英文站点成功生成。
  • 在该版本的真实 CPU Ray/Serve 进程中,较晚请求先完成时查询返回 done=false,排空后的新请求返回 HTTP 503。内联结果写入失败以及另一请求仍卡在生成时的后台评分失败都能传回。将恢复预算设为 1 秒并让评估卡住,Controller 在 1.001 秒后超时,清理训练分区调用次数为 0。本机未运行 GPU 或多节点故障注入。

最终提交的远端单测全部通过。CPU 为 10,931 项通过、115 项跳过,另有 31 个子用例通过。H20 单卡、四卡单测以及 Qwen3.5 双卡视觉语言、四卡 GPU 异步、四卡 NPU 异步集成测试均通过。

前次复审修复

415fc621 修复了四种恢复场景。

  • 在 fully-async 和 hybrid 下,如果 Actor 已提交最后一步,或重建未训练分区所需的消费者已经退出,Rollout 故障会在清理分区前转全局重启。
  • hybrid 和 colocate 启用 --keep-old-actor 时使用引擎级容错,保证旧策略快照按原训练流程轮转。纯 fully-async 仍支持组件级恢复。
  • 替换 Rollout 前等待旧实例完成已提交的异步评分和上报。评分失败会传回训练入口,全局重启也可以接管仍在等待评分的局部恢复。
  • 从 checkpoint 加载游标遇到数据集指纹不匹配时,训练直接报告原始错误,保留推理恢复预算。

在 cu12 训练镜像中运行了 34 个相关 CPU 测试文件,1072 项测试和 10 个子测试全部通过。真实 CPU Ray/Serve 进程验证了游标和评分错误能跨进程传回 Controller。另用实际参数解析器验证了 hybrid 的旧策略准入,用实际 Advantages 循环验证了末步回退保留分区。中英文文档构建通过。本轮未在本机运行 GPU 或多节点故障注入。

复审修复 5a189bf6 将组件恢复限定在启动时的引擎池,原生和外部扩容均在创建请求前返回 HTTP 409。测试使用公开请求列表确认队列为空,并确认执行入口未被调用。扩缩容相关 107 项测试通过,中英文文档构建通过。

复审修复 7d36a1ef 恢复训练后权重传输的 600 秒等待上限。开启组件恢复时,如有权重 rank 始终 pending,Actor 保留同步预约与训练分区,交给全局重启。正常训练和前向计算继续等待各 rank 自然完成。新增 pending rank 用例在旧代码上失败,修复后两个相关 CPU 测试文件共 59 项通过。 真实 Ray CPU 对照把等待上限缩短到 0.6 秒。旧实现超过 1.2 秒仍卡住,新实现在 0.604 秒报错;Ray 此时仍有 1 个 pending rank,训练步和分区均保留。

复审修复 1ce96532:

  • Controller 在 TQ 初始化及集群 attach 检查结束后选择恢复模式。实际使用 MooncakeStore 时保留引擎级容错,auto 回退 SimpleStorage 时可以启用组件恢复。全局重启复用配置时,先移除旧 Ray 句柄,再启动节点缓存清理。
  • 组件恢复模式拒绝外部引擎扩容和手动引擎恢复,两个 HTTP 入口均返回 409。回归覆盖未登记、未派发请求以及原有成功路径。
  • 在隔离 CPU Ray 环境复现了从旧会话序列化恢复句柄导致的原生错误,并验证清除旧句柄后节点 RPC 成功。中英文文档构建通过。

本轮复审 468de314 修复了 full-async/hybrid 权重握手和同步非共置的恢复选择。修复前,Rollout 准备、ActorFwd 探测和 Rollout 释放三处连接异常均被吞掉。修复后,三个回归均验证 Actor 保留同步预约和原训练分区,训练步不会前进。准入测试使用真实 CPU 状态矩阵,反转就绪值的对照会失败。

验证结果:34 个相关 CPU 测试文件共 1055 项通过,另有 10 个子测试通过。最终使用 CPU Torch 张量的准入测试文件另行复跑,21 项通过。隔离的 CPU Ray Serve 烟测确认关闭健康检查后,训练入口以错误码 1 退出,等待中的接收副本和其子 rank 在 Ray 关闭前已终止。完整文档构建通过。本轮未运行 GPU 或多节点故障注入。

本轮复审修复 aaf4d1d7:

  • 正常训练与前向等待全部 rank 完成。启用局部恢复时,单个 rank 失败后限时排空其他 rank,启动与恢复阶段的权重同步也保留时限。CPU 容器中 34 个相关测试文件共 1050 项通过,另有 10 个子测试通过。独立的真实 Ray CPU 烟测以缩短的恢复时限覆盖慢 rank 正常完成、维护超时、故障后其余 rank 未完成及全部结束后的错误传播。
  • 直接验证严格清理等待最后一个存储 ACK。全部 ACK 成功才释放 Controller 索引,任一失败都保留索引。在进程内把清理改为首次失败即返回,新增回归能捕获提前返回。
  • 修复离线 OpenAPI 生成器对运行时模块的导入。仅安装 FastAPI 和 Pydantic 及其依赖即可生成四份服务规范;完整 npm run docs:build 通过。本轮未重跑 GPU 或多节点训练。

最终提交 e97938f3 按 CI 要求调整两处 docstring 的换行,18 项定向回归复跑通过。

历史版本的验证记录

当前 CPU CI 修复版本:f95759d61db7f4f529eeba1896a47f8d96ac2ee9,合入 main@c75b0a1c 对齐 CI 的合并测试版本。两个跳过构造函数的 Rollout 测试对象补齐 _resume_data_source 和真实 RecoveryGate 初始化,仅增加 3 行,不新增用例或生产兜底。原 7 项失败已在本机复现,修复后相关 98 项 CPU 测试通过。新版本远端 pre-commit 已通过,CPU 单测等待 runner:本轮 Unit Tests。

当前修复版本:54fa2be7d7c8ed6c89041611d048456fbed0a260。离线准入三模式回归在修复前全部失败、修复后通过;相关恢复测试 83 项、离线运行时与 Actor 分区测试 71 项通过,共 154 项。全量 pre-commit 通过,独立复核未发现阻塞问题。本轮未运行 GPU/多节点训练,以下历史硬件证据仍仅对应各自注明版本。

此前验证版本:02bbea180f325e084f4ac4c0a120db6c77289255。本轮 80 项相关 CPU 测试通过,全量 pre-commit 通过;未重跑 GPU/多节点训练。以下既有验证记录仍对应各自注明版本。

本次冲突处理:975194876d24f0ff633dc94dc7c9c077f28675bd 合入 main@d0e00f3。Controller 同时保留启动同步失败时取消其余任务,以及 recovery 准入和成功后的解锁;同步适配旧测试桩的 rollout_only 参数。

本轮验证:本机 387 项 CPU 测试及 10 个子用例通过;此前指定镜像内 39 项后端/恢复/LoRA 同步 CPU 测试通过,合计 426 项及 10 个子用例;冲突文件 Ruff 检查通过。本轮未重跑 GPU/多节点训练,以下 GPU 证据仍对应原注明版本,不能视为本次合并版本的 GPU 验证。

此前验证实现:2ee4ffc6d63bb(生产tree 1e149bbe234527970c2f65416fa7cf8d12a8cbaf)。本轮只调整7个已有生产模块,未修改FSDP实现、CLI或agent/skill。GPU固定源码与提交仅有两处新增docstring的自动换行差异,无行为改动;最后一个提交仅适配测试夹具,生产tree与7caada8相同。

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

CPU:当前提交的全量CPU CI为 9909 passed、0 failed、155 skipped,另有3个subtests passed。跳过项未计通过。原11项失败均为初始化测试手工构造配置缺少backend字段及manager配置响应,已只改夹具并保留原有断言。

本机相关套件分别1077项、真实Ray/Serve全局恢复及收发回执206项、CI夹具文件23项通过;本机21项既有tokenizer前置条件skip未计通过。最终等待策略变更后另有86项关键回归及3个subtests复跑通过。未手动运行未分组的全仓pytest tests/。

本轮GPU四项均正常退出并通过独立审计。使用目标训练镜像(ID sha256:7be0cf58e0007e1d6d06eb233d62d4cb8efcf5294e6c10e6fce94a99b95cda1b)、已有Qwen2.5-1.5B-Instruct+GSM8K资产、单节点H800、训练TP2/推理TP1、非零有限梯度及decode CUDA graph。

场景 实测结果
关闭recovery的统一编排基线 4rank均完整完成rollout 0..1,无故障注入或恢复,exit0
Colocate Rollout局部恢复 4rank完成0..5;local1/global0,训练对象和CPU快照身份保持,4个旧引擎进程树退出,4个替代引擎版本4匹配sender4,exit0
Fully-async跨角色共享累计预算 Rollout/Fwd/Rollout三次local后两个原Actor rank均继续训练,attempt1/2/3不清零;第四次Fwd异常在sync=False/unsafe=False时原生报budget(3) exhausted、attempt4;global恰1次后新2rank完整0..15,exit0;严格17项检查全通过
Hybrid Rollout局部恢复 4rank完成0..5;local1/global0;训练实例、model/optimizer/scheduler保持并继续推进,DCS实际接收方等于两个替代引擎的预期集合,exit0

四项均验证真实恢复和后续训练,不以服务启动状态代替通过。完整日志、argv、原始观察和审计保留在本机,实验产物未加入源码。

历史GPU边界:d16fbf9还实测通过DCS部分接收拒绝与全局回退、HealthChecker全局恢复及原生token回执链。这两项未在本轮新编排上重新运行GPU;本轮真实Ray/Serve和回执CPU回归覆盖了对应控制链,不冒充GPU重测。

边界:Ray按仓库本机入口提前启动;未验证多节点、推理TP2、长期收敛、吞吐等价、GPU/节点丢失或hung检测。全局重启从HF重建,不承诺跨global保留optimizer。对象身份/版本不等于逐字节数值等价。此前提交通过的远端检查包括:pre-commit、CPU全量、H20单卡/四卡单测、多模态GPU集成、全异步GPU集成及全异步NPU集成。

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

上表只记录本版本实际执行的测试;每个训练用例保留独立 driver/Ray 日志、argv、原始观察与审计结果。

保留训练 Actor、optimizer 和 scheduler,在共享累计预算内局部重建
Rollout 或独立 ActorFwd,并在确认旧工作终态和替代实例接管后继续训练。

组件拥有恢复准入,Ray 组协调服务握手和权重/评估派发,恢复执行器
拥有服务生命周期,Megatron 与 DCS 分别拥有本地模型导出和传输确认。

基于 PR redai-studio#548(RexFlux/Relax@0ab3d29)的功能与文档进行架构重划。
聚焦 CPU 回归 193 项通过;完整 Megatron/GPU 恢复验证仍有环境缺口。
@rai-studio-bot

rai-studio-bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

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

Remove the stateless core recovery executor and let Controller own the
cross-service recovery sequence. Rollout owns its pending data window
and replacement router configuration; the training backend keeps local
training state and metrics rather than recovery policy.

Preserve metrics and evaluation ordering across the deferred inference
tail, including direct backend callers. Validate with 403 focused CPU
tests and local GPU fault injection in colocate, async, and hybrid modes.
@Yangruipis Yangruipis changed the title feat(recovery): coordinate inference recovery feat(recovery): isolate inference recovery ownership Nov 16, 2026
Make Megatron training and forward calls execute only their local work.
Components always coordinate weight sync, evaluation, and metrics; the
recovery switch controls admission and failure handling rather than
selecting a second backend execution path.

Move RL evaluation HTTP to the existing inference coordinator, preserve
local offline evaluation, and align startup/recovery sender and receiver
steps explicitly. Keep FSDP's backend contract unchanged.
Supply the normal parsed backend setting and mock the manager publication
configuration in the existing initialization fixtures. Keep all sync and
offline assertions unchanged. The affected file passes all 23 cases.
Preserve main startup sender/receiver cancellation and receiver selection,
while retaining recovery admission and success-only synchronization release.
Align the existing recovery startup test double with rollout_only.

Validation: 387 CPU tests and 10 subtests passed; Ruff checks passed.
Select component recovery through --use-fault-tolerance for supported
configurations and retain engine recovery elsewhere. Prevent legacy
monitors, rebuilding, and fault injection from overlapping the new flow.

Remove the separate enable environment variable while retaining the local
attempt budget and drain timeout. Update existing tests and both guides.
@Yangruipis
Yangruipis marked this pull request as ready for review November 17, 2026 10:59
@Yangruipis
Yangruipis requested review from a team and NINGBENZHE November 17, 2026 10:59
@rai-studio-bot

rai-studio-bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Nyanpasu 审查看板

审查状态: ✅ 已通过

审查版本: 1e6e9c0

目标分支: main

F25 已修复。中英文指南和 PR 正文写清自定义数据源保留游标的条件。此次只改文档,建议将剩余的局部恢复改动保留在同一份 PR。

审查阶段进度范围与结果
常规审查 ✅ 已完成 已核对两份指南、当前 PR 正文、恢复调用与全局回退。原讨论已解决。
深度审查 ✅ 已完成 正文新增两项验证记录。作者报告在 1e6e9c0 的单机 H800 hybrid 训练中,替代 Rollout 少一个权重接收方时拒绝局部恢复并完成全局重启。隔离 CPU Ray/Serve 使用训练和队列替身,观察到自定义数据源缺少 discard_pending() 时进入全局重启。本轮核对了实现和版本,未独立复跑。当前文档构建、静态检查和 NPU 异步集成已通过。

审查发现

待处理
编号 严重性 问题状态规则来源
暂无待处理的记录。
已解决或已取代
编号 严重性 问题状态规则来源
F1 Low severity 将配置说明对齐到复用的容错开关 ✅ 已解决 局部推理恢复 · 配置开关
F2 Medium severity 为严格清理补充 ACK 失败回归 ✅ 已解决 AGENTS.md · 资源清理风险的行为验证
F3 Medium severity 同步非共置模式保留引擎级容错 ✅ 已解决 —
F5 High severity [experimental · ERR001] 探测失败时停止提交未完成的权重同步 ✅ 已解决 —
F6 Medium severity [experimental · ERR001] 确认 Rollout 已恢复生成再结束同步 ✅ 已解决 —
F7 Medium severity [experimental · TST002] 用实际状态矩阵验证恢复准入 ✅ 已解决 Relax 测试准则 · 替身边界
F8 Low severity [experimental · PR001] 在 PR 说明中标明 hybrid 指标刷新顺序 ✅ 已解决 —
F9 Medium severity 在扩容入口落实组件恢复的资源限制 ✅ 已解决 局部推理恢复 · 框架管理的静态资源
F10 Medium severity 明确报告引擎级恢复操作在组件模式下不可用 ✅ 已解决 —
F11 Medium severity 按实际 TransferQueue 后端选择恢复模式 ✅ 已解决 —
F12 Medium severity 明确原生扩容后的局部恢复行为 ✅ 已解决 局部推理恢复 · 框架管理的静态资源
F13 Low severity [experimental · TST005] 通过公开的请求列表检查未入队 ✅ 已解决 Relax 测试准则 · 行为验证
F14 High severity 给恢复前的评估排空设置截止时间 ✅ 已解决 —
F15 Medium severity 在健康回调接管前锁定评估的终止结果 ✅ 已解决 —
F16 Medium severity 排空所有已受理的评估任务 ✅ 已解决 —
F17 Medium severity [experimental · ERR001] 保留内联评估的报告错误 ✅ 已解决 局部推理恢复 · 评估错误处理
F18 Medium severity 最终排空优先传播已知评分失败 ✅ 已解决 —
F19 Medium severity 将内联评分结果的字段解析失败标记为终止错误 ✅ 已解决 —
F20 Low severity [experimental · ERR001] 说明评估生成失败后的恢复行为 ✅ 已解决 —
F21 Low severity [experimental · TST004] 让最终排空测试观察训练循环已处理截止时间 ✅ 已解决 —
F22 Medium severity 仅记录退出评分边界的错误 ✅ 已解决 —
F23 Medium severity 保留显式包装的评分失败 ✅ 已解决 —
F24 Low severity [experimental · PR001] 标明各项评分验证的范围 ✅ 已解决 —
F25 Low severity [experimental · PR001] 说明自定义数据源保留游标的条件 ✅ 已解决 —

改进建议(非阻塞)

精简

💡 生产代码 · 1 条建议

恢复专用入口可以复用已有的维护等待方法。

范围建议保留的行为与验证依据
Actor 重绑 Rollout、共置恢复推权重、传输重置及 ActorFwd 恢复停机 替换
复用 RecoveryGate.wait_for_maintenance,让维护等待策略有统一入口。
这些生产入口都在组件恢复状态已启用时调用,等待全部 rank 结束,并在仍有 rank 未结束时触发全局回退。
Controller 和 Service 仅通过局部恢复流程调用这些入口。启用恢复时 wait_for_maintenance 使用同一个 wait_all。 https://github.com/redai-studio/Relax/blob/a091790c02b4d037bbc2f8c3509cf0ea2ad46925/relax/components/actor.py#L132-L150 https://github.com/redai-studio/Relax/blob/a091790c02b4d037bbc2f8c3509cf0ea2ad46925/relax/components/actor_fwd.py#L127-L132 https://github.com/redai-studio/Relax/blob/a091790c02b4d037bbc2f8c3509cf0ea2ad46925/relax/components/recovery.py#L66-L71

相关 PR

💡 实现与合入建议

#548 与本 PR 都实现局部推理恢复。#791 已提供常规训练后的组级编排,#548 当前与 main 有合入冲突。

https://github.com/redai-studio/Relax/pull/548 · 0ab3d29ad44f7fee7366ef675a2d710d83a63fda · 目标分支 main

实现取舍: 倾向沿用 #705 与 #791 的组级接口及组件职责边界,保留替换前的评估排空和评分错误传播。#548 的历史 GPU 恢复验证可供参考,证据对应当时提交。

当前 PR 调整: 保留恢复准入、在途操作等待、未训练分区清理、替换接收方确认和全局回退。若改用 #548,复用 #791 的标准同步接口,并移植 #705 的评估排空和错误传播回归。

合入顺序: 可优先推进 #705,再由维护者处理 #548 中重叠的实现。若优先推进 #548,应先更新基线、适配 #791 并验证上述评估契约,再从 #705 裁掉重复恢复路径。

依据与验证范围: 核对了两个 PR 的基线和实现。#705 正文报告四组单机 H800 故障注入,第四组直接使用当前提交 1e6e9c0。另有同版本的 CPU Ray/Serve 数据源探针,观察至全局重启入口。运行结果为作者报告。 https://github.com/redai-studio/Relax/pull/791 https://github.com/redai-studio/Relax/blob/0ab3d29ad44f7fee7366ef675a2d710d83a63fda/relax/core/inference_recovery_executor.py#L53 https://github.com/redai-studio/Relax/blob/1e6e9c096e0de1f3a4b78bcbc8ab5af991dbcf5c/relax/core/controller.py#L1374

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.

审查结论:有非阻塞建议

已完成 02bbea1 的恢复职责、正常训练阶段、模式契约及测试审查,留下两项非阻塞建议,未确认阻塞缺陷。当前 CPU CI 为 9935 passed、155 skipped、10 subtests passed;本次未本地重跑测试,也未独立验证当前 head 的 GPU 局部恢复与多节点边界。

完整审查与改进建议

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

Comment thread docs/en/guide/configuration.md Resolved
Comment thread relax/utils/tq/recovery_storage.py Resolved
Yangruipis added a commit that referenced this pull request Nov 18, 2026
## What

新增只读架构专家,并接入仓库的专家入口与 code-review skill。包含专家定义、加载入口、review
skill,以及直接写入专家正文的架构案例。

## Why

功能测试通过无法说明代码职责归属合理。架构评审需要判断代码放置、模块边界、依赖方向,以及新增抽象是否必要,避免只修局部故障或移动同一份耦合。

## How

- `arch-expert.md` 提供完整专家指引;复用现有 `.codex/agents`、`.claude/agents` 到
`.opencode/agents` 的链接。
- `arch-expert.toml` 定义 Codex 自定义代理 `arch_expert`,要求先完整读取
Markdown,并保持只读。
- `AGENTS.md` 增加架构任务触发入口及不同工具中的代理名称。
- code-review skill 要求审视完整职责链,并单独给出设计合理性与简洁性的结论。
- `.codex/agents/arch-expert.md` 正文内直接记录 #548 → #705
的职责优化案例:组件统一编排、Controller 协调恢复、资源操作归拥有者,并删除内部兼容双路径。案例随完整专家指引一起读取,无独立
reference 文件。

不包含 recovery 实现、实验记录或 RSI 专用回执/等待流程。

### 专家如何产出:以真实改动驱动指引迭代

这份专家指引通过 DeepSeek 与 Codex 分工的 RSI 迭代形成:DeepSeek 负责生成和改进
`arch-expert.md`,独立 Codex 将指引用于真实 PR
的架构评审与修改,主评审根据代码结果给出反馈。迭代对象是可复用的架构判断方法,代码改动则用于检验指引是否能落实到职责、边界和调用关系上。

```mermaid
flowchart TD
    A["真实任务:评审 PR548 的恢复架构"] --> B["DeepSeek 生成或改进专家指引"]
    B --> C["固定本轮 MD 与代码起点版本"]
    C --> D["新开独立 Codex 会话<br/>不继承上轮对话,完整读取专家指引"]
    D --> E["检查相对 main 的完整 diff<br/>优化架构并验证行为"]
    E --> F["主评审独立评估代码结果<br/>按固定标准评分"]
    F --> G{"是否继续迭代?"}
    G -->|"未达预期且未到上限"| H["向 DeepSeek 返回分数与概括评语<br/>不提供评分细则或具体修复方案"]
    H --> B
    G -->|"符合预期或达到轮次上限"| I["整理专家指引、代码结果与验证结论"]
    I --> J["通用专家进入 PR706<br/>架构实践与案例见 PR705"]
```

流程设置最多 10
轮,以架构评审结论决定是否继续。评测侧关注职责归属、模块位置、依赖方向、抽象必要性及行为保持;反馈给指引生成侧时仅保留分数与概括评语,避免把具体修复答案写进专家规则。独立会话及显式加载用于减少历史上下文干扰;功能测试用于验证行为保持,架构合理性由完整职责链的评审判断。过程中结合维护者反馈校准架构目标,最终将实践经验整理为通用指引。

### 实践案例:从 PR548 到 PR705 的推理恢复职责优化

[PR548](#548)
提供真实恢复场景,[PR705](#705)
展示后续完成的职责重构。关键问题是训练后端同时承担服务握手、恢复准入和 RL HTTP 评估,而独立 Executor 又借用
Controller 的状态进行恢复编排。优化围绕“控制决策归编排者,资源操作归拥有者”展开,范围为 Megatron 路径。

```mermaid
flowchart TB
    subgraph Before["原实现 PR548"]
        BC["组件"] --> BT["训练 rank<br/>计算、恢复准入、服务握手、同步与评估"]
        BX["独立恢复 Executor"] --> BS["借用 Controller 的服务集合与状态"]
    end
    subgraph After["职责重构 PR705"]
        AC["组件<br/>阶段编排与 RecoveryGate"] --> AT["训练后端<br/>计算、模型状态与通信操作"]
        AC --> AS["同步协调模块<br/>服务握手、接收方选择与 RL 评估"]
        CT["Controller<br/>恢复流程编排"] --> OW["Service / Rollout / updater / DCS<br/>各自管理资源、清理与接收确认"]
    end
```

- 组件统一执行训练、同步、评估阶段;恢复开关控制准入与失败处理,收敛内部兼容双路径。
- 跨服务握手和 RL HTTP 评估从训练 rank 移到同步协调模块;后端保留模型、CPU 快照、通信操作与本地离线评估。
- 没有独立资源或生命周期的 Executor 收回 Controller;生成窗口清理由 Rollout 封装,传输资源与完整接收确认由
updater/DCS 管理。

这些调整减少跨层状态依赖和重复路径,保持用户可见的训练与恢复语义。案例已直接写入 `.codex/agents/arch-expert.md`
正文,供后续评审参考职责判断方法;具体目录与抽象仍需依据实际调用链决定。

## Testing

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

- 全量 pre-commit 检查通过。
- skill validator 与 TOML 解析通过,确认共享 Markdown 链接可解析。
- 原提交 `6ad2f58` 已通过 Codex CLI 0.167.1 新会话启动 `arch_expert`
的加载检查,子代理不继承历史,返回的专家文件 SHA-256 与该版本一致,并确认只读角色及正文规则。
- 已将案例并入专家正文,删除独立 reference 文件及跳转;确认 `.codex/agents`、`.claude/agents` 与
`.opencode/agents` 入口内容一致。合并后未重跑子代理加载实验。
- 未运行训练测试:本 PR 只改变开发代理配置与工作指引,不修改训练实现。加载检查不等于架构判断质量评测。

## Type of Change

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

## Screenshots / Logs

无需截图。加载检查在临时目录执行,未将实验产物加入仓库。

---------

Co-authored-by: Yangruipis <[email protected]>
RexFlux
RexFlux previously approved these changes Nov 18, 2026

@RexFlux RexFlux left a comment

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.

lgtm

Reuse is_offline_mode to keep SFT, DPO, and RM on their existing data
path when fault tolerance is enabled. This prevents the rollout recovery
gate from waiting for train partitions that offline producers never write.

Cover all three objectives through the existing recovery policy tests.
Merge main to match the PR CI checkout and retain its dataset-load error
handling. Initialize the recovery gate and resume-data flag in existing
Rollout test shells that bypass the constructor.

Reproduced all seven CPU failures before the fixture fix; 98 related
tests pass afterward. No new test cases or production fallback paths.
Preserve replay field selection and partition retirement, checkpoint scheduling, and Judge cleanup across recovery. Keep reference replay on the engine-level fault tolerance path because retired partition names cannot be reused within its run.
@Yangruipis

Copy link
Copy Markdown
Collaborator Author

/review

Keep startup and recovery weight synchronization bounded. After a training rank fails, settle its peers before recovery can reuse their resources. Cover delayed storage ACKs and restore the offline OpenAPI build.
@Yangruipis

Copy link
Copy Markdown
Collaborator Author

/review

@Yangruipis

Copy link
Copy Markdown
Collaborator Author

/review

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

审查结论:需要修改

已复核 e97938f。双语配置和存储 ACK 两项旧反馈已解决。组件恢复的权重握手仍可能在接收端未完成时提交训练步。当前版本文档构建、CPU 单测及 GPU/NPU CI 已通过;新增故障场景通过源码和调用链核查,未在集群复现。相关发现和拆分结论见审查看板。

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

Comment thread relax/components/recovery.py Resolved
Comment thread relax/distributed/ray/inference_sync.py Resolved
Comment thread relax/distributed/ray/inference_sync.py Resolved
Comment thread relax/distributed/ray/inference_sync.py Resolved
@Yangruipis

Copy link
Copy Markdown
Collaborator Author

/review

Yangruipis added a commit that referenced this pull request Nov 25, 2026
)

## What

将 Megatron 训练后的推理服务握手、权重同步调度和在线评估迁到 Actor 组件和 Ray 训练组。训练 rank
继续执行训练、保存和实际权重传输。这是 #705 的前置 PR,可单独合入 `main`。

## Why

原先各 rank 的训练入口包含 HTTP 握手、选择接收者和评估收尾。把这些步骤放到组件层后,训练组每个版本只需与服务协调一次。后续 #705
可以在同一边界处理推理服务故障。

## How

- Actor 等训练组完成本轮计算,再协调权重和评估。普通、hybrid、fully async 三条训练路径共用这个边界。FSDP
继续使用它已有的训练入口。
- 托管 LoRA 保留自己的发布协议。启动时先配置托管发布,再绑定训练组,组件和 rank
在绑定时分别读取同一配置。[RolloutManager
配置入口](https://github.com/redai-studio/Relax/blob/580aac1d898f378b8e4307064033c560ab4d956d/relax/distributed/ray/rollout.py#L1178-L1212)
- 普通异步握手成功后仍调用已有的 `/recover_rollout_engines`。ActorFwd 和 Reference
保留原有权重接收流程。
- hybrid 模式在发起本轮评估、结束权重更新窗口后刷新指标。最后一轮会等待评估完成。SFT、DPO 和 RM 的离线评估仍由训练 rank
执行。

## Testing

- 最新提交 `42bb5f91` 的 8 项远端检查全部通过。CPU 和单卡、四卡 H20 单测以及双卡多模态、四卡 GPU 与 NPU
异步训练均通过。最后一次测试改动在两层分别用真实 Ray/Serve 复跑了 3
个故障恢复场景。[单元测试](https://github.com/redai-studio/Relax/actions/runs/45574185399)
· [集成测试](https://github.com/redai-studio/Relax/actions/runs/45574185489)
- 复审修复版本 `580aac1d` 在 CU12 运行 8 个 CPU 测试文件,236 项通过。DCS 客户端访问真实 HTTP
地址,连续收到 503、503、200,同一训练 worker 先后返回两次原始拓扑错误,第三次完成训练。该实验采用单 rank
Gloo,模型计算与 GPU 权重传输使用替身。
- fully async 的成功同步计入 `train`。失败轮不刷新指标,从训练计算结束到下一次重试的区间计入下一份
`train_wait`。定时用例核对了成功后的下一步和 timeline。Rollout
地址解析失败会向上传播,已发起的异步权重更新仍执行结束握手。
- 普通权重更新复用训练组方法,两个具名的异步入口负责向各 rank 提交。控制器可以按需等待每个 rank 的结果。
- 已在仅装 FastAPI 和 Pydantic 的文档生成环境导出四份 OpenAPI 规范,完整 `npm run docs:build`
构建通过。
- 在 CU12 镜像中隐藏 GPU,运行 Megatron、FSDP、Actor、权重握手和训练模式的 10 个相关测试文件,226 项通过。
- 用两个真实 CPU Ray worker 和本机 HTTP 服务验证了 5 种情况下的调用顺序,覆盖
colocate、hybrid、fully async 和握手失败。模型计算使用轻量替身。
- 使用双进程 Gloo 验证 SFT、DPO、RM 的离线评估间隔、rank 0 数据清理和 barrier;模型计算和数据服务使用测试替身。

- [ ] `pre-commit run --all-files` passes
- [x] Tests pass (targeted suites above)
- [x] 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
- [x] Refactoring (includes the hybrid metrics ordering described above)
- [ ] Performance improvement
- [ ] CI/CD or build changes

## Screenshots / Logs

定向测试可从 checkout 根目录复跑,例如 `python -m pytest -q
tests/cpu/components/test_simple_inference_components.py
tests/cpu/distributed/ray/test_inference_sync.py
tests/cpu/backends/megatron/test_train_async_metrics.py
tests/cpu/backends/megatron/test_hybrid_weight_sync_lifecycle.py`。

---------

Co-authored-by: Yangruipis <[email protected]>
@Yangruipis
Yangruipis deleted the branch redai-studio:yangruipis/refactor/post-train-inference-sync November 25, 2026 08:33
@Yangruipis Yangruipis closed this Nov 25, 2026
@Yangruipis Yangruipis reopened this Nov 25, 2026
@Yangruipis
Yangruipis changed the base branch from yangruipis/refactor/post-train-inference-sync to main November 25, 2026 08:34
@Yangruipis

Copy link
Copy Markdown
Collaborator Author

/review

@Yangruipis Yangruipis closed this Nov 25, 2026
@Yangruipis Yangruipis reopened this Nov 25, 2026
@Yangruipis Yangruipis changed the title feat(recovery): isolate inference recovery ownership feat(recovery): add local recovery for Rollout and ActorFwd Nov 25, 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.

审查完成

已复核 a091790c 相对 main@7354e4fa 的改动。#791 已独立合入,建议将剩余的 Rollout 与 ActorFwd 局部恢复保留在一份 PR 中。留有一条文档建议。当前提交的 CPU、GPU 和 NPU CI 已通过,本轮采用源码和 CI 证据,未复跑多节点故障注入。 审查看板

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

Comment thread docs/en/guide/inference-recovery.md 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.

审查通过

已复核 1e6e9c09。中英文指南和 PR 正文均已补齐自定义数据源的游标约定,F25 已解决。此次只改动两份指南,文档构建和静态检查已通过。建议将剩余的局部恢复改动保留在同一份 PR。 审查看板

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

@RexFlux
RexFlux self-requested a review November 25, 2026 11:17

@RexFlux RexFlux left a comment

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.

lgtm

@RexFlux
RexFlux merged commit 50eb517 into redai-studio:main Nov 25, 2026
22 checks passed
dirtyDan0 added a commit to dirtyDan0/Relax that referenced this pull request Nov 29, 2026
Remove the managed, immutable multi-version LoRA publication introduced by
redai-studio#475 and redai-studio#476, and connect Agentic generation to the existing fixed-name
single-adapter path. This removes the version control subsystem, its public
configuration APIs, its Session ownership protocol, and its custom SGLang
control endpoints. Keep the original LoRA training and weight-transfer
paths together with the independent correctness fixes carried by those PRs.

1. The capability Relax already had

Before redai-studio#475 and redai-studio#476, Relax could train LoRA with either merge mode or
adapter mode. Merge mode folds the learned delta into the base weights
before transferring them to inference. Adapter mode sends the frozen base
once and subsequently transfers the adapter under the fixed name
relax_policy_lora. Colocate uses the existing in-memory tensor loading
path. Fully asynchronous training uses the existing bucketed NCCL path.
Ordinary rollout generation selects that adapter by sending its name as
lora_path in the native SGLang request.

That single-adapter transport is useful on its own. It reduces the amount
of weight data sent at each synchronization point. It already existed
before the version-publication PRs and remains the serving contract after
this removal. The inference engine can use its existing pause, cache
flush, same-name replacement, and resume sequence when weights change.

2. The concurrency problem that motivated the original feature

The reference was Miles #3127. Its motivating example has adapters A, B,
and C sharing a frozen base. They represent separate training identities
with their own data and training progress. When A finishes an update and
publishes A@2, existing generation using B or C should be able to continue.
An engine-wide pause and cache flush interrupts those independent tasks.
Miles addresses this by staging a fresh adapter name, transferring its
complete weights, validating the update, and opening it for sampling after
commit. The weight-update session in that path is a begin/send/end
transfer transaction.

Relax also has a possible overlap window in fully asynchronous training.
A new snapshot of its single training policy can be transferred while
requests using an earlier snapshot are still generating. The distinction
between separate training identities and successive versions of one
policy matters when choosing which parts of the reference to adopt.
Relax's integration continued to train one adapter with one current
optimizer state. It did not introduce independent A/B/C training jobs.

3. How the Relax requirement became substantially stronger

Task 7 explicitly required an Agent Session to bind a version on its first
generation and keep it through later tool turns, retries, and abort/resume.
RFC redai-studio#418 made that requirement concrete through a central version owner,
Session registrations, capacity accounting, and periodic reconciliation.
redai-studio#475 supplied the immutable identity and state machine. redai-studio#476 connected
that state to training export, engine loading, and resident Agent Sessions.
The broader contract was already present in the task and RFC before the
implementation was integrated.

The important change in scope was the lifetime of the version reference.
An inference request needs its selected weights while it can still be
forwarded, retried, queued, or executing. Whole-Session binding also keeps
the weights alive while an Agent has no inference request and is waiting
on a tool. A slow tool can therefore keep an old version resident across
several training updates. At the configured version limit, publication
must wait or skip until those Sessions release their references.

Whole-Session consistency is an additional sampling policy that needs its
own algorithmic or workload justification. The existing full-weight path
can use updated weights after rollout interruption and resumption. LoRA
training also continues to optimize the current adapter, including when
its batch contains samples produced by older versions. Keeping a Session
on an old inference version does not select that old adapter for its
training forward pass or make the batch automatically on-policy.

The managed publication mode made this stronger policy inseparable from
its concurrent-update mechanism. As a result, ordinary Agent execution
became an owner of inference-weight retention and cleanup.

4. How subsequent upstream work inherited the LoRA contract

The compatibility history helps explain the selective removal. The later
commits generally carried the Session-binding rules through changes to
shared infrastructure. Their fixes have value independently of the
sampling policy that originally required the version manager. The
following observations come from the upstream history through eb0ec97.
They describe observable code and test changes. Benefit and cost still
require a separate workload evaluation.

- redai-studio#628, 043d7a2, reworked Agentic admission and resource reuse. It kept
  lora_key, lora_binding, and the existing Session version selection. It
  changed finalization so a logical result could be published before the
  physical cleanup completed. To make that work with managed LoRA,
  _release_lora_session recorded a pending release before waiting for a
  binding task. If cleanup timed out during the wait, heartbeat still had
  responsibility for retrying the release. Its revised test explicitly
  allowed a terminal Session result while the old version's session_count
  remained one, then expected zero after background cleanup completed.
  This is a compatibility repair around an existing Session reference.
  Retain independent Session progress, result publication, background
  cleanup, and unconfirmed-request ownership. Withdraw the additional
  version reference and its pending-release/heartbeat protocol.

- redai-studio#655, d0e00f3, developed ordinary Qwen3.8 LoRA training and repaired the
  fixed-name adapter update failure path. The pre-existing managed branch
  remained alongside it. The important correction was that one rank's
  adapter-push failure had to reach all training ranks before any of them
  resumed generation or marked the new weights loaded. Keep that failure
  agreement and the ordinary model/adapter support. It does not depend on
  storing immutable versions or binding an Agent Session.

- redai-studio#720, 0f6dac5, addressed ordinary policy-sample and weight-sync
  consistency, including the effective checkpoint and quantization used by
  inference receivers. Its new sender and quantization tests were added to
  test_actor_lora_publication.py, which already hosted the managed LoRA
  tests. This made a file created for version publication contain useful
  ordinary synchronization coverage. Retain those tests in the original
  file and retain the receiver/configuration checks. Remove cases whose
  contract requires the deleted publication service.

- redai-studio#761, 21b3662, introduced shared router and multimodal replay ownership.
  It kept both the managed direct-engine transport and the normal router
  transport, wrapping them with post_generation_request. It added
  _BackendAttempt with the actual wire RID, target set, and send_done state.
  An abort acknowledgement arriving before a delayed generate request
  settled could not release ownership. _pending_backend_cleanups kept a
  Session alive while backend cleanup was unconfirmed. Managed tests also
  held session_count until a failed abort or release was safely retried.
  These changes show how a Session-bound weight reference had to follow
  the newer request-ownership model. Keep wire-RID tracking, replay leases,
  abort ordering and pending backend cleanup. Remove the separate managed
  transport, Session version reference, and LoRA release RPCs.

- redai-studio#791, 7354e4f, moved post-training inference coordination out of training
  ranks into the Actor component and inference_sync.py. It preserved the
  managed bypass of ordinary rollout-update readiness and completion
  handshakes. To select that behavior, the component queried
  get_lora_training_config and passed _managed_lora_publication through the
  shared coordinator. A feature-specific assumption therefore moved into
  the component-level orchestration API. Retain the once-per-group
  coordination, evaluation and metric settlement. Delete the old
  configuration lookup, managed parameter, and handshake bypasses.

- redai-studio#705, 50eb517, added local inference recovery around that coordinator.
  rebind_rollout_manager refreshed the managed configuration when replacing
  an inference target, and RecoveryGate supplied settlement and retry
  boundaries around training and weight synchronization. This continued
  the compatibility contract at a new lifecycle entry point. Keep rebind,
  RecoveryGate, waiting for all participating ranks, and verification of
  the expected replacement receivers. Rebinding the normal manager can
  proceed through these mechanisms after the version configuration query
  is removed.

- redai-studio#804, 8c11399, hardened ordinary multimodal IPC and request cleanup. Its
  interaction with the managed-LoRA test file was an additional fixture
  binding for _finish_ipc_dispatch. Preserve the production IPC lifecycle
  corrections and their ordinary tests. The fixture-only increment
  disappears with the removed feature test file. While rebasing the
  retained SGLang patch, keep the required IPC method bindings and use one
  consistent fixture adaptation where the old and new patch sections
  address the same lifecycle fields. Verify the resulting patch by
  applying it to the actual pinned source.

- redai-studio#805, 198f9a6, replaced the router infrastructure while keeping the LoRA
  branches around it. redai-studio#828, 250eca5, converted fault-tolerance and health
  arguments to direct reads inside the managed configuration checks. Keep
  the native routing and ordinary argument handling. The configuration
  checks that belonged exclusively to the removed version service are
  removed together with that service.

The version manager, runtime, training publisher, and managed engine
client under relax/engine/lora_versions and lora_client.py have identical
contents at redai-studio#476 and upstream eb0ec97. The repository's managed
configuration calls still occur in definitions and tests, with no training
script or example adding an automatic activation path. This establishes
how the in-repository integration evolved. External callers and deployments
are outside this source inspection.

The resulting pattern is that shared scheduling, replay, synchronization,
and recovery improved while continuing to honor a strong existing
Session contract. Maintaining that contract required repeated work in
surrounding systems even as the version-control core remained fixed.
A compatibility test demonstrates that a refactor respected its existing
contract. The justification for keeping whole-Session version pinning also
needs evidence that its sampling semantics and retention cost fit Relax's
workloads.

This removal follows those responsibility boundaries. Preserve each
independent correction at its existing owner and preserve the ordinary
single-adapter update path. Withdraw the version owner, cross-Session
weight-retention policy, dedicated transport and control APIs that caused
those systems to depend on managed publication. Reversing the original
PRs mechanically would also discard later useful work, so each affected
path is reduced to its ordinary behavior and its independent protections.

5. The concrete initialization conflict exposed by first-step prelaunch

The integration assigned a SessionKey in start_group only when a LoRA
runtime had already been installed. set_lora_runtime rejected a Shard with
any existing Groups. RolloutManager first synchronized and published the
initial adapter, then injected the runtime into the Shard fleet.

First-step prelaunch deliberately constructs PREPARE Groups before engine
initialization is complete. Their first inference requests remain queued
behind Runtime admission. Those Groups are safe to prepare before weights
are available, but the separate empty-Group configuration invariant still
rejects them. Merely deleting that check would also be unsafe. A Session
created before configuration could lack its key, and the old dispatch
branch used the presence of that key to select managed generation.

The implementation actually bound weights at the first permitted
inference dispatch. Nevertheless, its earlier key-allocation and runtime
injection rules imposed a stricter construction order. This coupled Agent
startup to initial weight publication and prevented the intended overlap
between preparing Agents and initializing inference engines.

This affected runs that explicitly configured managed publication. The
ordinary training scripts did not automatically enable that API-only mode.

6. Why the managed subsystem is removed

The additional policy required a dedicated LoRAVersionRuntime Ray actor,
SessionKey allocation, per-Session binding tasks, Shard registration,
release retries, heartbeats, sequence watermarks, engine inventory,
publication attempts, capacity states, and shutdown calls back into Shards.
Generation also acquired a LoRA-specific route directly to a verified
engine. Those responsibilities crossed training, rollout orchestration,
Agent lifetime management, and inference transport.

The integration further introduced shared-file snapshot publication and
an extra training control path alongside the working IPC/NCCL adapter
updates. Its automatic publication required a fixed Agentic/Megatron
fully-async pool and disabled recovery and several engine configurations.
These restrictions and ownership rules made the feature expensive to
maintain and exposed the initialization conflict described above.

The existing Agentic rollout-step boundary still pauses and aborts active
requests according to its scheduling rules. Resuming a Session on its old
adapter preserves weight identity across that interruption. It does not
establish uninterrupted execution for the entire Agent. Concurrent adapter
publication has a valid narrower purpose, but retaining the complete
Session-bound subsystem requires evidence for its stronger contract and
its integration cost. The feature is withdrawn here with that boundary
made explicit.

7. What this commit removes and restores

- Delete relax/engine/lora_versions, including immutable snapshot identity,
  shared-file artifacts, the version state machine, publisher, training
  publication coordinator, and the dedicated Ray actor.
- Delete the managed SGLang LoRA client and the Relax-specific inventory,
  load, fencing, and reclamation control protocol from the 0.5.17, 0.5.20,
  and 0.5.21 dependency patches.
- Remove RolloutManager's managed configuration, publication and actor-handle
  APIs, the publication concurrency group, and feature-specific fixed-pool
  restrictions on normal lifecycle operations.
- Remove Agentic runtime injection, SessionKey and version state, binding
  tasks, heartbeats, release watermarks, version metadata overrides, and
  LoRA-specific direct-engine generation and endpoint tracking.
- Remove the training publication configuration, topology lease, publication
  result handling, and the managed bypasses of normal weight-update
  readiness and completion handshakes. Retain the shared inference-sync
  implementation and its later recovery integration.
- Delete tests whose product contract disappears with the version manager,
  managed configuration, immutable publication, or whole-Session binding.
  Adapt mixed tests to exercise ordinary router, replay and request cleanup.
  Keep their original file names and their independent assertions.

SGLang's native ability to load named adapters remains available. The
removed API is Relax's additional managed publication and Session-binding
layer. Manual users of configure_lora_training, configure_lora_versions,
or get_lora_version_runtime must move to the ordinary adapter-mode path.

8. What is kept, and why each part remains useful

The fixed name relax_policy_lora, existing adapter export and gather,
colocated tensor transport, fully asynchronous NCCL buckets, merge mode,
and ordinary rollout request construction all remain in place. Ordinary
LoRA updates retain the existing scheduling and synchronization contract.
The later PRs also contain independent changes that were integrated around
the publication code. Retain those changes through their ordinary paths.

- redai-studio#655 keeps Qwen3.8 LoRA training and adapter export support. In the normal
  DeviceDirectBackend update, all training ranks reduce the adapter-push
  failure flag. A failed push raises before continue_generation, and only
  a confirmed successful push sets adapter_loaded and base_sync_done. This
  prevents rollout from using a partially updated adapter.
- redai-studio#628 keeps independent progress of Sessions within a Group and publishes
  the logical Session result before scheduling process and backend cleanup.
  _pending_backend_cleanups retains ownership of unconfirmed requests so
  cleanup can finish safely after logical retirement. The empty
  actor_fwd/reference-group gate also remains, avoiding communication to
  recipients that do not exist. Remove the separate LoRA Session-release
  and heartbeat work from this cleanup path.
- redai-studio#640 keeps synchronization of same-checkpoint NEXTN draft weights. The
  normal model and draft synchronization path continues to determine which
  inference weights are transferred.
- redai-studio#720 keeps effective receiver-checkpoint and quantization configuration
  during weight conversion and transfer. Its ordinary quantization cases
  remain in test_actor_lora_publication.py under the original file name.
  The file name alone does not make these cases publication-specific.
- redai-studio#761 keeps router and multimodal replay, response manifests, and cleanup
  using the actual wire request ID. Mixed replay tests use the ordinary
  router transport after removal of the LoRA-specific direct-engine path.
  Their success, lost-response, and late-publication expectations remain.
- redai-studio#791 keeps post-training inference coordination in the Actor component
  and inference_sync.py. Readiness checks, weight synchronization,
  evaluation completion, and metric settlement still run through the shared
  coordinator. Remove the managed flag and its handshake bypasses.
- redai-studio#705 keeps local inference recovery, RolloutManager rebinding,
  RecoveryGate settlement, and checks that the expected replacement engine
  actors actually received their weights. Rebinding no longer queries the
  deleted managed LoRA configuration API.

Keep unrelated image and model support already integrated around the
SGLang patches, including the CUDA 12/0.5.21 image work from redai-studio#503 and the
0.5.17 DeepStack correction from redai-studio#788. The dependency version pins and
existing platform patch application paths remain the basis of validation.

The following fixes introduced with the version feature also remain
because their failure modes are reachable without multi-version serving.

- Keep Megatron Bridge wrapper forwarding of *args and **kwargs in
  _make_adapter_splice_wrapper. Upstream adapter export can pass additional
  arguments such as exclude_adapter_base_prefixes. Dropping those arguments
  breaks ordinary adapter export as well. Its existing regression remains.
- Keep max_staleness > 0 in Agentic _step_can_close. With zero staleness,
  training must consume the current partition before a later rollout can
  proceed. Closing the current partition with missing samples can leave
  training waiting for rows that a blocked next rollout would have to
  produce. The existing zero-staleness regression remains.
- Keep ordinary LoRARegistry acquire and cancellation handling. Hold the
  registry lock while looking up an adapter and incrementing its request
  count so unregister cannot pass between those operations. If acquisition
  is cancelled after incrementing part of a batch, roll those increments
  back. This protects ordinary single-adapter load/unload as well.
- Keep ordinary SGLang request cleanup fixes. Requests dispatched to the
  scheduler retain their adapter reference until terminal output or abort
  acknowledgement. Parallel-sampling children share the parent's lease and
  keep it alive until all owners finish. A retired logical parent can still
  cancel its running children. These rules protect a single adapter during
  replacement as well as any normal named-adapter request.
- Keep the request lifecycle identity checks in the 0.5.21 patch. A delayed
  abort waiter or failed handler must not delete a new request that reused
  its RID. Validate a complete batch for RID conflicts before adding states
  so a later duplicate cannot leave an earlier half-registered request.
  Preserve the associated ordinary tokenizer lifecycle tests. The other
  supported SGLang patches retain their version-appropriate cleanup fixes.
- Keep the global Bridge parameter-name initialization and its regression
  for the first synchronization. That test also exercises a non-LoRA
  configuration and protects the normal weight-transfer path.

These retained pieces have explicit behavior and failure cases independent
of the removed version manager. Their presence is intentional, so this is
a selective removal that preserves independently useful fixes.

9. The small Agentic single-adapter connection

Ordinary rollout already sent lora_path=relax_policy_lora before redai-studio#475/redai-studio#476.
The earlier Agentic native /generate request did not carry that field.
After removing managed binding, enabling the engine's LoRA support alone
would still let such a request select the base model.

Add the same mode check and fixed-name field directly where the Agentic
SGLang payload is built. The implementation adds four nonblank lines and
reuses LORA_ADAPTER_NAME. Adapter mode selects the already loaded policy
adapter. Merge mode and full-weight requests retain their existing payload.
The existing router, request ID, admission, pause/resume, abort, replay and
cleanup paths carry the request. This closes the separate single-adapter
integration gap with a local request-field change.

10. Validation and evidence limits

During this removal, the retained dependency patches were applied to fixed
SGLang 0.5.17 29481685, 0.5.20 94602c9c, and 0.5.21 e00930c5 sources. All
three normal combinations, the 0.5.21 CUDA 13 two-stage application, and
the ROCm exclusion/overlay sequence applied successfully. The retained
0.5.21 embedded ordinary request regressions passed 13 cases after adapting
their existing fixture to the preserved lifecycle registration contract.
Those checks validate source transformation and CPU request behavior.

Final targeted CPU verification passed 34 existing eager Agentic generation,
backend abort-target, checkpoint-resume and Bridge forwarding tests. Three
temporary payload checks exercise the actual Agentic request construction
with controlled HTTP for full-weight, merge and fixed-adapter requests.
Full pre-commit checks passed against the complete tree. Temporary payload
checks are removed after execution. No permanent test file is added by this commit.

CUDA devices are unavailable in the local environment. Real Megatron
training, GPU numerical equivalence, multi-node execution, and rebuilt
training images remain unverified. No throughput or latency improvement is
claimed. The removed publication GPU tests are retired with their removed
feature contract, and the ordinary LoRA training tests remain available for
hardware validation.

References

radixark/miles#3127
https://github.com/redai-studio/community/blob/main/contributor-program/2026-cohort-2/official-task.md#task-7
redai-studio#418
redai-studio#475
redai-studio#476

BREAKING CHANGE: Remove Relax's managed multi-version LoRA publication APIs
and whole-Session version-pinning behavior. Ordinary LoRA merge and
fixed-name adapter serving remain supported, with fixed-name selection
also connected to Agentic generation.
nianliunian pushed a commit to nianliunian/Relax that referenced this pull request Nov 30, 2026
Resolve two conflicts and reconcile the version-source contract with
main's new managed LoRA publication (redai-studio#705):

- state.py: keep both main's MoE route-span imports and this branch's
  WeightVersionSpan import; build_sample keeps the response_start offset.
- device_direct.py: keep main's managed-publication fast path and this
  branch's actor_fwd_only rule (an actor_fwd-only sync advances
  weight_sync_attempts but not the published ordinal). Managed mode labels
  generation from `session.lora_binding.version_id`, so the counter doc
  now says the ordinal covers the traditional weight-sync paths.

Follow-through so a consumption stamp joins the same sequence generation
reports: add DeviceDirectBackend.published_weight_version (managed:
publisher.published_version, so a capacity_skipped publication does not
advance it; traditional: weight_version) and have the actor read it.
Extend the helper test to cover the managed sequence.
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