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
4c1183c3
Unverified
Commit
4c1183c3
authored
Jun 09, 2021
by
Yuge Zhang
Committed by
GitHub
Jun 09, 2021
Browse files
Fix hidden nodes' remove in Retiarii (#3736)
parent
159f9b34
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
1 deletion
+19
-1
nni/retiarii/nn/pytorch/mutator.py
nni/retiarii/nn/pytorch/mutator.py
+1
-1
test/ut/retiarii/test_highlevel_apis.py
test/ut/retiarii/test_highlevel_apis.py
+18
-0
No files found.
nni/retiarii/nn/pytorch/mutator.py
View file @
4c1183c3
...
...
@@ -33,7 +33,7 @@ class LayerChoiceMutator(Mutator):
model
.
get_node_by_name
(
node
.
name
).
update_operation
(
Cell
(
node
.
operation
.
cell_name
))
# remove redundant nodes
for
rm_node
in
target
.
hidden_nodes
:
for
rm_node
in
list
(
target
.
hidden_nodes
):
# remove from a list on the fly will cause issues
if
rm_node
.
name
!=
chosen_node
.
name
:
rm_node
.
remove
()
...
...
test/ut/retiarii/test_highlevel_apis.py
View file @
4c1183c3
...
...
@@ -93,6 +93,24 @@ class GraphIR(unittest.TestCase):
self
.
assertEqual
(
self
.
_get_converted_pytorch_model
(
model2
)(
torch
.
randn
(
1
,
3
,
3
,
3
)).
size
(),
torch
.
Size
([
1
,
5
,
3
,
3
]))
def
test_layer_choice_multiple
(
self
):
@
self
.
get_serializer
()
class
Net
(
nn
.
Module
):
def
__init__
(
self
):
super
().
__init__
()
self
.
module
=
nn
.
LayerChoice
([
nn
.
Conv2d
(
3
,
i
,
kernel_size
=
1
)
for
i
in
range
(
1
,
11
)])
def
forward
(
self
,
x
):
return
self
.
module
(
x
)
model
,
mutators
=
self
.
_get_model_with_mutators
(
Net
())
self
.
assertEqual
(
len
(
mutators
),
1
)
mutator
=
mutators
[
0
].
bind_sampler
(
EnumerateSampler
())
for
i
in
range
(
1
,
11
):
model_new
=
mutator
.
apply
(
model
)
self
.
assertEqual
(
self
.
_get_converted_pytorch_model
(
model_new
)(
torch
.
randn
(
1
,
3
,
3
,
3
)).
size
(),
torch
.
Size
([
1
,
i
,
3
,
3
]))
def
test_input_choice
(
self
):
@
self
.
get_serializer
()
class
Net
(
nn
.
Module
):
...
...
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