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
59521d33
Unverified
Commit
59521d33
authored
Feb 21, 2021
by
DU Hao
Committed by
GitHub
Feb 21, 2021
Browse files
cream codes update (#3383)
parent
c3b60511
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
10 additions
and
6 deletions
+10
-6
examples/nas/cream/lib/utils/builder_util.py
examples/nas/cream/lib/utils/builder_util.py
+2
-0
examples/nas/cream/lib/utils/util.py
examples/nas/cream/lib/utils/util.py
+2
-0
examples/nas/cream/test.py
examples/nas/cream/test.py
+1
-1
nni/algorithms/nas/pytorch/cream/trainer.py
nni/algorithms/nas/pytorch/cream/trainer.py
+4
-4
nni/algorithms/nas/pytorch/cream/utils.py
nni/algorithms/nas/pytorch/cream/utils.py
+1
-1
No files found.
examples/nas/cream/lib/utils/builder_util.py
View file @
59521d33
import
re
import
math
import
torch.nn
as
nn
from
copy
import
deepcopy
from
timm.utils
import
*
from
timm.models.layers.activations
import
Swish
from
timm.models.layers
import
CondConv2d
,
get_condconv_initializer
...
...
examples/nas/cream/lib/utils/util.py
View file @
59521d33
...
...
@@ -4,6 +4,8 @@
# email: haodu8-c@my.cityu.edu.hk and houwen.peng@microsoft.com
import
sys
import
logging
import
torch
import
argparse
import
torch.nn
as
nn
...
...
examples/nas/cream/test.py
View file @
59521d33
...
...
@@ -83,7 +83,7 @@ def main():
'ir_r1_k5_s2_e4_c40_se0.25'
,
'ir_r1_k3_s2_e6_c80_se0.25'
,
'ir_r1_k3_s1_e6_c96_se0.25'
,
'ir_r1_k
3
_s2_e6_c192_se0.25'
]
'ir_r1_k
5
_s2_e6_c192_se0.25'
]
arch_def
=
[[
stem
[
0
]]]
+
[[
choice_block_pool
[
idx
]
for
repeat_times
in
range
(
len
(
arch_list
[
idx
+
1
]))]
for
idx
in
range
(
len
(
choice_block_pool
))]
+
[[
stem
[
1
]]]
...
...
nni/algorithms/nas/pytorch/cream/trainer.py
View file @
59521d33
...
...
@@ -230,7 +230,7 @@ class CreamSupernetTrainer(Trainer):
self
.
optimizer
.
zero_grad
()
grad_student_val
=
torch
.
autograd
.
grad
(
validation_loss
,
self
.
model
.
module
.
rand_parameters
(
self
.
random_cand
),
self
.
model
.
module
.
rand_parameters
(
self
.
current_student_arch
),
retain_graph
=
True
)
grad_teacher
=
torch
.
autograd
.
grad
(
...
...
@@ -385,7 +385,7 @@ class CreamSupernetTrainer(Trainer):
step
+
1
,
len
(
self
.
train_loader
),
meters
)
if
self
.
main_proc
and
self
.
num_epochs
==
epoch
+
1
:
for
idx
,
i
in
enumerate
(
self
.
best_children_pool
):
for
idx
,
i
in
enumerate
(
self
.
prioritized_board
):
logger
.
info
(
"No.%s %s"
,
idx
,
i
[:
4
])
def
validate_one_epoch
(
self
,
epoch
):
...
...
@@ -396,9 +396,9 @@ class CreamSupernetTrainer(Trainer):
self
.
mutator
.
reset
()
logits
=
self
.
model
(
x
)
loss
=
self
.
val_loss
(
logits
,
y
)
prec1
,
prec5
=
self
.
accuracy
(
logits
,
y
,
topk
=
(
1
,
5
))
prec1
,
prec5
=
accuracy
(
logits
,
y
,
topk
=
(
1
,
5
))
metrics
=
{
"prec1"
:
prec1
,
"prec5"
:
prec5
,
"loss"
:
loss
}
metrics
=
self
.
reduce_metrics
(
metrics
,
self
.
distributed
)
metrics
=
reduce_metrics
(
metrics
)
meters
.
update
(
metrics
)
if
self
.
log_frequency
is
not
None
and
step
%
self
.
log_frequency
==
0
:
...
...
nni/algorithms/nas/pytorch/cream/utils.py
View file @
59521d33
...
...
@@ -17,7 +17,7 @@ def accuracy(output, target, topk=(1,)):
if
target
.
ndimension
()
>
1
:
target
=
target
.
max
(
1
)[
1
]
correct
=
pred
.
eq
(
target
.
view
(
1
,
-
1
).
expand_as
(
pred
))
correct
=
pred
.
eq
(
target
.
reshape
(
1
,
-
1
).
expand_as
(
pred
))
res
=
[]
for
k
in
topk
:
...
...
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