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
apex
Commits
942174bf
Commit
942174bf
authored
Jun 14, 2018
by
Michael Carilli
Browse files
Changing loss_scale to static_loss_scale in imagenet/main.py to be explicit
parent
2a2341c7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
5 deletions
+5
-5
examples/imagenet/main.py
examples/imagenet/main.py
+5
-5
No files found.
examples/imagenet/main.py
View file @
942174bf
...
...
@@ -61,8 +61,8 @@ parser.add_argument('--pretrained', dest='pretrained', action='store_true',
parser
.
add_argument
(
'--fp16'
,
action
=
'store_true'
,
help
=
'Run model fp16 mode.'
)
parser
.
add_argument
(
'--loss-scale'
,
type
=
float
,
default
=
1
,
help
=
'
L
oss scal
ing
, positive power of 2 values can improve fp16 convergence.'
)
parser
.
add_argument
(
'--
static-
loss-scale'
,
type
=
float
,
default
=
1
,
help
=
'
Static l
oss scal
e
, positive power of 2 values can improve fp16 convergence.'
)
parser
.
add_argument
(
'--prof'
,
dest
=
'prof'
,
action
=
'store_true'
,
help
=
'Only run 10 iterations for profiling.'
)
...
...
@@ -313,15 +313,15 @@ def train(train_loader, model, criterion, optimizer, epoch):
top1
.
update
(
to_python_float
(
prec1
),
input
.
size
(
0
))
top5
.
update
(
to_python_float
(
prec5
),
input
.
size
(
0
))
loss
=
loss
*
args
.
loss_scale
loss
=
loss
*
args
.
static_
loss_scale
# compute gradient and do SGD step
if
args
.
fp16
:
model
.
zero_grad
()
loss
.
backward
()
model_grads_to_master_grads
(
model_params
,
master_params
)
if
args
.
loss_scale
!=
1
:
if
args
.
static_
loss_scale
!=
1
:
for
param
in
master_params
:
param
.
grad
.
data
=
param
.
grad
.
data
/
args
.
loss_scale
param
.
grad
.
data
=
param
.
grad
.
data
/
args
.
static_
loss_scale
optimizer
.
step
()
master_params_to_model_params
(
model_params
,
master_params
)
else
:
...
...
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