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

[Training] Fix Overflow Handling in Cast Infer for ORTModule. #21202

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

Conversation

AdamLouly
Copy link
Contributor

Description

Infer cast function in symbolic shape infer cannot handle inf values and returns this error:

  File "/usr/local/lib/python3.10/dist-packages/onnxruntime/tools/symbolic_shape_infer.py", line 607, in int_or_float
    return int(value)
OverflowError: cannot convert float infinity to integer

added a fix to handle NaN and inf values.

@AdamLouly AdamLouly requested review from pengwa and wschin June 28, 2024 08:05
@pengwa pengwa added the training issues related to ONNX Runtime training; typically submitted using template label Jul 1, 2024
# Handle NaN and inf values explicitly
if np.isinf(value):
# Use the maximum float value as the replacement
return int(np.finfo(np.float32).max)
Copy link
Member

Choose a reason for hiding this comment

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

Why using float32? If this constant is used somewhere else, why not using a named constant?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
training issues related to ONNX Runtime training; typically submitted using template
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants