快捷方式

BatchSubSampler

class torchrl.trainers.BatchSubSampler(batch_size: int, sub_traj_len: int = 0, min_sub_traj_len: int = 0)[源代码]

用于在线 RL sota-implementations 的数据子采样器。

此类对刚从环境中收集到的整批数据的一部分进行子采样。

参数:
  • batch_size (int) – 要收集的子批次大小。提供的批次大小必须等于输出 tensordict 中的项目总数,这将具有大小 [batch_size // sub_traj_len, sub_traj_len]。

  • sub_traj_len (int, optional) – 在线环境中子采样轨迹的长度。默认为 -1(即,取轨迹的完整长度)

  • min_sub_traj_len (int, optional) – sub_traj_len 的最小值,以防批次中的某些元素包含少量步骤。默认为 -1(即,无最小值)

示例

>>> td = TensorDict(
...     {
...         key1: torch.stack([torch.arange(0, 10), torch.arange(10, 20)], 0),
...         key2: torch.stack([torch.arange(0, 10), torch.arange(10, 20)], 0),
...     },
...     [2, 10],
... )
>>> trainer.register_op(
...     "process_optim_batch",
...     BatchSubSampler(batch_size=batch_size, sub_traj_len=sub_traj_len),
... )
>>> td_out = trainer._process_optim_batch_hook(td)
>>> assert td_out.shape == torch.Size([batch_size // sub_traj_len, sub_traj_len])
register(trainer: Trainer, name: str = 'batch_subsampler')[源代码]

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().

文档

访问全面的 PyTorch 开发者文档

查看文档

教程

为初学者和高级开发者提供深入的教程

查看教程

资源

查找开发资源并让您的问题得到解答

查看资源