perf(fastsac): async collector push 的拷贝冗余与同步阻塞 - #63
Conversation
7c14df9 to
152f309
Compare
g1-wbt-dance 吞吐实测(RTX 5090 / 32 核,2048 envs,各 300 iters)
分解:
两项合计 +11%(76k -> 85k env-steps/s)。 注:300 iters 短程数据,iter200/iter300 采样点间波动约 ±1.5%;合并前可用 1000+ iters 复核稳态。 |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The new CPU affinity implementation can crash on platforms or environments without os.sched_getaffinity/sched_setaffinity, and the ring now requires ring_capacity >= 2 to avoid deadlock but does not currently enforce it.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (3)
What changed in this PR
This PR ports two performance-focused changes onto origin/main for the FastSAC async (two-process) trainer: reducing shared-memory ring copy/footprint by eliminating redundant next_obs storage, and adding optional per-process CPU affinity + thread capping to prevent the learner from stealing CPU resources from the collector.
Changes:
- Optimize
SharedTransitionRingto store 6 tensors per slot (derivenext_obs/next_critic_obsfrom the successor slot) and update learner/collector handoff accordingly. - Add configurable CPU core pinning for async learner and collector processes, and cap Torch intra-op threads per process.
- Update base config + tests to include the new async options and document the new knobs.
| File | Description |
|---|---|
| motrix_rl/tests/test_rl_sim_backend.py | Extends async test config to include the new CPU pinning options. |
| motrix_rl/src/motrix_rl/fastsac/config.py | Adds learner_cpu_cores / collector_cpu_cores to async options config. |
| motrix_rl/src/motrix_rl/fastsac/async_impl/worker.py | Implements CPU core spec parsing and applies pinning + torch.set_num_threads in worker processes. |
| motrix_rl/src/motrix_rl/fastsac/async_impl/shm.py | Removes next_obs storage from the transition ring and adds successor-slot accessors. |
| motrix_rl/src/motrix_rl/fastsac/async_impl/learner.py | Updates ring draining to wait for successor slot and derive next_obs/next_critic_obs. |
| motrix_rl/src/motrix_rl/fastsac/async_impl/collector.py | Updates ring push to match 6-field slots and uses actor buffers for action scaling. |
| configs/algo_base/motrix.fastsac.yaml | Documents and exposes the new CPU affinity configuration knobs. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
152f309 to
811a9c7
Compare
811a9c7 to
44cd228
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
torch.set_num_threads is skipped when affinity pinning fails (reducing the reliability of the intended CPU isolation), and the collector docstring currently contradicts the new “final batch may remain unconsumed” behavior.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
Resolved since last review (2)
44cd228 to
9861f22
Compare
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
The new ring_capacity >= 2 contract breaks an existing in-repo benchmark utility that still constructs SharedTransitionRing(1, ...), and that call site should be updated (or the API explicitly accommodate that use).
Review effort: Lite
Findings: None
Resolved since last review (1)
…king Closes #61, Closes #62 - halve transition-ring push cost on the CPU-env path (shm.py ring push copy optimization); the GPU-env async D2H staging path is not wired up yet and will be added together with GPU-env support (#61) - per-side CPU affinity pinning for the async learner/collector processes, configured as core specs like "0:5,7" via learner_cpu_cores / collector_cpu_cores (#62) Benchmark (g1-sonic 4096 envs): env_step 55 -> ~47ms, steady throughput ~59k -> ~65k env-steps/s.
9861f22 to
aa3bde2
Compare
|
Copilot 最新 overview 提到 |



Closes #61, Closes #62
基于
origin/main的两个 perf commit(从perf/fastsac-async-pushcherry-pick 而来):#61 — async collector push 的拷贝冗余与同步阻塞
shm.pyring push 优化)#62 — async learner 抢 CPU 核拖慢 collector
"0:5,7"表示核 0–5 加 7;越界核自动丢弃;null 关闭该侧 pinningtorch.set_num_threads把线程数限制在各自核片内Benchmark(g1-sonic 4096 envs):env_step 55 -> ~47ms,稳定吞吐 ~59k -> ~65k env-steps/s(对应 #62 配比表中 learner 2 核的最优档)。
cherry-pick 冲突解决:
collector.py中 main 侧使用构造参数action_scale/action_bias,按分支侧改为self.actor.action_scale(main 的Actor注册同名 buffer,语义等价)。