Skip to content

Commit

Permalink
[Feature] inline hold_out_net
Browse files Browse the repository at this point in the history
ghstack-source-id: c315202c8af55f0852195fe488ae855966386c4c
Pull Request resolved: #2499
  • Loading branch information
vmoens committed Oct 17, 2024
1 parent d894358 commit 7b70af1
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 7b70af1

Please sign in to comment.