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 30, 2024
commit 7c3681d9eb818ea153ce24b32b9736db486617b1
2 changes: 0 additions & 2 deletions torchrl/data/tensor_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1805,8 +1805,6 @@ def __init__(
dtype=dtype,
domain=domain,
)
if self.shape == torch.Size([0, 0]):
raise RuntimeError

def __eq__(self, other):
return (
Expand Down
10 changes: 5 additions & 5 deletions torchrl/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def consolidate_spec(
recurse_through_entries: bool = True,
recurse_through_stack: bool = True,
):
"""Given a TensorSpec, removes exclusive keys by adding -1 shaped specs.
"""Given a TensorSpec, removes exclusive keys by adding 0 shaped specs.

Args:
spec (CompositeSpec): the spec to be consolidated.
Expand Down Expand Up @@ -161,7 +161,7 @@ def _empty_like_spec(specs: List[TensorSpec], shape):
else:
# the exclusive key has values which are TensorSpecs ->
# if the shapes of the values are all the same, we create a TensorSpec with leading shape `shape` and following dims 0 (having the same ndims as the values)
# if the shapes of the values differ, we create a TensorSpec with -1 size in the differing dims
# if the shapes of the values differ, we create a TensorSpec with 0 size in the differing dims
spec_shape = list(spec.shape)

for dim_index in range(len(spec_shape)):
Expand All @@ -171,11 +171,11 @@ def _empty_like_spec(specs: List[TensorSpec], shape):
hetero_dim = True
break
if hetero_dim:
spec_shape[dim_index] = -1
spec_shape[dim_index] = 0

if -1 not in spec_shape: # the values have all same shape
if 0 not in spec_shape: # the values have all same shape
spec_shape = [
dim if i < len(shape) else -1 for i, dim in enumerate(spec_shape)
dim if i < len(shape) else 0 for i, dim in enumerate(spec_shape)
]

spec = spec[(0,) * len(spec.shape)]
Expand Down
Loading