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 4a502505dcd411a65373b0decc7e047a4934edd0
4 changes: 3 additions & 1 deletion torchrl/data/tensor_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4918,5 +4918,7 @@ def _minmax_dtype(dtype):
return info.min, info.max


def _remove_neg_shapes(shape):
def _remove_neg_shapes(*shape):
if len(shape) == 1 and not isinstance(shape[0], int):
return _remove_neg_shapes(*shape[0])
return torch.Size([int(d) if d >= 0 else 1 for d in shape])
4 changes: 2 additions & 2 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 0 shaped specs.
"""Given a TensorSpec, removes exclusive keys by adding -1 shaped specs.

Args:
spec (CompositeSpec): the spec to be consolidated.
Expand Down Expand Up @@ -173,7 +173,7 @@ def _empty_like_spec(specs: List[TensorSpec], shape):
if hetero_dim:
spec_shape[dim_index] = -1

if 0 not in spec_shape: # the values have all same shape
if -1 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)
]
Expand Down
Loading