OfflineToOnlineTrainer#
- class torchrl.trainers.algorithms.OfflineToOnlineTrainer(*args, **kwargs)[source]#
A SAC trainer for the offline-pretrain -> online-finetune transition.
See also
OfflineToOnlineTrainerConfigfor the Hydra configuration counterpart.Builds on
SACTrainer, swapping the plain replay buffer for anOfflineToOnlineReplayBuffer. Each collected batch is routed to the online buffer while optimization samples a mixed batch whose offline fraction is linearly annealed to zero overanneal_framesframes – warm-starting the policy on offline data and smoothly handing it over to its own online experience. All other SAC behaviour (target-net updates, weight sync, logging) is inherited.- Parameters:
collector (BaseCollector) – the data collector for online interactions.
total_frames (int) – total number of frames to collect.
frame_skip (int) – frames skipped between policy updates.
optim_steps_per_batch (int) – optimization steps per collected batch.
loss_module (LossModule) – the SAC loss module.
replay_buffer (OfflineToOnlineReplayBuffer) – the offline-to-online buffer.
- Keyword Arguments:
anneal_frames (int, optional) – frames over which
offline_fractiondecays to 0. Defaults tototal_frames; pass<= 0to keep the fraction fixed.batch_size (int, optional) – replay-buffer sampling batch size.
See
SACTrainerfor the remaining keyword arguments.Note
Experimental/prototype feature; the API may change.
- compute_loss(sub_batch: TensorDictBase, method: str | None = None) TensorDictBase | tuple[Any, ...]#
Evaluate the configured loss through the active execution boundary.
- load_from_file(file: str | Path, **kwargs) Trainer#
Loads a file and its state-dict in the trainer.
Keyword arguments are passed to the
load()function for legacy torch checkpoints and unified components explicitly saved with the torch state-dict payload format. Unified checkpoints additionally acceptstrictto control missing or incompatible components. Arguments are ignored whenCKPT_BACKEND=memmap.Note
Unified state-dict components use TensorDict storage by default and do not invoke the pickle loader. For explicit torch payloads and
CKPT_BACKEND=torchcheckpoints,weights_only=Trueis the default for safer deserialization. Passweights_only=Falseexplicitly only if the state dict contains custom objects. On torch < 2.4 the default isweights_only=Falsebecause the weights-only unpickler of those versions cannot deserialize thetorch.deviceinstances contained in TensorDict state-dicts.Note
Explicit torch payloads and
CKPT_BACKEND=torchcheckpoints usemmap=Trueby default. Passmmap=Falsefor legacy pre-zipfiletorch.savefiles or file-like objects. On Windows the default ismmap=Falsebecause a mapped checkpoint keeps the file locked, preventing deletion or re-save.Note
Unified checkpoint tensors are mapped to CPU by default. Pass an explicit
map_locationto select another device mapping.Note
After restoring an independently registered policy component, the trainer synchronizes the collector once so local policy copies and remote workers observe the restored learner weights.
- request_stop(reason: str | None = None) None#
Signal that training should stop at the next loop boundary.