Skip to content

Fix grad_norm unserializable tensor log failure#29212

Merged
amyeroberts merged 2 commits into
huggingface:mainfrom
svenschultze:main
Mar 4, 2024
Merged

Fix grad_norm unserializable tensor log failure#29212
amyeroberts merged 2 commits into
huggingface:mainfrom
svenschultze:main

Conversation

@svenschultze

Copy link
Copy Markdown

What does this PR do?

Fixes Issue #29207

@muellerzr
@pacman100

@svenschultze
svenschultze marked this pull request as draft February 22, 2024 13:49
@svenschultze

svenschultze commented Feb 22, 2024

Copy link
Copy Markdown
Author

The issue seems to be that deepspeeds get_global_grad_norm() unexpectedly returns a tensor instead of a float.
This fixes that issue. For Non-Deepspeed training, we already call item(), so there is no fix required.

@svenschultze
svenschultze marked this pull request as ready for review February 22, 2024 14:04

@qianhang1994 qianhang1994 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

met same error too, here is the variable print log
json_string = json.dumps(dataclasses.asdict(self), indent=2, sort_keys=True) + "\n"
"print(dataclasses.asdict(self))" results:

{...
'log_history': [
{'loss': 24.6648, 'grad_norm': tensor(1091.0826), 'learning_rate': 1e-05, 'epoch': 0.04, 'step': 5},
{'loss': 8.7945, 'grad_norm': tensor(248.9097), 'learning_rate': 1e-05, 'epoch': 0.08, 'step': 10}
], ...}

show grad_norm is a tensor

@muellerzr muellerzr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, looks good to me!

@muellerzr

Copy link
Copy Markdown
Contributor

Actually, this seems to be in direct conflict with #29158

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@amyeroberts

Copy link
Copy Markdown
Contributor

@muellerzr In this case, which PR should stand?

@winglian

winglian commented Mar 1, 2024

Copy link
Copy Markdown
Collaborator

Actually, this seems to be in direct conflict with #29158

That other PR seems to affect the else clause where, whereas this is in the if part of the clause, so it might be okay

@muellerzr

Copy link
Copy Markdown
Contributor

This one should stand and be okay, the other PR will need to change, so this is fine to me

@amyeroberts amyeroberts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for fixing!

@amyeroberts
amyeroberts merged commit 7941769 into huggingface:main Mar 4, 2024
@muellerzr muellerzr mentioned this pull request Mar 4, 2024
5 tasks
@wzzzzzy wzzzzzy mentioned this pull request Mar 6, 2024
1 task
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

Successfully merging this pull request may close these issues.

6 participants