Repository navigation
build(sglang): upgrade CUDA 13 runtime to 0.5.21 - #459
yuanlehome wants to merge 2 commits into
Conversation
Port Relax's SGLang patches to the 0.5.21 APIs and select versioned patches in the CUDA 13 image. Update Blackwell dependencies and compatibility for Kimi, multimodal OPD, routing replay, weight reload, disaggregated serving, and reloadable process groups. Keep versioned SGLang patches together and point both latest aliases at 0.5.21. Freeze the CUDA 12 image and its matching patches at 0.5.17, and retain the legacy per-position patch. Update OPD documentation for 0.5.21. Add regression coverage for the migrated SGLang patches and runtime compatibility changes. Validation: pre-commit run --all-files --show-diff-on-failure passed. End-to-end accuracy and performance validation remains in progress.
|
Thanks for contributing to Relax, @yuanlehome! 感谢你为 Relax 做出贡献! 📚 Contribution guide / 贡献指南Describe the problem, your changes, and how you validated them. Keep each PR focused and run 请说明问题、改动和验证方式,保持 PR 聚焦,并在提交前运行 🛠️ CI commands / CI 指令
Put one command on the first line of a new PR comment. Rerun/cancel require PR authorship or repository write access. 在新 PR 评论的首行写一条指令。PR 作者或有仓库写权限的贡献者可以重跑、取消 CI。 🔎 Merge requirements / 合入条件GitHub:❌ 存在冲突
|
Nyanpasu 审查看板审查状态: 🚧 需要修改 审查版本: 5d27116 目标分支: main 已完成 5d27116 的增量审查及独立反证。新增 F6:默认 cuda_ipc 阻断单个引擎跨节点启动,冻结的 0.5.17 与升级后的 0.5.21 均受影响;新增 F5 为两层示例的转换命令错误。原 F1–F4 仍未解决,两个原 P1 线程已补充本轮证据。审查结论:https://github.com/redai-studio/Relax/pull/459#pullrequestreview-5614676335
审查发现待处理
已解决或已取代
提交范围 · 接收 41 · 建议移出 0 · 待确认 0接收 41 个文件 · 建议移出 0 个文件 · 待确认 0 个文件。移出与待确认部分暂停深审,不代表审查通过。
Powered by Nyanpasu with gpt-6-astra xhigh, please check the suggestions carefully.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
🔵 Needs a closer look
Unresolved compatibility and synchronization issues remain, and end-to-end multi-GPU accuracy and performance validation is still pending.
2 open issues
What changed in this PR
Upgrades Relax’s CUDA 13 runtime to SGLang 0.5.21 while retaining the CUDA 12 baseline at 0.5.17.
Changes:
- Selects versioned patches and updates Blackwell dependencies.
- Adapts runtime APIs, weight reload, routing capture, and multimodal processing.
- Adds regression coverage and updates OPD documentation.
| File | Description |
|---|---|
| tests/utils/test_reloadable_process_group.py | Tests collectives across group reloads. |
| tests/backends/sglang/test_relax_patch_migration.py | Covers migrated patch behavior. |
| tests/backends/sglang/test_reduce_scatterv_gpu.py | Adapts distributed GPU tests. |
| tests/backends/sglang/test_opd_request_validation.py | Tests multimodal token preservation. |
| tests/backends/sglang/test_mxint4_weight_reload.py | Tests MXINT4 reload lifecycle. |
| tests/backends/sglang/test_kimi_k3_weight_reload.py | Updates Kimi test compatibility. |
| tests/backends/sglang/test_fused_moe_routing_capture.py | Tests fused routing capture. |
| tests/backends/sglang/test_dp_moe_reduce_scatter.py | Updates distributed test fixtures. |
| tests/backends/sglang/test_disaggregation_timeout_consensus.py | Tests distributed timeout handling. |
| tests/backends/sglang/test_bf16_moe_weight_reload.py | Tests BF16 reload and repacking. |
| tests/backends/megatron/test_kimi_packed_sequence_compat.py | Tests Kimi packing compatibility. |
| tests/backends/megatron/test_blackwell_flash_attention.py | Tests Blackwell attention and gradients. |
| skills/opd-tuning/references/teacher-knobs.md | Updates chunking variable names. |
| skills/opd-tuning/references/baselines.md | Updates tuning search commands. |
| scripts/models/kimi-k2.6.sh | Allows layer-count overrides. |
| relax/utils/reloadable_process_group.py | Forwards newer collective methods. |
| relax/backends/sglang/sglang_engine.py | Supports record-based server arguments. |
| relax/backends/sglang/routing_replay_patch.py | Preserves native asynchronous capture. |
| examples/on_policy_distillation/README.md | Documents versioned OPD patches. |
| examples/on_policy_distillation/mopd/run-mopd-qwen35-9b-8xgpu-colocate.sh | Updates chunking environment variables. |
| examples/on_policy_distillation/mopd/run-mopd-qwen35-35ba3b-16xgpu-colocate.sh | Updates chunking environment variables. |
| examples/on_policy_distillation/mopd/run-mopd-qwen3-vl-2b-8xgpu-colocate.sh | Updates chunking environment variables. |
| examples/diffusion/README.md | Documents the frozen diffusion baseline. |
| docker/scripts/validate_blackwell.py | Checks expected SGLang version. |
| docker/scripts/ensure_sgl_kernel_sm103.py | Recognizes compatible kernels and source layout. |
| docker/scripts/check_gpu_imports.py | Validates SGLang imports and version. |
| docker/scripts/build_flashinfer_sampling.py | Discovers the installed sampling cache. |
| docker/patch/transformer_engine/2.18.0-blackwell-fa4-head-dim.patch | Adds fallback for unaligned training heads. |
| docker/patch/sglang/v0.5.21_per_pos_topk.patch | Ports per-position logprob support. |
| docker/patch/sglang/v0.5.17_per_pos_topk.patch | Retains the legacy versioned patch. |
| docker/patch/megatron/kimi-packed-sequence-api.patch | Adapts Kimi packing and return handling. |
| docker/Dockerfile.cu13 | Upgrades runtime and applies compatibility patches. |
| docker/Dockerfile | Pins CUDA 12 to matching legacy patches. |
Review effort: Balanced
| async def test_qwen_uncached_image_prefill_preserves_sampled_ids( | ||
| monkeypatch, image_count, repeats, avoid_retokenize, use_legacy_fallback | ||
| ): | ||
| from sglang.srt.multimodal.processors import base_processor, qwen_vl |
There was a problem hiding this comment.
已在固定提交 aae75cf7 的 SGLang 0.5.17 环境复核:单个测试 test_qwen_uncached_image_prefill_preserves_sampled_ids[False-True-1-1] 在第 288 行报 AttributeError,缺失的正是 _process_mm_data_uncached。安装的 Qwen processor 文件与官方 0.5.17 源码一致。可按这里的建议仅限定新增测试的版本,或选择旧版 process_mm_data_async 入口;保留原有 0.5.17 测试覆盖。此检查使用模拟媒体处理,未运行 GPU 推理。
| + preprocess_packed_seqs( | ||
| + inputs_embeds, | ||
| + saved_attention_mask, | ||
| + pre_process=True, | ||
| + )[0] |
| # not recognized by the installed SGLang ServerArgs are dropped with a | ||
| # warning rather than causing a TypeError at ServerArgs(**kwargs). | ||
| server_arg_fields = {f.name for f in dataclasses.fields(ServerArgs)} | ||
| server_arg_fields = {f.name for f in _server_args_fields(ServerArgs)} |
There was a problem hiding this comment.
CUDA 13 升级后,普通 dense GenRM(如 Qwen3)在 --colocate / offload_rollout=True 下会启动失败:这里保留 enable_memory_saver=True,而 GenRMManager._build_engine_env_vars() 固定设置 SGLANG_MEMORY_SAVER_CUDA_GRAPH=true;0.5.21 默认使用 breakable prefill graph,其构造函数会直接抛出 NotImplementedError("Breakable CUDA graph is not compatible with memory saver mode")。_compute_server_args() 已有禁用默认 prefill graph 的兼容分支,_compute_genrm_server_args() 缺少相同处理。请在应用 GenRM 配置覆盖后补上该兼容处理,并覆盖 dense GenRM 的卸载配置。
There was a problem hiding this comment.
补充复核:dense、PP=1 且未显式关闭 prefill graph 的 GenRM 不会命中新版的 PP/KDA/多模态自动禁用分支,启动仍会进入上述拒绝检查。升级环境可暂时在 --genrm-engine-config 中设置 "cuda_graph_backend_prefill": "disabled" 规避;默认配置仍需与 rollout 的 memory-saver 兼容处理对齐。
There was a problem hiding this comment.
本轮新增的 GC 修补只控制 HTTP warmup 后的 freeze_gc 调用,无法修复这里发生在模型初始化阶段的 prefill graph 拒绝。当前 GenRM 参数构造仍未包含 rollout 已有的 memory-saver 兼容分支;请保留此问题为未解决,并将默认 dense GenRM 卸载配置纳入修复验证。
| + precision.weight_scale.storage.data, | ||
| + getattr(self, f"{prefix}_precision_config").weight_scale.storage.data, |
There was a problem hiding this comment.
使用 triton_kernel MoE backend 的 MXFP4 模型在首次权重重载时会抛出 AttributeError:0.5.21 的 _process_mxfp4_weights_after_loading() 已构造 PrecisionConfig(b_mx_scale=...),此处仍读取旧接口的 weight_scale。镜像所带 Triton 3.7.1 的 PrecisionConfig 没有该字段,因此初次加载能完成,下一次 restore/load/postprocess 无法恢复 rollout。请同步更新这两个字段访问,并让重载测试使用新版 precision config 契约。限定的 API 边界复现已得到该异常;未执行 GPU swizzle。
依赖依据:SGLang 构造新版 PrecisionConfig、Triton 3.7.1 字段定义。
| + precision.weight_scale.storage.data, | |
| + getattr(self, f"{prefix}_precision_config").weight_scale.storage.data, | |
| + precision.b_mx_scale.storage.data, | |
| + getattr(self, f"{prefix}_precision_config").b_mx_scale.storage.data, |
There was a problem hiding this comment.
本轮新增的两层 Kimi INT4 示例声明走 compressed-tensors 重量化路径;它的运行结果不能覆盖这里 mxfp4.py 的 Triton PrecisionConfig 重载接口。当前补丁仍在两处读取 weight_scale,请按原建议更新为 b_mx_scale,并用目标 Triton 版本的对象验证第二次权重装载。
| + # the fixed-size DP combine. Write back into the original buffer. | ||
| + reduce_input = input_ | ||
| + reduce_output = output | ||
| + if input_.dtype == torch.bfloat16: |
There was a problem hiding this comment.
开启 SGLANG_ENABLE_DETERMINISTIC_INFERENCE=true 后,新版 reduce_scatterv() 会在这些转换之前返回 _deterministic_reduce_scatterv(input_, output, sizes);该 helper 直接对 BF16 clone 调用 all_reduce()。旧版补丁始终把此处的 BF16 MoE 部分和转为 FP32,因此在使用 NCCL fallback 的拓扑上,升级会重新引入 BF16 中间舍入/抵消误差。请也在确定性分支执行 FP32 reduction,再一次性写回原 dtype/output。边界复现确认 all-reduce 收到 BF16;未在真实 NCCL 上测量误差幅度。
依赖依据:确定性 helper 与提前返回。
| # not recognized by the installed SGLang ServerArgs are dropped with a | ||
| # warning rather than causing a TypeError at ServerArgs(**kwargs). | ||
| server_arg_fields = {f.name for f in dataclasses.fields(ServerArgs)} | ||
| server_arg_fields = {f.name for f in _server_args_fields(ServerArgs)} |
There was a problem hiding this comment.
补充复核:dense、PP=1 且未显式关闭 prefill graph 的 GenRM 不会命中新版的 PP/KDA/多模态自动禁用分支,启动仍会进入上述拒绝检查。升级环境可暂时在 --genrm-engine-config 中设置 "cuda_graph_backend_prefill": "disabled" 规避;默认配置仍需与 rollout 的 memory-saver 兼容处理对齐。
| async def test_qwen_uncached_image_prefill_preserves_sampled_ids( | ||
| monkeypatch, image_count, repeats, avoid_retokenize, use_legacy_fallback | ||
| ): | ||
| from sglang.srt.multimodal.processors import base_processor, qwen_vl |
There was a problem hiding this comment.
已在固定提交 aae75cf7 的 SGLang 0.5.17 环境复核:单个测试 test_qwen_uncached_image_prefill_preserves_sampled_ids[False-True-1-1] 在第 288 行报 AttributeError,缺失的正是 _process_mm_data_uncached。安装的 Qwen processor 文件与官方 0.5.17 源码一致。可按这里的建议仅限定新增测试的版本,或选择旧版 process_mm_data_async 入口;保留原有 0.5.17 测试覆盖。此检查使用模拟媒体处理,未运行 GPU 推理。
Build and install the patched Rust HiCache extension with ABI checks and complete deferred backup/root handling and GC freeze startup ordering. Preserve framework CUDA IPC defaults and support the SM103 CP/FA2 fallback. Add the Kimi two-layer INT4 launcher, regression coverage, and validation notes focused on train/rollout diff, output length, and raw reward. ## Validation - Full pre-commit checks passed. - Installed migration and GC regressions: 99 passed. - CLI, default CUDA IPC, and HiCache regressions: 27 passed per stack. - Paired short training results and validation limits documented.
| # | ||
| # Prerequisite (one-time): | ||
| # Cast the original INT4 release to BF16 HF for the training side: | ||
| # python -m relax.tools.quant_cast.convert_moe_int4_to_bf16 \ |
There was a problem hiding this comment.
按此处前置步骤准备 BF16 checkpoint 时,python -m relax.tools.quant_cast.convert_moe_int4_to_bf16 会报 ModuleNotFoundError: No module named 'relax.tools',因为仓库中的转换器位于 relax/utils/quant_cast/。这会使新增示例在训练启动前就无法完成模型准备;请与现有 256 卡 INT4 示例使用同一入口。
| # python -m relax.tools.quant_cast.convert_moe_int4_to_bf16 \ | |
| # python -m relax.utils.quant_cast.convert_moe_int4_to_bf16 \ |
|
|
||
| # Keep multi-process multimodal features on CUDA across SGLang versions. | ||
| # Explicit CLI values and per-engine config overrides retain priority. | ||
| parser.set_defaults(sglang_mm_feature_transport="cuda_ipc") |
There was a problem hiding this comment.
这里将原先的自动选择改为显式 cuda_ipc,使未配置传输覆盖的跨节点引擎无法启动。例如现有 Qwen 128 卡脚本 设置每引擎 32 卡,按默认每节点 8 卡得到 nnodes=4;参数原样进入 SGLang,0.5.21 和冻结的 0.5.17 均抛出 ValueError: --mm-feature-transport=cuda_ipc only supports a single node.。0.5.21 在实际服务启动的 resolve_once() 阶段执行此校验,早于 tokenizer 初始化,纯文本模型也不会绕过。
请在确定每个引擎的最终拓扑后选择兼容的默认传输,同时保留显式配置的优先级。新增测试将 ServerArgs 替换为仅含传输字段的 dataclass,只验证参数转发;应补充 nnodes>1 的真实上游解析边界。此处针对单个引擎跨节点,不包括各引擎仍为单节点的集群部署。
| # not recognized by the installed SGLang ServerArgs are dropped with a | ||
| # warning rather than causing a TypeError at ServerArgs(**kwargs). | ||
| server_arg_fields = {f.name for f in dataclasses.fields(ServerArgs)} | ||
| server_arg_fields = {f.name for f in _server_args_fields(ServerArgs)} |
There was a problem hiding this comment.
本轮新增的 GC 修补只控制 HTTP warmup 后的 freeze_gc 调用,无法修复这里发生在模型初始化阶段的 prefill graph 拒绝。当前 GenRM 参数构造仍未包含 rollout 已有的 memory-saver 兼容分支;请保留此问题为未解决,并将默认 dense GenRM 卸载配置纳入修复验证。
| + precision.weight_scale.storage.data, | ||
| + getattr(self, f"{prefix}_precision_config").weight_scale.storage.data, |
There was a problem hiding this comment.
本轮新增的两层 Kimi INT4 示例声明走 compressed-tensors 重量化路径;它的运行结果不能覆盖这里 mxfp4.py 的 Triton PrecisionConfig 重载接口。当前补丁仍在两处读取 weight_scale,请按原建议更新为 b_mx_scale,并用目标 Triton 版本的对象验证第二次权重装载。
## What - CUDA 13 配方升级到官方 **SGLang 0.5.21**,迁移完整 Relax patch;CUDA 12 保持 0.5.17。 - 补齐 **PD + R3**:prefill 路由采集、decode 合并、CPU HiCache/retraction、多轮 Session 和 router 兼容性。 ## Why 基于上游 0.5.20 重新迁移,保留 OPD、Qwen/Kimi、权重热更新能力,并参考 Miles 补齐 PD+R3。替代 #459。 ## How - 固定源码版本、重建 Rust tree core,适配权重更新与 Blackwell 注意力;P 端真实路由覆盖 D 端占位前缀,保留已接受 token 的路由。 - **审查修复**:按各引擎最终拓扑选择 multimodal transport,仅单节点默认 CUDA IPC,保留显式配置;deterministic BF16 reduce-scatter 使用 FP32 累加,保留输出 dtype/buffer。 - **单测整理**:删除冗余参数组合,按权重更新、路由、引擎参数及 patch 兼容性归并,净减少 **5 个文件**;合并未丢失保留用例。 ## Testing - [x] `pre-commit run --all-files` passes - [ ] Tests pass (`pytest tests/`) — 未跑全仓库,专项结果见下。 - [x] New tests added (if applicable) - [x] Documentation updated (if applicable) 最新验证对应 `6cd6c9c`:**SGLang 0.5.21 / PyTorch 2.13.0+cu130 / CUDA 13.0 / Blackwell SM103(compute capability 10.3)**。 - 合并后 CPU 回归 **343 passed / 7 skipped**;这 7 项已在 GPU 上全部通过,相关代码未变,沿用结果;合计覆盖 **350 项,无剩余跳过**。 - GPU 覆盖 NCCL/CUDA Graph、BF16 reduction、Qwen 权重重载、进程组重载,以及 FA2/FA4 前反向和 CP 后端选择。 - 完整 patch 干净应用到官方 0.5.21,89 个受影响 Python 文件编译通过。 ## Type of Change - [x] 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 - [x] Refactoring (no functional changes) - [ ] Performance improvement - [x] CI/CD or build changes ## Screenshots / Logs 升级阶段单机 8 GPU、各 **5 轮**端到端结果;本次审查修复后未重跑: | 场景 | 样本数 | 平均训推 diff | 平均 assistant 输出 tokens | raw_reward | | --- | ---: | ---: | ---: | ---: | | Qwen3.5 regular + R3 | 1280 | 0.0086975 | 1564.1305 | 0.315625 | | Qwen3.5 PD + R3 | 1280 | 0.0087124 | 1562.5563 | 0.3140625 | | Mini-SWE PD + R3 + CPU HiCache | 80 | 0.0090159 | 7910.7 | 0.3375 | Qwen 对照使用 router 后续修正前的成功请求路径;Mini-SWE 最后一轮验证最新 router。验收看上述指标,不要求 logprob 严格一致。使用隔离运行时,未重建完整 Docker 镜像,未覆盖多节点及其他 GPU 架构。


What
Upgrade the CUDA 13 training runtime from SGLang 0.5.17 to 0.5.21, with versioned ports of Relax's existing SGLang patches and the required build/runtime compatibility updates.
docker/Dockerfile.cu13docker/DockerfileWhy
SGLang 0.5.21 changes server-argument records, MoE weight-loading paths, routing capture, and logprob/multimodal internals. Relax's existing rollout and training integration needs a version-specific patch port and compatibility updates for the target PyTorch/CUDA stack.
How
docker/patch/sglang/, point bothlatestaliases to 0.5.21, and retain the 0.5.17 per-position patch for the frozen CUDA 12 image.ServerArgsfield inspection, routing-replay guards, and reloadable process-group forwarding to the updated SGLang and PyTorch APIs.load_mm_data(); migrate per-position OPD query validation, chunk handling, and Base64 logprob transport.Testing
pre-commit run --all-filespassespytest tests/)Type of Change
Screenshots / Logs
N/A