Skip to content

Commit

Permalink
[BugFix] Fix deterministic fallback when the dist has no support (#830)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmoens authored Jun 24, 2024
1 parent aa2d0bc commit 8522bb6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tensordict/nn/probabilistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,15 @@ def _dist_sample(
try:
return dist.deterministic_sample
except AttributeError:
fallback = (
"mean" if isinstance(dist.support, D.constraints._Real) else "mode"
)
try:
support = dist.support
fallback = (
"mean" if isinstance(support, D.constraints._Real) else "mode"
)
except NotImplementedError:
# Some custom dists don't have a support
# We arbitrarily fall onto 'mean' in these cases
fallback = "mean"
try:
if fallback == "mean":
return dist.mean
Expand Down

0 comments on commit 8522bb6

Please sign in to comment.