Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Fix 'NoneType' Error on jupyter notebooks (#3337)
Browse files Browse the repository at this point in the history
  • Loading branch information
tczhangzhi authored Feb 2, 2021
1 parent 1dfda7a commit 8175f28
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions nni/retiarii/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import warnings
from collections import defaultdict
from typing import Any
from pathlib import Path


def import_(target: str, allow_none: bool = False) -> Any:
Expand Down Expand Up @@ -107,7 +108,18 @@ def blackbox_module(cls):
Register a module. Use it as a decorator.
"""
frm = inspect.stack()[1]

assert (inspect.getmodule(frm[0]) is not None), ('unable to locate the definition of the given black box module, '
'please define it explicitly in a .py file.')
module_name = inspect.getmodule(frm[0]).__name__

if module_name == '__main__':
main_file_path = Path(inspect.getsourcefile(frm[0]))
if main_file_path.parents[0] != Path('.'):
raise RuntimeError(f'you are using "{main_file_path}" to launch your experiment, '
f'please launch the experiment under the directory where "{main_file_path.name}" is located.')
module_name = main_file_path.stem

return _blackbox_cls(cls, module_name, 'args')


Expand All @@ -116,6 +128,8 @@ def register_trainer(cls):
Register a trainer. Use it as a decorator.
"""
frm = inspect.stack()[1]
assert (inspect.getmodule(frm[0]) is not None), ('unable to locate the definition of the given trainer, '
'please define it explicitly in a .py file.')
module_name = inspect.getmodule(frm[0]).__name__
return _blackbox_cls(cls, module_name, 'full')

Expand Down

0 comments on commit 8175f28

Please sign in to comment.