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
0a57438b
Unverified
Commit
0a57438b
authored
Jul 13, 2022
by
Yuge Zhang
Committed by
GitHub
Jul 13, 2022
Browse files
Fix unintended modification of trace symbol after dump (#4993)
parent
baf60758
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
0 deletions
+18
-0
nni/common/serializer.py
nni/common/serializer.py
+1
-0
test/ut/sdk/test_serializer.py
test/ut/sdk/test_serializer.py
+17
-0
No files found.
nni/common/serializer.py
View file @
0a57438b
...
@@ -538,6 +538,7 @@ def _trace_cls(base, kw_only, call_super=True, inheritable=False):
...
@@ -538,6 +538,7 @@ def _trace_cls(base, kw_only, call_super=True, inheritable=False):
# Pickle can't handle type objects.
# Pickle can't handle type objects.
if
'_nni_symbol'
in
obj_
:
if
'_nni_symbol'
in
obj_
:
obj_
=
dict
(
obj_
)
# copy the object to keep the original symbol unchanged
obj_
[
'_nni_symbol'
]
=
cloudpickle
.
dumps
(
obj_
[
'_nni_symbol'
])
obj_
[
'_nni_symbol'
]
=
cloudpickle
.
dumps
(
obj_
[
'_nni_symbol'
])
return
_pickling_object
,
(
type_
,
kw_only
,
obj_
)
return
_pickling_object
,
(
type_
,
kw_only
,
obj_
)
...
...
test/ut/sdk/test_serializer.py
View file @
0a57438b
...
@@ -371,6 +371,23 @@ def test_subclass():
...
@@ -371,6 +371,23 @@ def test_subclass():
assert
isinstance
(
obj
,
Super
)
assert
isinstance
(
obj
,
Super
)
class
ConsistencyTest1
:
pass
class
ConsistencyTest2
:
def
__init__
(
self
):
self
.
test
=
nni
.
trace
(
ConsistencyTest1
)()
def
test_dump_consistency
():
test2
=
ConsistencyTest2
()
symbol1
=
test2
.
test
.
trace_symbol
pickle
.
dumps
(
test2
)
symbol2
=
test2
.
test
.
trace_symbol
assert
symbol1
==
symbol2
def
test_get
():
def
test_get
():
@
nni
.
trace
@
nni
.
trace
class
Foo
:
class
Foo
:
...
...
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