pytorch
af1a7728 - Disable overloading of std::max & std::min for inputs of distinct types (#55638)

Commit
3 years ago
Disable overloading of std::max & std::min for inputs of distinct types (#55638) Summary: Fixes https://github.com/pytorch/pytorch/issues/55613 ### Problem By default, `std::max` and `std::min` only operate on inputs of the same type. In [`c10/util/BFloat16-math.h`](https://github.com/pytorch/pytorch/blob/master/c10/util/BFloat16-math.h), `std::max` & `std::min` have been overloaded: https://github.com/pytorch/pytorch/blob/305abde976d232494c6b5252111ce15523511ffe/c10/util/BFloat16-math.h#L32-L33 ezyang [observed](https://github.com/pytorch/pytorch/pull/55586#issuecomment-815862373) & [illustrated](https://godbolt.org/z/bjTjPMMco) that calls to `std::max` & `std::min` for distinct input types (eg. `std::max(int, float)`) are being handled via `BFloat16`'s aforementioned overloads via implicit conversion to `BFloat16`. (I haven't looked into why yet). ### Solution implemented 1. Disabled overloading of `std::max` & `std::min` for inputs of distinct types by removing these overloads for `BFloat16`. 2. Instead, `<` and `>` operators are now being overloaded for `BFloat16` now (for comparison with another `BFloat16`), since `std::max` and `std::min` use these operators. 3. Calls to `std::max` and `std::min` with inputs of distinct types are only present at 3 places in the codebase, where they can either be handled by a `static_cast`, or by changing the type: a. [`aten/src/ATen/native/quantized/fake_quant_per_tensor_affine.cpp`](https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/quantized/fake_quant_per_tensor_affine.cpp#L111) b. [`aten/src/ATen/native/cpu/BinaryOpsKernel.cpp`](https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/cpu/BinaryOpsKernel.cpp#L74) c. [`aten/src/ATen/native/quantized/cpu/kernels/QuantizedOpKernels.cpp`](https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/quantized/cpu/kernels/QuantizedOpKernels.cpp#L2998-L2999) Pull Request resolved: https://github.com/pytorch/pytorch/pull/55638 Reviewed By: albanD Differential Revision: D27669702 Pulled By: ezyang fbshipit-source-id: 790a67b76f86c25fad2c7ed0345b7f35ab5eca68
Parents
Loading