Unverified Commit 20d00ab1 authored by Tomasz Grel's avatar Tomasz Grel Committed by GitHub
Browse files

Do not unscale the gradients if loss scale equal to 1 (#748)

* Do not unscale the gradients if loss scale equal to 1

* Disable unscaling loss scale == 1 only for static scaling
parent 5633f6db
...@@ -92,6 +92,14 @@ def lazy_init_with_master_weights(self): ...@@ -92,6 +92,14 @@ def lazy_init_with_master_weights(self):
def post_backward_models_are_masters(scaler, params, stashed_grads, scale_override=None): def post_backward_models_are_masters(scaler, params, stashed_grads, scale_override=None):
grads_have_scale, stashed_have_scale, out_scale = scaler.loss_scale(), 1.0, 1.0 grads_have_scale, stashed_have_scale, out_scale = scaler.loss_scale(), 1.0, 1.0
# not much to do if scale == 1.0 and static scaling
if scaler.loss_scale() == 1.0 and not scaler.dynamic:
# Clear the stash.
for i in range(len(stashed_grads)):
stashed_grads[i] = None
return
if scale_override is not None: if scale_override is not None:
grads_have_scale, stashed_have_scale, out_scale = scale_override grads_have_scale, stashed_have_scale, out_scale = scale_override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment