Skip to content

Add grad_norm metrics #1143

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Add grad_norm metrics #1143

wants to merge 2 commits into from

Conversation

yzhangcs
Copy link
Contributor

What does this PR do?

This PR adds the grad_norm metric to the logging metrics.

Why this PR is important

Monitoring the gradient norm is crucial for detecting training stability and getting some optimization insights.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Apr 25, 2025
Copy link
Contributor

@tianyu-l tianyu-l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had a comment
also pls fix linting

@@ -394,7 +397,7 @@ def log(
color = self.color
logger.info(
f"{color.red}step: {step:2} "
f"{color.green}loss: {global_avg_loss:7.4f} "
f"{color.green}loss: {global_avg_loss:7.4f} gnorm: {grad_norm:.2f} "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

I agree this metric would be helpful. Do you think it has to be in the terminal print, instead of staying in TB/W&B only for now?
If so, could you invent a new color in the Color class -- o/w it seems visually harder to recognize loss. Also nit: two spaces before after each column.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants