Skip to content

【No.7 1/2】feat(lora): add immutable adapter version state machine - #475

Merged
SigureMo merged 6 commits into
redai-studio:mainfrom
overloadedHenry:feat/immutable-lora-publication
Nov 13, 2026
Merged

SigureMo merged 6 commits into
redai-studio:mainfrom
overloadedHenry:feat/immutable-lora-publication

Conversation

@overloadedHenry

@overloadedHenry overloadedHenry commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

feat(lora): add immutable adapter version state machine

关联 issue #418,作为 PR2 #476 的前序PR。

What

新增 relax/engine/lora_versions,提供不可变 LoRA(低秩适配)快照和版本状态机,用于协调版本发布、会话绑定和旧版本回收。会话绑定版本后,后续发布不会改变该绑定;旧版本只有在会话引用释放、引擎请求排空并确认物理副本消失后,才能完成回收。

本 PR 提供状态核心,引擎通信和训练接入由后续 PR 提供。状态机根据调用方提交的验证回执和清理观测返回操作,由调用方执行网络调用和引擎卸载。

Why

原地更新同名 adapter,会让持续运行的会话在执行过程中使用不同权重。版本发布需要与会话绑定分开:新版本可以成为新会话的默认版本,已有会话仍须使用绑定时的权重。

例如,已有会话绑定 v0 后,即使开始发布 v1,也继续使用 v0。只有全部目标引擎验证 v1 并完成 commit 后,默认版本才切换到 v1,供新会话绑定;已有会话结束后再释放 v0 的引用。

异步发布中的重复调用、迟到回执和引擎重启,还可能让过期事件影响当前状态。因此,状态机统一管理版本身份、发布尝试和引擎实例,并依据会话引用与引擎清理结果决定何时回收。

How

  • 冻结权重并确定版本身份。 快照将 tensor 复制到独立的 CPU 存储,隔离后续训练写入。规范化的 manifest 覆盖底座指纹、adapter 配置和 tensor 内容,SHA-256 摘要与版本号共同构成 adapter 名称。
  • 以 commit 作为默认版本的唯一切换点。 发布按 reserve → verify → commit 推进。同版本、同内容的发布可以幂等重试,内容冲突则被拒绝。
  • 隔离过期回执。 回执携带 attempt_id、引擎实例身份和 lora_id,旧发布尝试或旧引擎实例的回执不能更新当前状态。
  • 保持会话绑定稳定。 同一会话重复 bind 时仍返回原版本。release、分片关闭和会话水位用于清理引用,水位不能越过仍存活的会话。
  • 根据清理证据回收资源。 会话引用归零后,先关闭引擎接收入口,再等待请求排空,之后才允许卸载。只有全部目标确认物理副本消失且发布尝试已被隔离,才释放容量。超时不等于卸载成功,状态机也会拒绝表示清理进度倒退的观测。

Testing

定向测试覆盖快照隔离、摘要稳定性、重复发布、容量约束,以及取消竞态、迟到回执、引擎实例替换和分片关闭。随机事件回放用于检查默认版本、容量和引用计数的不变量。

Add detached adapter snapshots with canonical content digests and
position-weighted transport checksums. Introduce a synchronous version
manager with atomic publication, idempotent retries, session references,
capacity limits, and fenced cleanup decisions.

Keep engine I/O and runtime integration separate from the state core.
Cover failure ordering, engine and shard replacement, and late replies
with CPU scenarios and reproducible seeded event replay.

Validation: 34 CPU tests pass, including 100,000 seeds and 6.4 million
replayed event steps. Tests also pass after the lora_versions rename.
All pre-commit checks pass. Real engine and GPU integration follow in
subsequent changes.
Reject regressive cleanup snapshots as a whole, preserving fencing and
admission state without combining fields from different observations.
Allow request counts to grow until both loading and admission are closed.

Move the backend-independent version core and tests to engine/lora_versions.
Extend seeded replay to two concurrently active shards and verify that
closing one shard preserves the other shard's version references.

Validation: 41 CPU tests pass, including 100,000 seeds and 6.4 million
replayed event steps. Focused reproductions confirm that the previous
implementation accepts all three cleanup regressions and this change
rejects them. All pre-commit checks pass.
Merge main at 11a1de8 into the immutable LoRA publication branch.
The five publication core and test files remain byte-for-byte unchanged.

Validation: 41 CPU tests passed; all pre-commit hooks passed.
@rai-studio-bot

rai-studio-bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for contributing to Relax, @overloadedHenry! 感谢你为 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, RexFlux, yuanlehome, SigureMo, NINGBENZHE, Lemon-412
CI ✅ 已通过

@SigureMo SigureMo changed the title feat(lora): add immutable adapter version state machine (PR1) 【No.7 1/5】feat(lora): add immutable adapter version state machine (PR1) Oct 23, 2026
@SigureMo SigureMo changed the title 【No.7 1/5】feat(lora): add immutable adapter version state machine (PR1) 【No.7 1/5】feat(lora): add immutable adapter version state machine Oct 23, 2026
@overloadedHenry
overloadedHenry marked this pull request as ready for review October 25, 2026 19:36
@overloadedHenry
overloadedHenry requested a review from a team October 25, 2026 19:36
@rai-studio-bot

rai-studio-bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Nyanpasu 审查看板

审查状态: ✅ 已通过

审查版本: b60bc67

目标分支: main

测试归类建议已确认修复,未发现剩余需修改问题。两份测试原样迁入 CPU 套件,生产核心未变;当前 CI 尚在运行。已在原线程回复确认,但当前账号无权将线程标记为已解决。

审查阶段进度范围与结果
常规审查 ✅ 已完成 6 个路径均已接收。两份测试逐字节一致,新增包标记符合相邻结构,无新增父级 fixture 或生产改动;新路径进入 CPU 套件并被单卡 GPU 套件排除。F1 已在原讨论确认修复。
深度审查 ➖ 无需执行 纯目录迁移,不新增本地测试或重复套件;复用已审核心与回归内容。作者报告隐藏 GPU 后 49 项通过,当前 CI 结果尚未完成,未将该报告作为独立运行证据。

审查发现

待处理
编号 严重性 问题状态规则来源
暂无待处理的记录。
已解决或已取代
编号 严重性 问题状态规则来源
F1 Low severity 将两份纯 CPU 回归移入 tests/cpu/engine/lora_versions ✅ 已解决 AGENTS.md:按实际设备需求归类测试

改进建议(非阻塞)

相关 PR

💡 实现与合入建议

建议保持 #475 → #476 的合入顺序;#476 同步当前状态核心及 CPU 测试路径,同时保留自己的引擎实例 accessor 和接入增量。

https://github.com/redai-studio/Relax/pull/476 · eb9b5f183d8f0379bedb9fd2f948de0f90cf8fc5 · 目标分支 main

实现取舍: 采用 #475 的持久撤销、完成记录压缩和活跃索引修复。#476 当前状态核心仍是旧实现加 engine_instance();其产物、引擎、会话与训练接入保护不同边界,应保留。

当前 PR 调整: #475 无需再为协调改动生产代码。#476 同步最新 manager.py 时保留 engine_instance();核心回归采用 tests/cpu/engine/lora_versions/{__init__.py,test_identity.py,test_manager.py},保留新增重放及压缩回归,不恢复旧路径或复制两套测试。

合入顺序: 优先先合 #475,再让 #476 更新到实际 main,使共享核心和核心测试退出其净增量。维护者也可先让 #476 吸收最新修复与测试并完成后端适配验收,再整体合入并处理 #475 的已覆盖范围;当前 #476 尚不完整替代新版核心。

依据与验证范围: 双方 open、head 和 main/merge-base 已复核。固定源码比较确认 #476 缺少本轮核心修复;其 runtime 仍使用 engine_instance(),终态副本详情未发现消费冲突:https://github.com/redai-studio/Relax/blob/eb9b5f183d8f0379bedb9fd2f948de0f90cf8fc5/relax/engine/lora_versions/runtime.py#L182 。#476 已新增 v0.5.21 补丁,但本次未评估其适配或实际 GPU 行为;当前镜像验证请求仍是下游未验证边界:https://github.com/redai-studio/Relax/pull/476#issuecomment-6822998228 。仅静态协调,不代表 #476 运行就绪。

提交范围 · 接收 6 · 建议移出 0 · 待确认 0

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

文件结论仓库维护必要性依据替代去向或方案
relax/engine/lora_versions/__init__.py
relax/engine/lora_versions/identity.py
relax/engine/lora_versions/manager.py
接收 不可变 LoRA 状态核心属于 engine;本轮与已审生产源码一致。 PR #475/issue #418 的快照、发布、会话绑定及回收契约;既有审查。 当前 engine/lora_versions 位置合适,后端接入仍由后续 PR 实现。
tests/cpu/engine/lora_versions/__init__.py
tests/cpu/engine/lora_versions/test_identity.py
tests/cpu/engine/lora_versions/test_manager.py
接收 纯 CPU 回归已迁入 CPU 套件目录,新增包标记遵循同层测试结构;两份测试内容未变。 F1 迁移建议;AGENTS.md:150-152 和 unittest.yml:38-50 的目录分组契约。 当前 tests/cpu/engine/lora_versions 位置符合设备需求,保留测试内容和回归能力。
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.

审查通过

已完成 f565d0d 的快照身份、版本发布、会话绑定与安全回收状态审查,未发现需要修改的问题,建议合入。CI 日志确认新增 41 个用例通过;本结论限于状态核心,真实引擎通信和训练接入由后续 PR 验证。

审查看板与关联 PR 协调建议

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

@overloadedHenry overloadedHenry changed the title 【No.7 1/5】feat(lora): add immutable adapter version state machine 【No.7 1/2】feat(lora): add immutable adapter version state machine Oct 26, 2026
@overloadedHenry

Copy link
Copy Markdown
Contributor Author

@SigureMo 任务已完成,请求 review

@GUOGUOPOT

Copy link
Copy Markdown
Contributor

感谢提交这个 PR,整体设计和测试覆盖都比较完整,审查中发现以下两点需要进一步关注,供讨论和完善。

  1. 冲突回执后的服务资格撤销可以被重放绕过
    [manager.py:225–235]:发现 lora_id 冲突后,代码删除 verified 并调用 cancel(),但 cancel() 对 PUBLISHED/RETIRED 状态不生效。随后重放旧回执或冲突回执时,因 previous 已为空,两者都会被接受,引擎重新进入 serving_engines。
    建议区分“尚未验证”和“已检测到冲突”,保留冲突状态,直到实例替换或明确的新验证代际完成恢复;补充上述两种重放回归。这是状态核心异常处理路径的缺陷,目前未证明真实引擎会产生该冲突。

  2. 历史版本元数据持续保留,绑定开销随累计版本数增长
    [manager.py:304–309]:回收完成后只清空 verified,完整 fingerprints、targets 和 cleanup 仍保留;每次新会话绑定调用的 serving_engines 又会扫描全部历史版本。
    建议压缩已回收版本的历史元数据,仅保留幂等与冲突检测所需字段,并让容量及服务资格计算只遍历仍相关的版本。

Reject receipt replays after invalid or conflicting verification until the
engine instance is replaced. Keep completed publications as compact records
and restrict capacity and serving checks to active versions, preserving
idempotency and aborted-attempt fingerprint validation.

Terminal publication snapshots now omit replica details after cleanup.
Add regressions for replay rejection, replacement recovery, history compaction,
and active operations that do not scan historical versions.

Validation: 49 LoRA version tests and all pre-commit hooks passed, including
private-key detection and gitleaks.
@overloadedHenry

Copy link
Copy Markdown
Contributor Author

感谢提交这个 PR,整体设计和测试覆盖都比较完整,审查中发现以下两点需要进一步关注,供讨论和完善。

已完善细节问题

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

审查通过

已复查 d368be21 对两项人工反馈的修复:回执重放无法清除撤销状态,历史压缩保留了冲突检测和清理后重试语义。未发现新增需修改问题,建议合入本 PR;当前 CI 尚在运行,本轮未重复执行本地测试,真实引擎接入仍需在后续 PR 验证。

审查看板与关联 PR 同步建议

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

Merge origin/main at 931726a while preserving immutable publication state,
receipt revocation, and compact history handling. The merge required no
manual conflict resolution.

Validation: 49 LoRA version tests passed with GPUs hidden. All pre-commit
hooks passed, including private-key detection and gitleaks. Multi-node GPU
integration tests were not run because this merge was validated in the local
CPU environment.

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

有补充意见(非阻塞)

本次合并 main 后,LoRA 核心及回归内容与已审版本一致,未发现新增正确性问题;有一项适配当前 CPU/GPU 测试分组的归类建议。当前 CI 尚在运行;关联 PR 的同步核对将在看板中补齐。

审查看板

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

@@ -0,0 +1,681 @@
# Copyright (c) 2026 Relax Authors. All Rights Reserved.

"""CPU publication scenarios and seeded event replay, with no Ray/GPU

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Low severity P3 · 将两份纯 CPU 回归移入 CPU 套件(非阻塞)

合入当前 main 后,单测矩阵只在 CPU 作业收集 tests/cpu,其余 tests/ 进入单卡 GPU 作业。这份状态机测试及 test_identity.py 均无需 GPU;留在当前位置会使 CPU 作业遗漏它们,并占用 GPU 测试通道。

请将两个文件原样迁至 tests/cpu/engine/lora_versions/,保留现有回归,无需改 workflow 或增加 mock/skip。这也符合当前 AGENTS.md 的设备分类要求。

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已确认 b60bc67 将两份测试原样迁入 tests/cpu/engine/lora_versions/,并补上包标记;git diff --find-renames 显示两文件内容均未改变。新路径已纳入当前 CPU 单测矩阵,此归类问题已解决。当前 CI 仍在运行,本轮未重复执行本地测试。

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

Move identity and manager regressions into tests/cpu/engine/lora_versions
and add a package marker. Preserve both test files without content changes.

Validation: all 49 tests passed with GPUs hidden.

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

审查通过

已确认 b60bc67 修复了测试归类建议,测试内容和生产核心均未改变,未发现剩余需修改问题,建议合入。当前 CI 尚在运行,本轮未重复执行本地测试。原线程已回复修复确认,线程的“已解决”标记受当前账号权限限制。

审查看板

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 498167c into redai-studio:main Nov 13, 2026
17 checks passed
SigureMo pushed a commit that referenced this pull request Nov 16, 2026
# Publish immutable adapters for resident sessions

关联 issue #418,作为 PR1 #475 的后续 PR。

## What

将不可变 LoRA(低秩适配)版本接入
SGLang、常驻会话和异步训练,连接训练快照导出、引擎加载、会话绑定和旧版本回收。发布期间,旧会话继续使用绑定的版本;只有全部目标引擎验证新版本后,才切换新会话的默认版本。旧版本在会话结束、引擎请求排空后回收。

本 PR 依赖 `feat/immutable-lora-publication` 提供的状态核心,合入顺序为 PR1 → PR2。以下描述
PR2 相对 PR1 的增量。

## Why

原地更新固定名字的
adapter,会让多轮会话在不同轮次使用不同权重。全局暂停生成和清空缓存又会影响仍在运行的会话,因此需要让旧会话继续使用原版本,同时为新会话发布新版本。

这要求训练导出、引擎加载和会话生命周期共同遵守版本状态机的约束。发布失败时,系统仍需保留默认版本和待清理副本的状态;HTTP
超时既不能证明加载失败,也不能证明副本已经消失,清理必须核对引擎的实际状态。

## How

### 不可变产物与发布

- **产物与传输。** 自动训练发布使用共享目录中的不可变文件产物(FILE),包含 adapter tensor、配置和
manifest。同机共享内存传输(SHM)保留为另一条发布接口。
- **验证与提交。** 每个目标引擎校验实际接收的内容,再加载独立命名的 adapter。发布器核对回执,并使用指定版本执行 1 token
greedy 探针;全部目标验证通过后,状态机才提交默认版本。该探针验证版本可用性,数值一致性仍需单独验收。
- **状态核对与失败清理。** Ray runtime
持有发布状态,并定期核对引擎实际状态。失败发布先隔离对应尝试,再关闭接收入口、排空请求并卸载;即使缺少加载回执,runtime
仍会查询并清理实际副本。

### 引擎与会话

SGLang 补丁提供 inventory、load、fence 和 unload 控制接口。受管 adapter
禁止隐式重载,也不能经旧接口绕过控制;请求引用保留至调度器报告终态,避免因请求取消而提前卸载。

会话在首次允许派发请求时绑定版本,工具等待、abort/resume 和后续轮次均保留该绑定。生成请求携带明确的
`lora_path`,直接路由到已验证的引擎。会话终结后释放版本引用,样本记录实际绑定的版本号。

补丁覆盖 SGLang 0.5.17 和 0.5.20。由于 0.5.20 的并行采样会扩展自动生成的请求 ID,本 PR 仅为逻辑
prompt 建立父状态和引用。前缀请求与采样子请求共享引用,直到全部请求终结。

### 训练接入与启用条件

训练先完成底座同步,再发布初始 adapter;后续更新导出新快照,通过独立发布并发组调用
runtime。训练进程共享发布结果,避免某个进程提前退出集合通信。

容量不足时保留当前版本并跳过本次发布。发布失败或结果未确认时,训练保留 pending 版本及原产物,并抛出错误;本 PR
不提供训练作业的自动故障恢复。

该模式通过 `RolloutManager.configure_lora_training(...)` 显式启用,配置须早于训练 actor 的
`set_rollout_manager`。该 API 接收共享产物目录、底座指纹和有效的探针
token;共享目录须对全部目标引擎可见,并按训练作业隔离。现有训练命令不会自动启用此模式,当前没有专用 CLI 开关。

自动发布须满足以下条件:

- Megatron、fully-async、Agentic rollout 和 LoRA adapter 模式。
- 冻结底座,训练与推理使用独立 GPU,固定单模型引擎池。
- 关闭 colocate/hybrid、rollout offload 和自动恢复;配置检查会拒绝启用
`use_fault_tolerance` 或 `use_health_check`。
- 引擎的数据并行、流水线并行度均为 1,使用单 tokenizer worker;暂不支持 prefill/decode 分离、推测解码或
HiCache 外部存储层。

保留 K 个版本时,`max_loras_per_batch` 至少为 K+1,`max_loaded_loras` 不小于
`max_loras_per_batch`。例如,K=2 时可将两者均配置为 3。

## Testing

CPU 测试使用生产共享内存序列化器和实际补丁定义,HTTP 与 GPU worker
执行边界使用测试替身。并行采样回归使用完整的请求归一化和请求处理方法,覆盖默认、字符串、列表形式的请求 ID(RID),以及混合 LoRA
请求。

### 已有 GPU 验收:SGLang 0.5.17

以下结果使用 SGLang 0.5.17。验收环境为单机 Qwen3-0.6B / GSM8K,1 张训练卡和 2
个推理引擎,张量并行、流水线并行度均为 1。训练验收使用独立脚本,脚本未随本 PR 提交。

| 场景 | 已验证结果 |
| --- | --- |
| 真实训练发布 | 完成 2 次 optimizer 更新,双引擎提交 v0/v1/v2 |
| 跨更新训练会话 | 8 条旧会话按实际 abort 前缀恢复 v0,与 24 条新 v1 样本共同进入下一训练批次和实际 loss |
| 工具与会话恢复 | 独立探针覆盖外部工具、非空 abort 和跨发布恢复;探针不进入 optimizer batch |
| 持续负载 | 288 个请求全部完成;发布期间未观察到全局 pause/flush/abort_all 调用 |
| 容量不足 | 跳过发布后继续训练;旧版本释放并回收后可发布新快照 |
| 发布失败与超时 | 覆盖接收端拒绝、提交后控制回执超时,以及加载成功后的 HTTP ACK 超时;失败作业按预期抛错退出 |
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants