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

[BugFix] Do not unlock td if it's not locked in TDParams (for compile compat) #1125

Merged
merged 1 commit into from
Dec 3, 2024
Merged
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
7 changes: 6 additions & 1 deletion tensordict/nn/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import re
import weakref
from concurrent.futures import Future, ThreadPoolExecutor
from contextlib import nullcontext
from copy import copy
from functools import wraps
from typing import Any, Callable, Dict, Iterator, List, OrderedDict, Sequence, Type
Expand Down Expand Up @@ -171,7 +172,11 @@ def new_func(_self, *args, **kwargs):
if _self.is_locked:
# if the root (TensorDictParams) is locked, we still want to raise an exception
raise RuntimeError(_LOCK_ERROR)
with _self._param_td.unlock_():
with (
_self._param_td.unlock_()
if _self._param_td.is_locked
else nullcontext()
):
meth = getattr(_self._param_td, name)
out = meth(*args, **kwargs)
_self._reset_params()
Expand Down
Loading