Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] SafeModule not safely handling specs #1352

Merged
merged 12 commits into from
Jul 5, 2023
Merged
Prev Previous commit
Next Next commit
fixes
Signed-off-by: Matteo Bettini <matbet@meta.com>
  • Loading branch information
matteobettini committed Jul 4, 2023
commit d1599e1d0ef5f4e5f0862909846e4ff8ceb2f541
2 changes: 1 addition & 1 deletion test/test_tensordictmodules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,7 @@ def test_safe_specs():
in_keys=[],
)
assert original_spec == spec
assert spec[out_key] == mod[out_key]
assert original_spec[out_key] == mod.spec[out_key]


def test_actor_critic_specs():
Expand Down
5 changes: 4 additions & 1 deletion torchrl/data/tensor_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2582,7 +2582,10 @@ def __init__(self, *args, shape=None, device=None, **kwargs):
item = CompositeSpec(item, shape=shape)
if item is not None:
if self._device is None:
self._device = item.device
try:
self._device = item.device
except RuntimeError:
self._device = item._device
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this because otherwise it would throw an error when trying to clone a CompositeSpec with no device

matteobettini marked this conversation as resolved.
Show resolved Hide resolved
self[k] = item

@property
Expand Down