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

Update tolerance of provider tests to fix flaky tests #19792

Merged
merged 6 commits into from
Mar 7, 2024

Conversation

tianleiwu
Copy link
Contributor

@tianleiwu tianleiwu commented Mar 6, 2024

Description

Check float/double/float16/bfloat16 tensors are close like numpy.isclose.

absolute(a - b) <= (atol + rtol * absolute(b))

The default tolerance thresholds:

  • float: atol=1e-6 and rtol=1e-5
  • float: atol=1e-5 and rtol=1e-4
  • float16: atol=0.0025 and rtol=0.001
  • bfloat16: atol=0.02 and rtol=0.01

Motivation and Context

Current pipeline has frequent failure due to using only relative tolerance in #19608:

[ RUN ] MatMulIntegerToFloat.NoZeroPoint_NoBias_test_U8S8
1: C:\a_work\1\s\onnxruntime\test\providers\checkers.cc(272): error: The difference between cur_expected[i] and cur_actual[i] is 1.3113021850585938e-06, which exceeds *(params.relative_error) * std::abs(cur_expected[i]), where
1: cur_expected[i] evaluates to -1.3113021850585938e-06,
1: cur_actual[i] evaluates to 0, and
1: *(params.relative_error) * std::abs(cur_expected[i]) evaluates to 2.6226043559063328e-08.

It is not reasonable to use relative tolerance for a small value very close to 0. Combining relative tolerance with a positive absolute tolerance could avoid such issue.

@tianleiwu tianleiwu force-pushed the tlwu/test_rel_error branch from 34aebcd to 976faf4 Compare March 6, 2024 17:31
@tianleiwu tianleiwu force-pushed the tlwu/test_rel_error branch from 541de1e to d92f250 Compare March 6, 2024 21:27
@tianleiwu tianleiwu merged commit bff4f8b into main Mar 7, 2024
95 checks passed
@tianleiwu tianleiwu deleted the tlwu/test_rel_error branch March 7, 2024 01:47
zz002 pushed a commit to zz002/onnxruntime that referenced this pull request Mar 7, 2024
### Description

Check float/double/float16/bfloat16 tensors are close like
[numpy.isclose](https://numpy.org/doc/stable/reference/generated/numpy.isclose.html).
```
absolute(a - b) <= (atol + rtol * absolute(b))
```

The default tolerance thresholds:
- float: atol=1e-5 and rtol=1e-4
- float16: atol=0.0025 and rtol=0.001
- bfloat16: atol=0.02 and rtol=0.01

### Motivation and Context

Current pipeline has frequent failure due to using only relative
tolerance in microsoft#19608:

[ RUN      ] MatMulIntegerToFloat.NoZeroPoint_NoBias_test_U8S8
1: C:\a\_work\1\s\onnxruntime\test\providers\checkers.cc(272): error:
The difference between cur_expected[i] and cur_actual[i] is
1.3113021850585938e-06, which exceeds *(params.relative_error) *
std::abs(cur_expected[i]), where
1: cur_expected[i] evaluates to -1.3113021850585938e-06,
1: cur_actual[i] evaluates to 0, and
1: *(params.relative_error) * std::abs(cur_expected[i]) evaluates to
2.6226043559063328e-08.

It is not reasonable to use relative tolerance for a small value very
close to 0. Combining relative tolerance with a positive absolute
tolerance could avoid such issue.
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.

2 participants