[Test][Topi] Avoid depending on f32 rounding behavior for crop_and_divide tests #13773
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
crop_and_resizeoperator uses floating-point arithmetic to determine whether an index is within a view-box. This can cause the use ofextrapolation_valueto depend on target-dependent rounding differences.For example, this issue was initially noticed on Vulkan during debugging of #13530, and was the result of computing
0.2*223.0 + 0.8*223.0 < 223.0. If all intermediates are cast to float32, the left-hand side evaluates to223.00002. If intermediates are kept at a higher precision, the left-hand side evaluates to223.0.The floating-point indexing can't be removed, because the operator must match the API defined by TensorFlow's operator implementation. The TensorFlow documentation for
CropAndResizedoes not specify behavior in these cases, nor do the current TensorFlow unit tests check cases of rounding error. Since the TensorFlow unit tests only use binary fractions for theboxesargument, which largely avoids the rounding issue, this commit updates the TVM unit tests to avoid depending on floating-point precision.