Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
nni
Commits
8175f280
Unverified
Commit
8175f280
authored
Feb 02, 2021
by
ZHANG Zhi
Committed by
GitHub
Feb 02, 2021
Browse files
Fix 'NoneType' Error on jupyter notebooks (#3337)
parent
1dfda7aa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
0 deletions
+14
-0
nni/retiarii/utils.py
nni/retiarii/utils.py
+14
-0
No files found.
nni/retiarii/utils.py
View file @
8175f280
...
@@ -2,6 +2,7 @@ import inspect
...
@@ -2,6 +2,7 @@ import inspect
import
warnings
import
warnings
from
collections
import
defaultdict
from
collections
import
defaultdict
from
typing
import
Any
from
typing
import
Any
from
pathlib
import
Path
def
import_
(
target
:
str
,
allow_none
:
bool
=
False
)
->
Any
:
def
import_
(
target
:
str
,
allow_none
:
bool
=
False
)
->
Any
:
...
@@ -107,7 +108,18 @@ def blackbox_module(cls):
...
@@ -107,7 +108,18 @@ def blackbox_module(cls):
Register a module. Use it as a decorator.
Register a module. Use it as a decorator.
"""
"""
frm
=
inspect
.
stack
()[
1
]
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__
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'
)
return
_blackbox_cls
(
cls
,
module_name
,
'args'
)
...
@@ -116,6 +128,8 @@ def register_trainer(cls):
...
@@ -116,6 +128,8 @@ def register_trainer(cls):
Register a trainer. Use it as a decorator.
Register a trainer. Use it as a decorator.
"""
"""
frm
=
inspect
.
stack
()[
1
]
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__
module_name
=
inspect
.
getmodule
(
frm
[
0
]).
__name__
return
_blackbox_cls
(
cls
,
module_name
,
'full'
)
return
_blackbox_cls
(
cls
,
module_name
,
'full'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment