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] Fix info reading with async gym #2150

Merged
merged 6 commits into from
May 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
amend
  • Loading branch information
vmoens committed May 3, 2024
commit d0f6ad3f93d99b4f09ab1da668bb6b66479dcf1d
7 changes: 7 additions & 0 deletions torchrl/envs/gym_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def __call__(
if self.ignore_private:
keys = [key for key in keys if not key.startswith("_")]
self.keys = keys
# create an info_spec only if there is none
info_spec = None if self.info_spec is not None else CompositeSpec()
for key in keys:
if key in info_dict:
Expand All @@ -133,6 +134,12 @@ def __call__(
info_spec[key] = UnboundedContinuousTensorSpec(
val.shape, device=val.device, dtype=val.dtype
)
elif self.info_spec is not None:
# Fill missing with 0s
tensordict.set(key, self.info_spec[key].zero())
else:
raise KeyError(f"The key {key} could not be found or inferred.")
# set the info spec if there wasn't any - this should occur only once in this class
if info_spec is not None:
if tensordict.device is not None:
info_spec = info_spec.to(tensordict.device)
Expand Down
Loading