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] TensorDictPrimer updates spec instead of overwriting #2332

Merged
merged 8 commits into from
Jul 31, 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
Next Next commit
amend
  • Loading branch information
matteobettini committed Jul 29, 2024
commit 9a4718fc353bdbc41a34d9a35f9ca38fc895ea7d
16 changes: 7 additions & 9 deletions torchrl/envs/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4638,15 +4638,13 @@ def transform_observation_spec(
raise ValueError(
f"observation_spec was expected to be of type CompositeSpec. Got {type(observation_spec)} instead."
)
for key, spec in self.primers.items():
if spec.shape[: len(observation_spec.shape)] != observation_spec.shape:
expanded_spec = self._expand_shape(spec)
spec = expanded_spec
try:
device = observation_spec.device
except RuntimeError:
device = self.device
observation_spec[key] = self.primers[key] = spec.to(device)
try:
device = observation_spec.device
matteobettini marked this conversation as resolved.
Show resolved Hide resolved
except RuntimeError:
device = self.device
if self.primers.shape[: len(observation_spec.shape)] != observation_spec.shape:
self.primers = self._expand_shape(self.primers)
observation_spec.update(self.primers.to(device))
return observation_spec

def transform_input_spec(self, input_spec: TensorSpec) -> TensorSpec:
Expand Down