快捷方式

make_composite_from_td

torchrl.envs.utils.make_composite_from_td(data, unsqueeze_null_shapes: bool = True)[原始碼]

從 tensordict 建立一個 Composite 例項,假定所有值都是無界的。

引數:
  • data (tensordict.TensorDict) – 將對映到 Composite 的 tensordict。

  • unsqueeze_null_shapes (bool, optional) – 如果為 True,每個空形狀將被 unsqueeze 為 (1,)。預設為 True

示例

>>> from tensordict import TensorDict
>>> data = TensorDict({
...     "obs": torch.randn(3),
...     "action": torch.zeros(2, dtype=torch.int),
...     "next": {"obs": torch.randn(3), "reward": torch.randn(1)}
... }, [])
>>> spec = make_composite_from_td(data)
>>> print(spec)
Composite(
    obs: UnboundedContinuous(
         shape=torch.Size([3]), space=None, device=cpu, dtype=torch.float32, domain=continuous),
    action: UnboundedContinuous(
         shape=torch.Size([2]), space=None, device=cpu, dtype=torch.int32, domain=continuous),
    next: Composite(
        obs: UnboundedContinuous(
             shape=torch.Size([3]), space=None, device=cpu, dtype=torch.float32, domain=continuous),
        reward: UnboundedContinuous(
             shape=torch.Size([1]), space=ContinuousBox(low=Tensor(shape=torch.Size([]), device=cpu, dtype=torch.float32, contiguous=True), high=Tensor(shape=torch.Size([]), device=cpu, dtype=torch.float32, contiguous=True)), device=cpu, dtype=torch.float32, domain=continuous), device=cpu, shape=torch.Size([])), device=cpu, shape=torch.Size([]))
>>> assert (spec.zero() == data.zero_()).all()

文件

訪問全面的 PyTorch 開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲取問題解答

檢視資源