Issue662#667
Open
DH13768095744 wants to merge 16 commits into
Open
Conversation
Collaborator
|
再适配一下 flashsac 吧,任务指令: |
Collaborator
|
补充报告: |
Collaborator
Author
都弄了 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reduce FastSAC learner launch fragmentation
背景
这个 PR 处理的是 FastSAC 在
sac/g1_walk_flat/mujoco上暴露出的 learner-side GPU duty cycle 低、tiny kernel 过多、CUDA launch API bound 的问题,并用sac/g1_walk_rough/mujoco做相邻任务复核。核心判断是:当前瓶颈主要不是稳定态 replay/H2D starvation,而是 SAC learner update 被切成大量微小 CUDA kernels;这些 kernels 在 RTX 5090 D 这类大 GPU 上无法填满 SM,并且 CUDA runtime launch API 的累计成本高于 GPU kernel 设备端执行时间。
本 PR 的优化范围保持在 FastSAC learner、off-policy runtime、replay staging owner layer 内,不把长期业务规则放到
scripts/,也不改变 env/backend contract、runner lifecycle 或 SAC 的数学语义。Summary
实验环境
Root Cause Evidence
Timeline trace
Nsight Systems
Nsight Compute
torch.compile coverage
Replay / H2D costs
NVTX attribution
Main vs Issue662 AB Profile
AB test 比较
origin/main与issue662,覆盖两个任务:sac/g1_walk_flat/mujocosac/g1_walk_rough/mujoco每个 task/variant 运行 3 次,E2E 时间取均值,error bar 表示 min/max。关键 profile 指标包括 tiny kernel 数量、launch API time/count、MemcpyAsync、stream sync、GPU metrics、graph copy range 和 time-reward smoke。
E2E wall time
Reward smoke
Infra metrics
GPU metrics
Graph boundary copy ranges
Cycle-level learner update
FlashSAC Extension
同一类 CUDA graph 优化已经迁移到 FlashSAC 路径,并保持 opt-in 语义。默认
conf/offpolicy/algo/flashsac.yaml仍关闭use_cuda_graph_critic、use_cuda_graph_actor、use_cuda_graph_critic_packed_staging和use_cuda_graph_actor_packed_staging;只有显式 override 时,FlashSAC learner 才进入 graph replay 路径。实现上,FlashSAC learner 增加 critic / actor graph capture 与 replay body,runner 将 Hydra 参数传递到 learner,double-buffer runtime 只在 learner 显式声明支持 packed staging 且对应 flag 打开时生成sac_graph_packed_source。因此,优化边界仍位于 learner / replay staging owner layer,没有把 FlashSAC 的私有能力泄漏到 env 或 backend contract。该迁移复用了 FastSAC/SAC 中已经验证过的设计原则:graph replay 使用固定地址 staging buffer;shape 变化会重建 graph;packed staging 只改变 graph 输入组织方式,不改变 replay sampling、critic update、actor update、temperature update 或 target soft update 的数学含义。由此,FlashSAC 的修改目标被限定为降低 learner update 的 launch fragmentation,而不是改变策略优化问题本身。
FlashSAC timeline evidence
FlashSAC 的原始 clean timeline 显示,cycle 中的长条主要来自 collector pacing、actor inference、env step 以及 learner update 的交叠压力。Figure 27 给出未启用 FlashSAC graph path 时的稳态 cycle 分解;这说明 FlashSAC 的瓶颈并不只是单个 GPU kernel 慢,而是 collector/learner pipeline 中多个短阶段的重复调度成本。
在 Motrix 后端上启用
both_graph_packed后,Figure 28 的 smoke timeline 显示 learner update 被压缩到更窄的 cycle 区间。该图的意义不在于单独证明最终吞吐,而在于显示 CUDA graph + packed staging 对 cycle 内 learner 窗口的结构性影响:critic/actor update 不再以大量碎片化 launch 的形式铺满一个宽窗口,而是更集中地完成。Figure 29 将同一 optimized path 延长到
iter=50后重新统计,避免只依赖极短 smoke run 的瞬时形态。iter50 timeline 中,cycle 仍保留 actor inference 与 env step 的可见占比,说明后续瓶颈会更多转向 collector/env cadence;但 learner update 的 cycle 占位已经显著收敛,这与 CUDA graph 主要压缩 launch-bound learner work 的预期一致。FlashSAC time-reward evidence
从宏观行为看,FlashSAC CUDA graph path 的核心收益是 wall-clock 压缩,而不是 reward 函数或样本效率的改变。MuJoCo 与 Motrix 的
iter=500time-reward 图均以 3 个 seed 串行运行,TensorBoardreward/mean按训练 wall time 对齐,均值曲线配合 min/max band 展示。两组后端上,baseline 与 optimized 曲线处于同一行为量级;局部早期区间中 baseline/native 曲线可能先达到较高 reward,因此这些图不支持把 CUDA graph 解读为提升 reward 收敛速度的算法改动。它们支持的结论更窄:在未观察到明显行为漂移的前提下,optimized path 更快完成相同 iteration 预算。Semantic Equivalence / Algorithm Safety
这个 PR 的设计目标是 infra-level launch reduction,而不是改变 SAC 算法。
保持不变的语义包括:
training.sim_backend、task/reward/backend 选择仍走 Hydra + owner config,不在脚本层绕开 contract。Reward smoke 图只支持短 run 中未观察到明显异常;长期策略质量仍应通过更长训练和更多 seed 验证。