unilab.training

Shared training helpers for entrypoint scripts.

The re-exports below keep the owner-facing unilab.training import path clear. New code should import from canonical owner modules instead (unilab.training.*, unilab.base.config_adapter, and unisim.backend.base).

class unilab.training.EnvConfigAdapter[source]

Bases: object

Build env/play overrides from the final composed config.

Parameters:
__init__(cfg, *, root_dir, algo_name=None, scene_materializer=<function materialize_scene_visual_override>)[source]
Parameters:
build_task_env_cfg_override()[source]

Build env_cfg_override from the resolved reward + env sections.

Return type:

dict[str, Any]

build_play_env_cfg_override()[source]

Build play-mode overrides from an optional backend-agnostic play profile.

Return type:

dict[str, Any]

class unilab.training.ExperimentTracker[source]

Bases: object

Tracks experiment metadata locally and optionally in Weights & Biases.

Parameters:
__init__(*, root_dir, log_dir, algo_name, task_name, sim_backend, training_cfg, full_cfg, device=None, configured_device=None, collector_device=None, device_resolution=None, seed_info=None, tf32_matmul_policy=None)[source]
Parameters:
property run: Any | None
property run_url: str | None
property wandb_settings: dict[str, Any]
start()[source]
Return type:

None

update_summary(summary=None)[source]
Parameters:

summary (dict[str, Any] | None)

Return type:

None

log_video(video_path, key='media/play_video')[source]
Parameters:
Return type:

None

finish()[source]
Return type:

None

unilab.training.algo_config_dict(cfg)[source]

Resolve the composed cfg.algo subtree into a plain mutable dict.

Parameters:

cfg (DictConfig)

Return type:

dict[str, Any]

unilab.training.apply_env_nan_guard(env, training_cfg)[source]

Attach a NanGuard to env when diagnostics are enabled.

Parameters:
  • env (Any)

  • training_cfg (Any)

Return type:

None

unilab.training.assert_offpolicy_task_choice_matches_algo(cfg, *, algo_name=None)[source]

Reject off-policy configs whose cfg.algo.algo does not match the requested algo.

Parameters:
  • cfg (DictConfig)

  • algo_name (str | None)

Return type:

None

unilab.training.build_run_dir_name(timestamp, sim_backend, *, world_size=1)[source]

Return the canonical run directory name shared by all training entries.

Parameters:
  • timestamp (str)

  • sim_backend (str)

  • world_size (int)

Return type:

str

unilab.training.create_env(cfg, *, num_envs, env_cfg_override=None, sim_backend=None, task_name=None)[source]

Construct an environment via the registry using the current Hydra config.

Parameters:
unilab.training.ensure_registries()[source]

Import env modules so registry-based entrypoints can instantiate tasks.

Return type:

None

unilab.training.format_play_checkpoint_error(cfg, *, task_log_root, load_path, load_path_dir)[source]

Build the user-facing diagnostic for an unresolvable play checkpoint.

Parameters:
Return type:

str

unilab.training.get_hydra_runtime_choice(cfg, group)[source]

Return a selected Hydra config-group choice when runtime metadata is available.

Parameters:
  • cfg (DictConfig)

  • group (str)

Return type:

str | None

unilab.training.get_latest_checkpoint(run_dir, *, suffix='.pt')[source]

Return the latest model checkpoint inside a run directory.

Parameters:
Return type:

Path | None

unilab.training.get_latest_run(log_dir)[source]

Return the lexicographically latest run directory under a task log root.

Parameters:

log_dir (str | Path)

Return type:

Path | None

unilab.training.get_log_root(root_dir, cfg=None, *, algo_log_name=None, log_root=None)[source]

Resolve the algorithm log root.

The configured training.log_root (or the explicit log_root argument) wins; otherwise the UNILAB_TEST_LOG_ROOT override applies; otherwise the default is <root_dir>/logs/<algo_log_name>. Pass either a composed Hydra cfg or an explicit algo_log_name.

Parameters:
Return type:

Path

unilab.training.graceful_keyboard_interrupt(entrypoint)[source]

Let entrypoint cleanup finish, then exit Ctrl+C without a traceback.

Runners own their finally blocks. This outer boundary converts only the resulting KeyboardInterrupt into the conventional shell status after all collector, logger, and distributed-process cleanup has completed.

Parameters:

entrypoint (TypeVar(_F, bound= Callable[..., Any]))

Return type:

TypeVar(_F, bound= Callable[..., Any])

unilab.training.is_viser_play_render_mode(play_render_mode)[source]

Return whether the configured mode selects the browser-based viser viewer.

viser is a UniLab-level playback mode layered on top of the unisim PLAY_RENDER_MODES contract; it renders through the shared MuJoCo playback shell instead of a backend-native renderer, so it never reaches SimBackend.resolve_play_render_plan.

Parameters:

play_render_mode (str | None)

Return type:

bool

unilab.training.log_playback_plan(plan, *, prefix='')[source]

Print user-facing playback status for a resolved backend plan.

Parameters:
  • plan (PlayRenderPlan)

  • prefix (str)

Return type:

None

unilab.training.nonfatal_play_step(step)[source]

Keep independent post-training play artifacts (ONNX export, video render) from blocking each other: log the failure and continue with the rest.

Parameters:

step (str)

Return type:

Iterator[None]

unilab.training.resolve_checkpoint_path(task_log_root, load_run, *, checkpoint=None, suffix='.pt')[source]

Resolve a checkpoint from a task log root.

load_run selects the run: "-1" picks the latest run under task_log_root; any other value is first tried as a direct path and then relative to task_log_root, and may name either a run directory or a checkpoint file. checkpoint optionally selects one checkpoint inside the resolved run (an iteration number or a filename).

Returns (checkpoint_path, run_dir). A resolved run that lacks the requested (or any) checkpoint yields (None, run_dir); an unresolvable run yields (None, None).

Parameters:
Return type:

tuple[Path | None, Path | None]

unilab.training.resolve_configured_checkpoint_path(cfg, *, root_dir, load_run=None, task_name=None, checkpoint=None, suffix='.pt')[source]

Resolve a checkpoint path from Hydra config and repository root.

Parameters:
Return type:

tuple[Path | None, Path | None]

unilab.training.resolve_nan_guard_cfg(training_cfg)[source]

Build the shared tensor diagnostics config, or None.

Parameters:

training_cfg (Any)

Return type:

NanGuardCfg | None

unilab.training.resolve_run_log_dir(cfg, *, world_size=1, timestamp=None, root_dir=None)[source]

Resolve one canonical run directory shared by all distributed ranks.

Parameters:
Return type:

str

unilab.training.should_run_playback(*, play_only, no_play, play_render_mode)[source]

Return whether train/eval should enter playback for the configured mode.

Parameters:
Return type:

bool

class unilab.training.TrainingSeedInfo[source]

Bases: object

Configured and effective seed metadata for a training run.

Parameters:
configured_seed: int | None
configured_seed_source: str | None
effective_seed: int | None
to_dict()[source]
Return type:

dict[str, int | str | None]

__init__(configured_seed, configured_seed_source, effective_seed)
Parameters:
unilab.training.apply_configured_training_seed(cfg, *, torch_runtime=True, cuda=True)[source]

Resolve and apply the configured training seed before runtime construction.

Parameters:
Return type:

TrainingSeedInfo

unilab.training.apply_training_seed(seed, *, torch_runtime=True, cuda=True)[source]

Apply a seed to the runtimes used by training entrypoints.

Parameters:
Return type:

int | None

unilab.training.resolve_training_seed(cfg)[source]

Resolve the configured seed from the algorithm-level algo.seed contract.

Parameters:

cfg (Any)

Return type:

TrainingSeedInfo

unilab.training.setup_logger(log_dir, algo_name, *, echo=True, filename='train.log')[source]

Create a simple file-backed logger for script-local progress messages.

Parameters:
Return type:

Logger

Modules

common

Shared helpers for training entrypoints.

cuda_mps_cli

User-owned CUDA MPS daemon management for the UniLab CLI.

cuda_process_sharing

Fail-closed validation for CUDA process-sharing execution modes.

dp_config

Hydra-side data-parallel configuration assembly.

experiment

Shared experiment tracking utilities for local files and W&B.

onnx_export

ONNX export and onnxruntime numeric verification helpers for play entrypoints.

run

Run directory and checkpoint resolution helpers.

seed

Shared training seed contract helpers.

soak

Resource and progress monitoring for long-duration training soaks.

tensor_diagnostics

Finite-state diagnostics for the tensor-native environment runtime.

tensor_runtime

Hydra config resolution for the off-policy tensor-runtime contract.

tensor_runtime_hooks

Pickleable runtime hooks injected across the unilab.rl spawn boundary.