pytorch / pytorch/rl

[Feature Request] Support propagation of in-place modifications to masked tensordict to the parent tensordict.

Open
#298 0 comments 0 reactions 1 assignee View on GitHub

@vmoens is already working on this.

Since Jul 19, 2022.

enhancement
Dominant language
Python
Stars
3.6k
Forks
487
Avg merge
1d 1h
Merged PRs (30d)
207

Description

Motivation

For tensors, the following apply,

x = torch.randn(3,4)
mask = [True, False, True]
y = torch.randn(2,4)
x[mask] = y

torch.testing.assert_allclose(x[mask],y)

on the other hand for tensordict

    td = TensorDict({"a": torch.randn(3, 4, 2), "b": torch.randn(3, 4)}, [3, 4])

    mask = torch.tensor([True, False, True])
    x = torch.randn(2, 4, 2)
    td[mask]["a"] = x
    torch.testing.assert_allclose(td[mask]["a"], x)

returns error AssertionError: Tensor-likes are not close!

Solution

Instead of return a new Tensordict using mask-select, we can return instead a SubTensorDict.

Checklist

  • I have checked that there is no similar issue in the repo (required)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.