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:
objectBuild env/play overrides from the final composed config.
- Parameters:
- __init__(cfg, *, root_dir, algo_name=None, scene_materializer=<function materialize_scene_visual_override>)[source]¶
- class unilab.training.ExperimentTracker[source]¶
Bases:
objectTracks experiment metadata locally and optionally in Weights & Biases.
- __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]¶
- unilab.training.algo_config_dict(cfg)[source]¶
Resolve the composed
cfg.algosubtree into a plain mutable dict.
- unilab.training.apply_env_nan_guard(env, training_cfg)[source]¶
Attach a
NanGuardtoenvwhen diagnostics are enabled.
- 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.
- unilab.training.build_run_dir_name(timestamp, sim_backend, *, world_size=1)[source]¶
Return the canonical run directory name shared by all training entries.
- 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.
- unilab.training.ensure_registries()[source]¶
Import env modules so registry-based entrypoints can instantiate tasks.
- Return type:
- 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.
- unilab.training.get_hydra_runtime_choice(cfg, group)[source]¶
Return a selected Hydra config-group choice when runtime metadata is available.
- unilab.training.get_latest_checkpoint(run_dir, *, suffix='.pt')[source]¶
Return the latest model checkpoint inside a run directory.
- unilab.training.get_latest_run(log_dir)[source]¶
Return the lexicographically latest run directory under a task log root.
- 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 explicitlog_rootargument) wins; otherwise theUNILAB_TEST_LOG_ROOToverride applies; otherwise the default is<root_dir>/logs/<algo_log_name>. Pass either a composed Hydracfgor an explicitalgo_log_name.
- unilab.training.graceful_keyboard_interrupt(entrypoint)[source]¶
Let entrypoint cleanup finish, then exit Ctrl+C without a traceback.
Runners own their
finallyblocks. This outer boundary converts only the resultingKeyboardInterruptinto the conventional shell status after all collector, logger, and distributed-process cleanup has completed.
- unilab.training.is_viser_play_render_mode(play_render_mode)[source]¶
Return whether the configured mode selects the browser-based viser viewer.
viseris a UniLab-level playback mode layered on top of the unisimPLAY_RENDER_MODEScontract; it renders through the shared MuJoCo playback shell instead of a backend-native renderer, so it never reachesSimBackend.resolve_play_render_plan.
- unilab.training.log_playback_plan(plan, *, prefix='')[source]¶
Print user-facing playback status for a resolved backend plan.
- 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.
- unilab.training.resolve_checkpoint_path(task_log_root, load_run, *, checkpoint=None, suffix='.pt')[source]¶
Resolve a checkpoint from a task log root.
load_runselects the run:"-1"picks the latest run undertask_log_root; any other value is first tried as a direct path and then relative totask_log_root, and may name either a run directory or a checkpoint file.checkpointoptionally 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).
- 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.
- unilab.training.resolve_nan_guard_cfg(training_cfg)[source]¶
Build the shared tensor diagnostics config, or
None.- Parameters:
training_cfg (
Any)- Return type:
- 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.
- unilab.training.should_run_playback(*, play_only, no_play, play_render_mode)[source]¶
Return whether train/eval should enter playback for the configured mode.
- class unilab.training.TrainingSeedInfo[source]¶
Bases:
objectConfigured and effective seed metadata for a training run.
- 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:
- unilab.training.apply_training_seed(seed, *, torch_runtime=True, cuda=True)[source]¶
Apply a seed to the runtimes used by training entrypoints.
- unilab.training.resolve_training_seed(cfg)[source]¶
Resolve the configured seed from the algorithm-level
algo.seedcontract.- Parameters:
cfg (
Any)- Return type:
- 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.
Modules
Shared helpers for training entrypoints. |
|
User-owned CUDA MPS daemon management for the UniLab CLI. |
|
Fail-closed validation for CUDA process-sharing execution modes. |
|
Hydra-side data-parallel configuration assembly. |
|
Shared experiment tracking utilities for local files and W&B. |
|
ONNX export and onnxruntime numeric verification helpers for play entrypoints. |
|
Run directory and checkpoint resolution helpers. |
|
Shared training seed contract helpers. |
|
Resource and progress monitoring for long-duration training soaks. |
|
Finite-state diagnostics for the tensor-native environment runtime. |
|
Hydra config resolution for the off-policy tensor-runtime contract. |
|
Pickleable runtime hooks injected across the |