Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions torchrl/data/tensor_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,11 @@ def _project(self, val: torch.Tensor) -> torch.Tensor:
maximum = maximum.expand_as(val)
val[val < minimum] = minimum[val < minimum]
val[val > maximum] = maximum[val > maximum]
except RuntimeError:
minimum = minimum.expand_as(val)
maximum = maximum.expand_as(val)
val[val < minimum] = minimum[val < minimum]
val[val > maximum] = maximum[val > maximum]
return val

def is_in(self, val: torch.Tensor) -> bool:
Expand Down
8 changes: 8 additions & 0 deletions torchrl/objectives/value/advantages.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ class GAE(nn.Module):
gradient_mode (bool): if True, gradients are propagated throught the computation of the value function.
Default is `False`.

GAE will return an :obj:`"advantage"` entry containing the advange value. It will also
return a :obj:`"value_target"` entry with the return value that is to be used
to train the value network. Finally, if :obj:`gradient_mode` is :obj:`True`,
an additional and differentiable :obj:`"value_error"` entry will be returned,
which simple represents the difference between the return and the value network
output (i.e. an additional distance loss should be applied to that signed value).

"""

def __init__(
Expand Down Expand Up @@ -336,6 +343,7 @@ def forward(
)

tensordict.set("advantage", adv.detach())
tensordict.set("value_target", value_target)
if self.gradient_mode:
tensordict.set("value_error", value_target - value)

Expand Down