perf(mujoco): 单卡默认 pool 线程数收敛到有效 CPU 数,消除 2× 超订 (#1328) - #1333
Merged
TATP-233 merged 1 commit intoAug 27, 2026
Merged
Conversation
…rsubscription (#1328) Single-GPU (cpu_ids=None) BatchEnvPool sizing now uses the CPUs actually usable by this process (len(os.sched_getaffinity(0)), falling back to os.cpu_count() where unavailable) instead of 2*cpu_count(). Measured on this machine (sac + g1_motion_tracking + mujoco, num_envs=4096, 2000 iters, steady-state second-half median): 86,162 -> 96,262 steps/s (+11.7%), collector env_step 47.6ms -> 41.9ms. Explicit cpu_ids still fixes nthread = len(cpu_ids).
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.
Fixes #1328
改动
src/unilab/base/backend/mujoco/backend.py:新增_effective_cpu_count()(len(os.sched_getaffinity(0)),尊重 taskset/cgroup;macOS 等无此 syscall 的平台回退os.cpu_count()),单卡(cpu_ids=None)默认 sizing 从min(num_envs, 2*cpu_count())改为min(num_envs, _effective_cpu_count())。显式cpu_ids路径不变(nthread = len(cpu_ids))。tests/base/backend/test_mujoco_cpu_affinity_wiring.py:新增两条 sizing 规则单测(默认 = 有效 CPU 数;被num_envs截断)。tests/base/backend/test_mujoco_chunk_size_wiring.py:原有测试改为 monkeypatch_effective_cpu_count(原先 patchcpu_count,在 ≥4 核机器上对本 sizing 已失效,会导致 benchmark 分支被短路)。chunk tuner 的 cache key 含
nthread(chunk_tuner.py),默认线程数变化后自动重调,无脏 cache。Validation
make test-all@ df9def3:2286 passed, 28 skipped, 1 xfailed(All checks passed)。src/unilab/envs/{locomotion,manipulation,motion_tracking}三个纯__pycache__残留目录(非 git 跟踪文件),它们以 namespace package 形式导致test_removed_legacy_env_packages_stay_removed假失败;与代码改动无关。scripts/benchmark/env/benchmark_env_step.pyimport 时全局且不可撤销地 patchunilab.base.backend.create_backend(mujoco_warp 可导入时),致tests/base/test_motrix_backend_options.py两个用例在全量套件中失败(单跑通过);base 分支(dev/issue-1042)上不复现。建议单独建 issue 跟进。uv run train --algo sac --task g1_motion_tracking --sim mujoco algo.num_envs=4096 algo.max_iterations=2000,tfevents 后半程 median):perf/steps_per_secperf/iter_mstiming/collector_env_step_mstiming/learner_train_ms满足 acceptance:默认
nthread == min(num_envs, 有效 CPU 数);显式cpu_ids仍为len(cpu_ids);稳态 steps/s +11.7%(≥5%)。本机为 collector-bound(learner 仅 ~20ms/iter),收益集中在 env_step 物理相,与 issue 的 Linux 机型诊断一致。范围外(issue non-goals,未动)
scripts/benchmark/下裸测脚本中的2*cpu_countsizing。