Skip to content

Commit

Permalink
[Feature] inline hold_out_net (#2498)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmoens authored Oct 17, 2024
1 parent cbfcd63 commit 7c63e2e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions torchrl/objectives/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,18 @@ def __init__(self, network: nn.Module) -> None:

def __enter__(self) -> None:
if self.mode:
self.network.requires_grad_(False)
if is_dynamo_compiling():
self._params = TensorDict.from_module(self.network)
self._params.data.to_module(self.network)
else:
self.network.requires_grad_(False)

def __exit__(self, exc_type, exc_val, exc_tb) -> None:
if self.mode:
self.network.requires_grad_()
if is_dynamo_compiling():
self._params.to_module(self.network)
else:
self.network.requires_grad_()


class hold_out_params(_context_manager):
Expand Down

0 comments on commit 7c63e2e

Please sign in to comment.