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

[Test] Keep a tight control over warnings #951

Merged
merged 4 commits into from
Aug 6, 2024
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: 3 additions & 2 deletions tensordict/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6973,9 +6973,10 @@ def map_iter(
)
finally:
try:
pool.terminate()
finally:
pool.close()
pool.join()
except Exception:
pool.terminate()
else:
yield from self._map(
fn=fn,
Expand Down
28 changes: 17 additions & 11 deletions tensordict/tensorclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ def __subclasscheck__(self, subclass):
"is_shared",
"items",
"keys",
# "ndim",
"ndimension",
"numel",
"size",
"values",
# "ndim",
]

# Methods to be executed from tensordict, any ref to self means 'self._tensordict'
Expand Down Expand Up @@ -252,6 +253,7 @@ def __subclasscheck__(self, subclass):
"new_zeros",
"norm",
"permute",
"pin_memory",
"pow",
"pow_",
"prod",
Expand Down Expand Up @@ -1104,12 +1106,13 @@ def check_out(kwargs, result):
return wrapped_func


def _wrap_method(self, attr, func):
warnings.warn(
f"The method {func} wasn't explicitly implemented for tensorclass. "
f"This fallback will be deprecated in future releases because it is inefficient "
f"and non-compilable. Please raise an issue in tensordict repo to support this method!"
)
def _wrap_method(self, attr, func, nowarn=False):
if not nowarn:
warnings.warn(
f"The method {func} wasn't explicitly implemented for tensorclass. "
f"This fallback will be deprecated in future releases because it is inefficient "
f"and non-compilable. Please raise an issue in tensordict repo to support this method!"
)

@functools.wraps(func)
def wrapped_func(*args, **kwargs):
Expand Down Expand Up @@ -2666,14 +2669,17 @@ def __torch_function__(

def _fast_apply(self, *args, **kwargs):
kwargs["filter_empty"] = False
return _wrap_method(self, "_fast_apply", self._tensordict._fast_apply)(
*args, **kwargs
)
return _wrap_method(
self, "_fast_apply", self._tensordict._fast_apply, nowarn=True
)(*args, **kwargs)

def _multithread_rebuild(self, *args, **kwargs):
kwargs["filter_empty"] = False
return _wrap_method(
self, "_multithread_rebuild", self._tensordict._multithread_rebuild
self,
"_multithread_rebuild",
self._tensordict._multithread_rebuild,
nowarn=True,
)(*args, **kwargs)

def tolist(self):
Expand Down
Loading
Loading