Unverified Commit 9895a1af authored by lizz's avatar lizz Committed by GitHub
Browse files

Check empty before clip grads (#219)


Signed-off-by: default avatarlizz <lizz@sensetime.com>
parent cd873f9c
...@@ -11,8 +11,10 @@ class OptimizerHook(Hook): ...@@ -11,8 +11,10 @@ class OptimizerHook(Hook):
self.grad_clip = grad_clip self.grad_clip = grad_clip
def clip_grads(self, params): def clip_grads(self, params):
clip_grad.clip_grad_norm_( params = list(
filter(lambda p: p.requires_grad, params), **self.grad_clip) filter(lambda p: p.requires_grad and p.grad is not None, params))
if len(params) > 0:
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()
......
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