Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the function of inspect_grad? #5

Open
KelleyYin opened this issue May 18, 2021 · 1 comment
Open

What is the function of inspect_grad? #5

KelleyYin opened this issue May 18, 2021 · 1 comment

Comments

@KelleyYin
Copy link

self.inspected_grads = OrderedDict() if getattr(args, 'inspect_grad', False) else None

Hey man,

I don't understand the function of inspect_grad. It doesn't seem to be used in your running script.
Could you please to explain it?

Thanks!

@wangqiangneu
Copy link
Owner

self.inspected_grads = OrderedDict() if getattr(args, 'inspect_grad', False) else None

Hey man,

I don't understand the function of inspect_grad. It doesn't seem to be used in your running script.
Could you please to explain it?

Thanks!

Thanks for your interest!

Yes,inspect_grad only works during training to record the gradients in the collection, e.g., the gradient of every encoder layer. Then, you can easily watch the gradient flow in Tensorboar. Please refer to:

dlcl/fairseq/trainer.py

Lines 354 to 365 in c632ee2

def _update_gnorm_detail(self, meters, model):
if not hasattr(model, 'inspected_grads'):
return
#gnorms = {}
for name, p in model.inspected_grads().items():
if p.grad is None:
continue
gn = utils.item(torch.norm(p.grad.data))
name = 'grad_%s' % name
if name not in meters:
meters[name] = AverageMeter()
meters[name].update(gn)

and

dlcl/train.py

Line 188 in c632ee2

write_tensorboard(args, stats['num_updates'], stats, is_training=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants