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] SAC compatibility with composite distributions. #2447

Merged
merged 8 commits into from
Oct 11, 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
Next Next commit
test fixes
  • Loading branch information
albertbou92 authored and vmoens committed Oct 10, 2024
commit cdb91ec339f64e5485c19cd64341ded0c5fa501e
5 changes: 2 additions & 3 deletions torchrl/objectives/sac.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def new_func(self, *args, **kwargs):


def compute_log_prob(action_dist, action_or_tensordict, tensor_key):
"""Compute the log probability of an action given a distribution."""
if isinstance(action_or_tensordict, torch.Tensor):
log_p = action_dist.log_prob(action_or_tensordict)
else:
Expand Down Expand Up @@ -464,9 +465,7 @@ def target_entropy(self):
else:
action_container_shape = action_spec.shape
target_entropy = -float(
action_spec[self.tensor_keys.action]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too I had to change. Shouldn't action spec already have the correct shape?

.shape[len(action_container_shape) :]
.numel()
action_spec.shape[len(action_container_shape) :].numel()
)
delattr(self, "_target_entropy")
self.register_buffer(
Expand Down