Skip to content

feat(LoRA): Support Qwen38 Flash-Next LoRA Training - #655

Merged
NINGBENZHE merged 8 commits into
redai-studio:mainfrom
GUOGUOPOT:feat/youtai/qwen38_lora
Nov 17, 2026
Merged

NINGBENZHE merged 8 commits into
redai-studio:mainfrom
GUOGUOPOT:feat/youtai/qwen38_lora

Conversation

@GUOGUOPOT

Copy link
Copy Markdown
Contributor

what

Add Qwen3.8 Flash-Next LoRA training recipes and support for Hyper-Connection (HC) and Per-Layer Embedding (PLE) adapters, including nonzero dropout.
Includes SFT recipes for Blackwell and H800, a colocated DAPO merge-mode recipe, and fixes for adapter gradient synchronization, checkpoint recovery, and rollout weight updates.

Why

HC/PLE adapters require explicit target resolution and synchronization across parallel replicas. Without these safeguards, adapters can be silently excluded, replicated gradients can be counted incorrectly, and dropou
RNG state can diverge after recomputation or checkpoint restore.
LoRA training also needs to avoid unnecessary allocations in frozen blocks and prevent generation from resuming after a failed adapter update.

HOW

  • Resolve canonical HC/PLE target names while preserving portable export names; validate adapter coverage and frozen base parameters.
  • Synchronize replicated TP adapters, use Bridge's EP gradient finalization, and exclude duplicate expert-adapter gradients from norm calculation.
  • Add a dedicated PLE dropout RNG stream and require per-P RNG checkpoint state when needed.
  • Release temporary decoders before reconstruction and avoid forcing input gradients for fully frozen recompute blocks.
  • Cancel outstanding startup synchronization tasks on failure and keep rollout generation paused when adapter updates fail.
  • Fix SLang LoRA request cleanup during cancellation and request-ID reuse.
  • Add regression coverage and place multi-GPU tests under 'tests/gpux4'.
    HC/PLE rollout requires merge mode. PLE projection adapters require streamed PLE to be disabled; unsupported configurations fail explicitly.

Testing

  • Full pre-commit checks passed.
  • Selected CPU regression suites: 177 passed; 10 failed because the local environment lacks 'libcuda.so.1'.
  • Additional LoRA gradient synchronization tests: 12 passed.
  • Four multi-GPU cases were collected and skipped because the required CUDA GPUs were unavailable.
  • End-to-end distributed training and GPU numerical parity remain unverified in this environment.
  • 'pre-commit run --all-files' passes
  • İ i Tests pass ('pytest tests/')
  • New tests added (if applicable)
  • Documentation updated (if applicable) - development plan added

Type of Change

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

@rai-studio-bot

rai-studio-bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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

@rai-studio-bot

rai-studio-bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Nyanpasu 审查看板

审查状态: ✅ 已通过

审查版本: ff5fb33

目标分支: main

已完成当前保存与离线导出增量的源码、复用边界及测试有效性核对,未发现新增可行动问题,既有问题均已解决。已核实 673d003 的四个 HC/PLE GPU 用例实际通过,相关实现本次未变;新导出端到端与完整训练恢复仍有验证缺口。

审查阶段进度范围与结果
常规审查 ✅ 已完成 35 个接收文件均有覆盖:复用未变的 27 路径证据,核对新增 8 文件及双语说明。轻量 native 保存仅临时过滤生成的状态字典,随后 HF 导出读取完整模型;其他恢复保护仍有效。
深度审查 ✅ 已完成 已按固定 Bridge 核对 BF16/FP8 共用 writer、懒 dtype 转换、CPU 加载、vision/MoE target、分片索引及失败回滚,未确认缺陷或额外删除建议。新增 CPU 用例检查真实 writer/工具 helper,但 Bridge 与 native I/O 被隔离,本轮未运行本地测试。[673d003 四卡日志](https://github.com/redai-studio/Relax/actions/runs/44002400707/job/133769522035#step:8:1)确认四个 HC/PLE 用例通过;新导出真实 checkpoint、CP fused=1+LoRA/dropout、完整训练恢复、文件系统故障与多节点尚未验证。

审查发现

待处理
编号 严重性 问题状态规则来源
暂无待处理的记录。
已解决或已取代
编号 严重性 问题状态规则来源
F1 High severity 补齐 reduced-HF 测试依赖的脚本 ✅ 已解决 —
F2 Medium severity 同步更新 PEFT 测试替身的属性契约 ✅ 已解决 —
F3 Low severity 将配方拓扑注释中的 PP4 改为 PP1 ✅ 已解决 —
F4 High severity 整合 main 的 SGLang 后续补丁后重新生成 diff ✅ 已解决 —

改进建议(非阻塞)

拆分

💡 1 个拆分方案

可按七个行为单元拆分,仅 C 依赖 A/B,在线组合保存与离线转换可独立落地。已覆盖全部 35 路径、3086 变更行,其中测试 2125 行、配方 312 行、依赖补丁实际新增 16 行,无生成文件、锁文件或重命名膨胀。以下为非阻塞建议及拆分后的验证要求,不是本轮测试结果。

箭头表示前置部分 → 后续部分;目标分支为 main。

flowchart LR
    target["目标分支"]
A["PR A"]
target --> A
B["PR B"]
target --> B
C["PR C"]
A --> C
B --> C
D["PR D"]
target --> D
E["PR E"]
target --> E
F["PR F"]
target --> F
G["PR G"]
target --> G
Loading
部分PR 主题内容与范围验证
A LoRA 梯度与优化器语义 lora_grad_sync.py 与 model.py 的 EP finalizer、内存释放委托及 optimizer norm hunks;携带梯度、optimizer steps、resident SFT 和 checkpoint compatibility 回归。checkpoint helper 沿用基线。 拆分后验证 TP SUM/AVG、EP fused main_grad 单次同步、范数/裁剪/更新和优化器步数;CPU/Gloo 不替代真实 EP/TP 集成。
B 合并与 adapter 导出兼容 hf_weight_iterator_bridge.py、device_direct.py._merge_full_base 的 tp_group 修正及 megatron_peft_utils.py 的 MTP fc/eh_proj 映射,连同 lora_weight_sync、megatron_peft_utils 回归。 拆分后验证普通 TP、expert-TP、PP 源 rank 合并、原权重不变及 portable adapter 重载。
C HC/PLE LoRA 与 Blackwell 配方 common/qwen3_8 LoRA、model_provider.py 和 model.py 的统一 finalize 入口,携带 provider、HybridEP、CPU/GPU 模型回归及完整八卡配方。目标解析、冻结/初始化、merge-only、非流式 PLE 和 dropout/RNG 恢复约束保持同组。 拆分后重验受影响 CPU 与 2–4 GPU FP32/BF16 用例,并验证真实 Blackwell 训练保存恢复。已核实的 673d003 四个 GPU 用例仅覆盖其规定边界,不证明完整训练恢复。
D 冻结块重计算修复 活动 Megatron patch 新增的 16 行 recompute hunk 与 test_peft_recompute_frozen_blocks.py,保留上游梯度和后注入 adapter 通路。 在固定 Bridge/Core 上验证补丁及冻结、动态解冻、上游/adapter 梯度,另以实卡验证重计算与 CP 集成。
E 权重同步失败与任务清理 controller.py 的 receiver/rollout_only 路由及同步任务取消,device_direct.py 的错误传播、保持暂停与成功状态 hunks,携带两组 core 回归;合并接口归 B。 验证零/单/双接收者及收发失败收尾;注入 adapter push 失败,确认所有 rank 一致失败、不恢复生成及最终 teardown。Ray/NCCL 需集群验证。
F 轻量 checkpoint 同时保存 HF arguments.py 的组合保存放行与帮助、两份 LoRA 指南、test_arguments_lora_checkpoint.py 及 test_lora_resume_checkpoint.py 新增回归;沿用基线 native-save→save_hf_model 链路。 验证 BF16 原生轻量保存、完整合并 HF/portable adapter 导出和 native 恢复,确认其余恢复保护有效;外部 I/O 替身不替代真实保存恢复。
G 离线 HF 转换 转换脚本的 CPU 初始化、精度重建、懒 cast、vision/MoE target 与分片参数,fp8_checkpoint.py 的共享 StreamingHFWriter/FP8 子类,以及转换工具回归。writer 与消费者一起落地。 验证工具及既有 FP8 回归、真实 vision/MoE/PLE checkpoint 转换、分片索引、失败时旧输出保护和 FP8 兼容。输出缓冲有界,完整模型仍驻 CPU。
如何按依赖提交(stack)

作者 GUOGUOPOT 为 MEMBER,来自 GUOGUOPOT/Relax fork;只读 collaborator permission API 已确认其对 redai-studio/Relax 有 write 权限。

先按表重组混合提交,每部分携带对应测试和文档;逐层验证,并核对顶层最终树与原 PR 一致。独立部分各自向目标分支开普通 PR;只将有依赖的线性链组成 stack,分叉或多前置依赖按图分别安排提交。

有上游写权限: 将各层分支放在上游仓库,在已按依赖拆好的一条分支链上注册并提交(替换目标分支与分支名):

gh stack init --base <target> <layer-1> <layer-2>
gh stack view
gh stack submit

下层更新后用 gh stack rebase 调整上层,或用 gh stack sync 同步整条链。上述命令管理已拆好的分支,不会自动拆开混合提交。参见 gh-stack 使用说明。

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

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

文件结论仓库维护必要性依据替代去向或方案
docker/patch/megatron/20260915-4a4de8657.patch
relax/backends/megatron/model.py
relax/backends/megatron/model_provider.py
relax/backends/megatron/weight_update/hf_weight_iterator_bridge.py
relax/core/controller.py
relax/distributed/checkpoint_service/backends/device_direct.py
relax/models/qwen3_8/lora.py
relax/utils/megatron_peft_utils.py
relax/utils/training/lora_grad_sync.py
relax/models/common/lora.py
relax/utils/arguments.py
relax/utils/quant_cast/fp8_checkpoint.py
scripts/tools/convert_torch_dist_to_hf_bridge.py
接收 LoRA 训练、同步、恢复与共享导出工具的运行契约归现有模块;新增 dtype/流式写出和轻量 checkpoint+HF 保存属于相关持久功能。 PR #655 HC/PLE 与 checkpoint/export 要求及当前 improve checkpoint export and HF saving 提交。 Current modules and dependency patches own these runtime contracts.
examples/models/qwen3.8-flash-next/scripts/run-qwen38-qsa-lora-sft-8xgpu-blackwell.sh
接收 Reusable Blackwell Qwen3.8 LoRA SFT training recipe. PR #655 What: Blackwell SFT recipe. Model-specific example script is the established location.
tests/cpu/backends/megatron/test_checkpoint_optimizer_steps.py
tests/cpu/backends/megatron/test_expert_adapter_grad_sync.py
tests/cpu/backends/megatron/test_peft_recompute_frozen_blocks.py
tests/cpu/backends/megatron/test_qwen38_hybridep.py
tests/cpu/backends/megatron/test_resident_sft_param_sync.py
tests/cpu/backends/megatron/test_training_checkpoint_compatibility.py
tests/cpu/backends/megatron/weight_update/test_lora_weight_sync.py
tests/cpu/core/test_controller_s3_model_cleanup.py
tests/cpu/core/test_initial_weight_sync.py
tests/cpu/models/test_qwen38_lora.py
tests/cpu/models/test_qwen38_lora_targets.py
tests/cpu/utils/test_lora_grad_sync.py
tests/cpu/utils/test_megatron_peft_utils.py
tests/gpux4/backends/megatron/test_qwen38_lora_dropout_gpu.py
tests/gpux4/backends/megatron/test_qwen38_lora_gpu.py
tests/cpu/backends/megatron/test_model_provider_vpp.py
tests/cpu/backends/megatron/test_lora_resume_checkpoint.py
tests/cpu/tools/test_convert_torch_dist_to_hf_bridge.py
tests/cpu/utils/test_arguments_lora_checkpoint.py
接收 CPU 与多 GPU 回归覆盖 LoRA、同步、依赖补丁与恢复契约;本次追加的 provider 测试替身修复属于原有 CPU 测试。 PR #655 LoRA 要求、现有 provider 参数/进程组转发回归及 F2 测试接口兼容意见。 Tests are placed according to runtime requirements; check their actual coverage in correctness review.
docs/en/guide/low-rank-adaptation-training.md
docs/zh/guide/low-rank-adaptation-training.md
接收 双语用户文档说明轻量训练 checkpoint 与 HF 导出、恢复的边界,属于维护文档。 当前 --save-lora-only + --save-hf 新行为与已有 LoRA 用户指南。 沿用现有中英文 LoRA 指南,而不是另增一次性实验报告。
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.

需要修改(初步结论)

固定提交 ee139989 已确认一个会使 CPU 测试收集失败的问题,需修复后合入。模型构造与新配方的静态检查已完成;HC/PLE 并行数值及 rollout 失败路径仍在核对,端到端 GPU 训练尚未验证。

审查面板

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

SCRIPTS = ROOT / "examples/models/qwen3.8-flash-next/scripts"
SPEC = importlib.util.spec_from_file_location("qwen38_reduced_hf", SCRIPTS / "prepare_qwen38_reduced_hf.py")
reduced = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(reduced)

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.

High severity P1 · 补齐 reduced-HF 测试依赖的脚本

固定提交中没有 examples/models/qwen3.8-flash-next/scripts/prepare_qwen38_reduced_hf.py,这里却在模块导入时无条件执行它。单独运行 python -m pytest tests/cpu/tools/test_qwen38_reduced_hf.py::test_reduced_view_preserves_source_ple_vision_and_prefix[4] -q 即在第 22 行报 FileNotFoundError;CPU CI 会收集整个 tests/cpu,因此会在执行测试前失败。后面的 launcher 测试引用的 run-qwen38-flash-next-lora-sft-smoke-8xgpu-blackwell.sh 也未提交。请一并提交实际工具和配方,或将这组测试随对应实现另行提交。

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.

已确认 ff61a6a9 删除了依赖未提交工具的 test_qwen38_reduced_hf.py;对比已审提交,仅此一处文件删除,当前 CPU 测试树中也不再引用这两个缺失脚本。原收集失败的触发点已移除,F1 已解决。本轮未重跑测试,后续回归由 CI 验证。

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

Add an 8-GPU Blackwell SFT LoRA recipe for the unified Qwen3.8 runtime.
Release temporary decoders before Bridge rebuilds them and avoid forcing
input gradients for fully frozen recompute blocks.

Harden startup weight synchronization, adapter export, and rollout LoRA
request cleanup. Add CPU regressions for these paths.
Resolve HC/PLE targets while preserving portable checkpoint names, validate
trainable adapters and frozen bases, and synchronize replicated TP adapters.
Use Bridge EP gradient finalization and exclude duplicate expert adapter
optimizer shards from gradient norms.

Add CPU and NCCL numerical regressions for gradients, updates, restore and
merge behavior. Nonzero HC/PLE LoRA dropout remains explicitly unsupported.

Validation: staged-file pre-commit passed. Full-repository checks found an
existing extra EOF newline in the unrelated 8-GPU training script.
Use a dedicated PLE RNG stream across context-parallel replicas and require
per-data-parallel RNG checkpoint state for nonzero HC/PLE LoRA dropout.
Guard unsupported inputs and checkpoints that lack the PLE RNG stream.

Extend CPU coverage and add GPU parity, activation recomputation, and
native RNG checkpoint resume tests. Update the 8-GPU LoRA training recipe.

Validation: CPU tests could not collect because libcuda.so.1 is unavailable;
the four-GPU integration test was not run in this environment.
@GUOGUOPOT
GUOGUOPOT force-pushed the feat/youtai/qwen38_lora branch from ee13998 to ff61a6a Compare November 12, 2026 08:24

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

审查通过

已复审 ff61a6a9:相对已审版本仅移除了依赖缺失工具的测试,F1 已验证解决,其余代码未变;未发现剩余可操作问题。真实 GPU 训练、完整 checkpoint 恢复及 Ray/NCCL 集成仍未验证。

审查面板

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.

审查意见

已复审 1354b4ac 的旧补丁撤回和测试范围调整;保留一项有 CI 与源码证据的测试替身兼容意见,未确认新增生产运行缺陷。真实 GPU 数值、完整 checkpoint 恢复和 Ray/NCCL 集成仍未验证。

审查面板

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


try:
peft = build_lora_peft(args)
peft.target_modules = qwen38_lora_targets(model, list(peft.target_modules), args)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Medium severity P2 · 同步更新 PEFT 测试替身的属性契约

这里新增了对 peft.target_modules 的无条件读取,但 test_model_provider_vpp.py:646,687 的两处 build_lora_peft 替身仍返回普通 lambda。上一版同一代码的 CPU CI 已有 7 个用例因此报 AttributeError;本行与这两处替身在 1354b4ac 中均未变化。请将两处替身改为可调用且带 target_modules 的 PEFT 对象,以恢复 wrapper 参数与 process-group 转发的回归检查。此证据定位的是测试兼容问题,未证明真实 PEFT 运行路径故障。

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.

已确认 707d5c65 的两处替身均改为可调用且带 target_modules 的 _FakePEFT,原有 wrapper 参数与 process-group 转发断言保留;F2 的接口不匹配已修复。本次仅此测试文件变化,未重跑本地测试,当前 CI 尚未完成。

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

@GUOGUOPOT
GUOGUOPOT force-pushed the feat/youtai/qwen38_lora branch from 1354b4a to 707d5c6 Compare November 12, 2026 12:05

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

审查通过

已复审 707d5c65:测试替身的接口修复符合现有调用契约,其余已审代码未变,未发现剩余可操作问题。当前 CI 尚未完成;真实 GPU 数值、完整 checkpoint 恢复及 Ray/NCCL 集成仍未验证。

审查面板

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

@GUOGUOPOT
GUOGUOPOT force-pushed the feat/youtai/qwen38_lora branch from 88d5e97 to deb1e22 Compare November 15, 2026 14:31
Comment thread relax/backends/megatron/model.py Resolved

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

补充一项非阻塞的配方注释修正建议。

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

需要修改

已完成 7087f350 复审:确认 SGLang 补丁与当前 main 的后续修改叠加后会阻断 CUDA 13 测试镜像构建,需整合后再合入。通用 LoRA 分派与 TP selector 未确认新增运行缺陷;真实 GPU 数值和完整保存恢复仍未验证。

审查面板

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

Comment thread docker/patch/sglang/v0.5.21.patch Outdated
Comment on lines +3718 to +3722
- request_rids = {obj.rid} if obj.is_single else set(obj.rid)
+ request_rids = {
+ rid: self.rid_to_state[rid]
+ for rid in ([obj.rid] if obj.is_single else obj.rid)
+ }

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.

High severity P1 · 整合 main 的 SGLang 后续补丁后重新生成 diff

当前 main 已合入 #476,其中后续 tokenizer diff 仍依赖这里修改前的 request_rids 集合;嵌入 lease 测试的后续 diff 也依赖旧 fixture 上下文。7087f350 与 main 的补丁单独都能应用,但 CI 合并结果的镜像步骤在固定 SGLang e00930c5 上报 tokenizer_manager.py:888 和 test_tokenizer_lora_lease_cleanup.py:116 的 patch does not apply,测试尚未开始。请在包含 #476 的基线上整合两侧修改,从固定源重新生成对应文件的最终 diff,保留取消回收和不可变租约语义;仅修改 hunk 行号不能解决旧像不一致。

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.

已核实 6651bad5 的 SGLang patch 与当前 main 完全一致:此前本 PR 的取消屏蔽/RID 清理增量已撤回,原来的两层旧像冲突不再存在。当前 CPU CI在新合并树上完成镜像准备及测试,本构建阻断意见已消除;这不表示原取消改动已整合,也不代表 HC/PLE GPU 或完整恢复已验证。

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

@GUOGUOPOT
GUOGUOPOT force-pushed the feat/youtai/qwen38_lora branch from 7087f35 to 6651bad Compare November 16, 2026 12:38
Provide resolve_lora_targets and finalize_lora_models, dispatched according to model configuration
@GUOGUOPOT
GUOGUOPOT force-pushed the feat/youtai/qwen38_lora branch from 6651bad to b5b8761 Compare November 16, 2026 13:05

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

通过复审

b5b8761 已修正配方拓扑说明,原 SGLang 补丁构建阻断也已消除,未发现新增阻断问题。运行代码沿用已核实覆盖;HC/PLE GPU 数值、完整训练保存恢复及多节点集成仍未验证。

审查面板

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

NINGBENZHE
NINGBENZHE previously approved these changes Nov 17, 2026

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

复查 673d003,未发现阻塞问题。此前配方拓扑与 CP/QSA 注释已修正;通用 LoRA 入口保留了校验和初始化时机,SGLang 补丁与 main 一致。本地相关 CPU 回归 54 passed、2 skipped;最新 CI 通过,4 个 HC/PLE GPU 用例均实际通过。完整 Qwen3.8 训练保存恢复及真实故障注入未独立验证。

Handle folded vision and deepstack LoRA adapters without treating them as
per-expert tensors. Preserve checkpoint precision, keep PLE dtype casts
lazy, and stream BF16 output through size-bounded safetensors buffers.

Allow resumable LoRA-only checkpoints alongside full HF exports and
document loading the original base plus native LoRA training state.

Validation: 30 CPU converter/export regressions passed. Megatron/Bridge
integration remains unverified because libcuda.so.1 is unavailable.
@GUOGUOPOT
GUOGUOPOT force-pushed the feat/youtai/qwen38_lora branch from 673d003 to d24a012 Compare November 17, 2026 07:36
@GUOGUOPOT
GUOGUOPOT requested a review from SigureMo as a code owner November 17, 2026 07:36

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

lgtm

@NINGBENZHE
NINGBENZHE enabled auto-merge (squash) November 17, 2026 08:21
@NINGBENZHE
NINGBENZHE merged commit d0e00f3 into redai-studio:main Nov 17, 2026
15 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.
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.

4 participants