lit_sb3.utils.model
source module lit_sb3.utils.model
Trained model path and hyperparameter loading utilities.
Functions
-
get_saved_hyperparams — Load hyperparameters saved by :class:
~lit_sb3.core.exp_manager.ExperimentManager. -
get_hf_trained_models — Fetch trained models from a HuggingFace organisation.
-
get_trained_models — Scan log_folder for trained agents saved by the ExperimentManager.
-
get_model_path — Retrieve the path to a trained model, along with its log directory.
source get_saved_hyperparams(stats_path: str | Path, norm_reward: bool = False, test_mode: bool = False) → tuple[dict[str, Any], str | Path | None]
Load hyperparameters saved by :class:~lit_sb3.core.exp_manager.ExperimentManager.
Parameters
-
stats_path : str | Path — Path to the folder containing
config.yml. -
norm_reward : bool — Whether to keep reward normalisation active.
-
test_mode : bool — Disable reward normalisation and training flag.
Returns
-
tuple[dict[str, Any], str | Path | None] — Tuple of
(hyperparams_dict, stats_path_or_None).
source get_hf_trained_models(organization: str = 'sb3') → dict[str, tuple[str, str]]
Fetch trained models from a HuggingFace organisation.
Returns a dict mapping model names to (algo, env_id) tuples,
mirroring :func:get_trained_models.
Requires huggingface_hub to be installed.
:param organization: HuggingFace organisation to search.
:return: Dict mapping model names to (algo, env_id) tuples.
Raises
-
ImportError
source get_trained_models(log_folder: str) → dict[str, tuple[str, str]]
Scan log_folder for trained agents saved by the ExperimentManager.
Parameters
-
log_folder : str — Root log directory (same as
--log-folderin training).
Returns
-
dict[str, tuple[str, str]] — Dict mapping
ModelNamestrings to(algo, env_id)tuples.
source get_model_path(exp_id: int, folder: str, algo: str, env_name: EnvironmentName, load_best: bool = False, load_checkpoint: str | None = None, load_last_checkpoint: bool = False) → tuple[str, str, str]
Retrieve the path to a trained model, along with its log directory.
Parameters
-
exp_id : int — Experiment ID (0 → use the latest available run).
-
folder : str — Root folder where run directories are stored (e.g.
logs/). -
algo : str — Algorithm name, e.g.
"ppo". -
env_name : EnvironmentName — :class:
EnvironmentNamewrapper for the target environment. -
load_best : bool — When
True, loadbest_model.zipinstead of the final checkpoint. -
load_checkpoint : str | None — If non-
None, load the model saved at this specific step count (e.g."10000"). -
load_last_checkpoint : bool — When
True, load the numerically largest step-count checkpoint rather than the final model.
Returns
-
tuple[str, str, str] —
(name_prefix, model_path, log_path)where name_prefix is a human-readable identifier, model_path points to the.zipfile, and log_path is the run directory.
Raises
-
ValueError