UpdateWeights¶
- class torchrl.trainers.UpdateWeights(collector: DataCollectorBase, update_weights_interval: int, policy_weights_getter: Callable[[Any], Any] | None = None)[源代码]¶
一个收集器权重更新钩子类。
当收集器的策略权重位于与 Trainer 正在训练的策略权重不同的设备上时,必须使用此钩子。在这种情况下,这些权重必须定期同步。如果设备匹配,则此操作将不执行任何操作。
- 参数:
collector (DataCollectorBase) – 需要同步策略权重的收集器。
update_weights_interval (int) – 同步必须发生的间隔(以收集的批次数计)。
示例
>>> update_weights = UpdateWeights(trainer.collector, T) >>> trainer.register_op("post_steps", update_weights)
- register(trainer: Trainer, name: str = 'update_weights')[源代码]¶
Registers the hook in the trainer at a default location.
- 参数:
trainer (Trainer) – the trainer where the hook must be registered.
name (str) – the name of the hook.
注意
To register the hook at another location than the default, use
register_op()
.