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

[Feature] Dynamic specs #2143

Merged
merged 27 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
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
Next Next commit
amend
  • Loading branch information
vmoens committed May 29, 2024
commit 3ce16da8d2e64fc59eec4cdd8d607d396a0c7d9f
1 change: 0 additions & 1 deletion torchrl/collectors/collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
TensorDict,
TensorDictBase,
TensorDictParams,
unravel_key,
)
from tensordict.nn import TensorDictModule
from torch import multiprocessing as mp
Expand Down
9 changes: 8 additions & 1 deletion torchrl/envs/libs/gym.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ def _gym_to_torchrl_spec_transform(
return BinaryDiscreteTensorSpec(
spec.n, device=device, dtype=numpy_to_torch_dtype_dict[spec.dtype]
)
elif isinstance(spec, gym_spaces.Sequence):
# a spec type cannot be a string, so we're sure that versions of gym that don't have Sequence will just skip through this
elif isinstance(spec, getattr(gym_spaces, "Sequence", str)):
if not spec.stack:
raise ValueError(
"Sequence spaces must have the stack argument set to ``True``."
Expand Down Expand Up @@ -1098,6 +1099,12 @@ def _make_done_spec(self): # noqa: F811

@implement_for("gym", None, "0.26")
def _reset_output_transform(self, reset_data): # noqa: F811
if (
isinstance(reset_data, tuple)
and len(reset_data) == 2
and isinstance(reset_data[1], dict)
):
return reset_data
return reset_data, None

@implement_for("gym", "0.26", None)
Expand Down
Loading