ray.rllib.policy.torch_policy_v2.TorchPolicyV2.from_checkpoint#
- static TorchPolicyV2.from_checkpoint(checkpoint: str | Checkpoint, policy_ids: Collection[str] | None = None) Policy | Dict[str, Policy] #
Creates new Policy instance(s) from a given Policy or Algorithm checkpoint.
Note: This method must remain backward compatible from 2.1.0 on, wrt. checkpoints created with Ray 2.0.0 or later.
- Parameters:
checkpoint – The path (str) to a Policy or Algorithm checkpoint directory or an AIR Checkpoint (Policy or Algorithm) instance to restore from. If checkpoint is a Policy checkpoint,
policy_ids
must be None and only the Policy in that checkpoint is restored and returned. If checkpoint is an Algorithm checkpoint andpolicy_ids
is None, will return a list of all Policy objects found in the checkpoint, otherwise a list of those policies inpolicy_ids
.policy_ids – List of policy IDs to extract from a given Algorithm checkpoint. If None and an Algorithm checkpoint is provided, will restore all policies found in that checkpoint. If a Policy checkpoint is given, this arg must be None.
- Returns:
An instantiated Policy, if
checkpoint
is a Policy checkpoint. A dict mapping PolicyID to Policies, ifcheckpoint
is an Algorithm checkpoint. In the latter case, returns all policies within the Algorithm ifpolicy_ids
is None, else a dict of only those Policies that are inpolicy_ids
.