unisim.backend.mujoco.chunk_tuner¶
Adaptive thread-pool chunk_size selection for the MuJoCo BatchEnvPool.
All probing/benchmarking happens on the cold path (materialize()), never on
step/reset. Results are cached on disk keyed by model signature + device
fingerprint + (num_envs, nthread, dtype, …) so repeated trainings reuse them.
Functions
|
Min wall-clock of a representative |
Coarse, deterministic local-device descriptor for the cache key. |
|
|
Best-effort inter-process exclusive lock; no-op where fcntl is absent. |
|
Clamp to |
|
|
|
|
|
Candidate chunk_sizes within |
|
Structural determinants of per-step cost (proxy for 'task'). |
|
|
|
|
|
- unisim.backend.mujoco.chunk_tuner.make_candidates(num_envs, nthread)[source]¶
Candidate chunk_sizes within
[1, upper], densified at the sweet spot.upper = ceil(num_envs / nthread)is a hard ceiling: a chunk_size beyond it produces fewer chunks than threads, leaving threads idle -> always slower. The optimum sits nearheur = num_envs / (10 * nthread)(~10 chunks per thread), so the band around it is sampled densely while the always-bad large chunks are never generated.
- unisim.backend.mujoco.chunk_tuner.filter_candidates(candidates, num_envs, *, max_candidates=16)[source]¶
Clamp to
[1, num_envs], dedup, sort. If over the cap, trim the coarse middle while keeping the low/optimum band (smallest values) plus the coarsest anchor – never log-spaced (which used to drop the optimum).
- unisim.backend.mujoco.chunk_tuner.device_fingerprint()[source]¶
Coarse, deterministic local-device descriptor for the cache key.
- unisim.backend.mujoco.chunk_tuner.model_signature(model, n_variants)[source]¶
Structural determinants of per-step cost (proxy for ‘task’).
- unisim.backend.mujoco.chunk_tuner.make_cache_key(*, backend_type, model_sig, device, num_envs, nthread, dtype, post_step_forward_sensor, bench_nsteps)[source]¶
- unisim.backend.mujoco.chunk_tuner.file_lock(lock_path)[source]¶
Best-effort inter-process exclusive lock; no-op where fcntl is absent.
- Parameters:
lock_path (
Path)
- unisim.backend.mujoco.chunk_tuner.benchmark_chunk_sizes(pool, state, nstep, candidates, *, control, post_step_forward_sensor, warmup=2, reps=20, time_budget_s=25.0)[source]¶
Min wall-clock of a representative
pool.stepper candidate.Each candidate is sampled
repstimes and reduced viamin(uncontended cost).None(native default) is always measured as the baseline anchor.
- unisim.backend.mujoco.chunk_tuner.select_chunk_size(timings, base, *, margin=0.03, tie_tol=0.02)[source]¶