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
MMCV
Commits
41ca64cb
Unverified
Commit
41ca64cb
authored
Jun 08, 2020
by
Wang Xinjiang
Committed by
GitHub
Jun 08, 2020
Browse files
add gradient norm to logger (#326)
parent
e7a446ae
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
2 deletions
+6
-2
mmcv/runner/hooks/optimizer.py
mmcv/runner/hooks/optimizer.py
+6
-2
No files found.
mmcv/runner/hooks/optimizer.py
View file @
41ca64cb
...
@@ -14,11 +14,15 @@ class OptimizerHook(Hook):
...
@@ -14,11 +14,15 @@ class OptimizerHook(Hook):
params
=
list
(
params
=
list
(
filter
(
lambda
p
:
p
.
requires_grad
and
p
.
grad
is
not
None
,
params
))
filter
(
lambda
p
:
p
.
requires_grad
and
p
.
grad
is
not
None
,
params
))
if
len
(
params
)
>
0
:
if
len
(
params
)
>
0
:
clip_grad
.
clip_grad_norm_
(
params
,
**
self
.
grad_clip
)
return
clip_grad
.
clip_grad_norm_
(
params
,
**
self
.
grad_clip
)
def
after_train_iter
(
self
,
runner
):
def
after_train_iter
(
self
,
runner
):
runner
.
optimizer
.
zero_grad
()
runner
.
optimizer
.
zero_grad
()
runner
.
outputs
[
'loss'
].
backward
()
runner
.
outputs
[
'loss'
].
backward
()
if
self
.
grad_clip
is
not
None
:
if
self
.
grad_clip
is
not
None
:
self
.
clip_grads
(
runner
.
model
.
parameters
())
grad_norm
=
self
.
clip_grads
(
runner
.
model
.
parameters
())
if
grad_norm
is
not
None
:
# Add grad norm to the logger
runner
.
log_buffer
.
update
({
'grad_norm'
:
grad_norm
},
runner
.
outputs
[
'num_samples'
])
runner
.
optimizer
.
step
()
runner
.
optimizer
.
step
()
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