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
ColossalAI
Commits
dddacd2d
Unverified
Commit
dddacd2d
authored
Jan 10, 2023
by
HELSON
Committed by
GitHub
Jan 10, 2023
Browse files
[hotfix] add norm clearing for the overflow step (#2416)
parent
57b6157b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
0 deletions
+5
-0
colossalai/nn/optimizer/zero_optimizer.py
colossalai/nn/optimizer/zero_optimizer.py
+5
-0
No files found.
colossalai/nn/optimizer/zero_optimizer.py
View file @
dddacd2d
...
...
@@ -140,6 +140,10 @@ class ZeroOptimizer(ColossalaiOptimizer):
return
self
.
_found_overflow
.
item
()
>
0
def
_clear_global_norm
(
self
)
->
None
:
for
c16
in
self
.
chunk16_set
:
c16
.
l2_norm
=
None
def
_calc_global_norm
(
self
)
->
float
:
norm_sqr
:
float
=
0.0
group_to_norm
=
dict
()
...
...
@@ -201,6 +205,7 @@ class ZeroOptimizer(ColossalaiOptimizer):
self
.
optim_state
=
OptimState
.
UNSCALED
# no need to unscale grad
self
.
grad_scaler
.
update
(
found_inf
)
# update gradient scaler
self
.
_logger
.
info
(
f
'Found overflow. Skip step'
)
self
.
_clear_global_norm
()
# clear recorded norm
self
.
zero_grad
()
# reset all gradients
self
.
_update_fp16_params
()
return
...
...
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