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

Kernel init graceful failure #125

Draft
wants to merge 2 commits into
base: development
Choose a base branch
from
Draft
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
7 changes: 2 additions & 5 deletions hippynn/custom_kernels/env_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def _featsum_legacy(env, sense, pair_first, pair_second):
compiler=torch.jit.script,
)

old_kernels_compile = MessagePassingKernels(
old_kernels_compile = MessagePassingKernels.safe_init(
"_legacy_compile",
_envsum_legacy, _sensesum_legacy, _featsum_legacy,
compiler=torch.compile,
Expand All @@ -197,11 +197,8 @@ def _featsum_legacy(env, sense, pair_first, pair_second):
compiler=torch.jit.script,
)

pytorch_kernels_compile = MessagePassingKernels(
pytorch_kernels_compile = MessagePassingKernels.safe_init(
"pytorch",
envsum, sensesum, featsum,
compiler=torch.compile,
)



16 changes: 16 additions & 0 deletions hippynn/custom_kernels/registry.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

from hippynn.custom_kernels.autograd_wrapper import wrap_envops


Expand Down Expand Up @@ -37,6 +39,20 @@ def __init__(self, impl_name: str, envsum_impl, sensesum_impl, featsum_impl, wra
else:
self._registered_implementations[impl_name] = self

@classmethod
def safe_init(self, impl_name, *args, **kwargs):
"""Init self, but return None if init fails and raise a warning"""
try:
out = self.__init__(impl_name, *args, **kwargs)
except Exception as e:
w = RuntimeWarning(*e.args)
w.with_traceback(e.__traceback__)
warnings.warn(w)
out = None

self._registered_implementations[impl_name] = out
return out

@classmethod
def get_implementation(cls, impl_name):
"""
Expand Down
Loading