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

Warn instead of raising exceptions in inf-check #1852

Merged
merged 2 commits into from
Dec 31, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions icefall/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def register_inf_check_hooks(model: nn.Module) -> None:
def forward_hook(_module, _input, _output, _name=name):
if isinstance(_output, Tensor):
if not torch.isfinite(_output.to(torch.float32).sum()):
raise ValueError(
f"The sum of {_name}.output is not finite: {_output}"
logging.warning(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will the training continue with inf loss and inf grad?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, like the backward code, it will just warn instead of printing the tensor and raising an exception.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In that case, will it propagate the inf grad to model parameters and result in inf parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is only applied with the inf-check option tuned on, i.e., for finding where the infinites are coming from. So it wouldn't affect normal model training.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. Thanks!

f"The sum of {_name}.output is not finite"
)
elif isinstance(_output, tuple):
for i, o in enumerate(_output):
Expand All @@ -50,8 +50,8 @@ def forward_hook(_module, _input, _output, _name=name):
if not isinstance(o, Tensor):
continue
if not torch.isfinite(o.to(torch.float32).sum()):
raise ValueError(
f"The sum of {_name}.output[{i}] is not finite: {_output}"
logging.warning(
f"The sum of {_name}.output[{i}] is not finite"
)

# default param _name is a way to capture the current value of the variable "name".
Expand Down
Loading