-
Notifications
You must be signed in to change notification settings - Fork 560
Description
🚀 Feature
In response to pytorch/pytorch#62396, we opened pytorch/pytorch#97869 and pytorch/pytorch#97868 in the PyTorch repo
Motivation
Upsample with mode nearest in Pytorch has a bug where the output size is rounded incorrectly using floor() rather than round() which makes it inconsistent with other frameworks like openCV, tensorflow etc. We are fixing this by adding a kwarg per the approach in pytorch/pytorch#64983 (comment). This is breaking xla CI, we need to fix this on XLA side as well in order to land the PR
Pitch
The specific code is here:
xla/torch_xla/csrc/aten_xla_type.cpp
Lines 177 to 188 in 7d9d43e
| std::vector<int64_t> GetOutputSizeWithScale( | |
| absl::Span<const int64_t> input_size, const c10::optional<double> scales_h, | |
| const c10::optional<double> scales_w, | |
| const std::vector<int64_t>& output_size) { | |
| XLA_CHECK(scales_h); | |
| XLA_CHECK(scales_w); | |
| // Calculate the output size from input_shape and scale_factors | |
| XLA_CHECK_EQ(input_size.size(), 4); | |
| int64_t output_h = input_size[2] * (*scales_h); | |
| int64_t output_w = input_size[3] * (*scales_w); | |
| return {output_h, output_w}; | |
| } |
int64_t output_h = 0.5 + input_size[2] * (*scales_h);or
int64_t output_h = input_size[2] * (*scales_h);in the UpsampleNearest variants depending on new flag
round_with_scale_factor
However, this flag can't be exposed in, for example, upsample_bilinear2d function:
xla/torch_xla/csrc/aten_xla_type.cpp
Line 3112 in 7d9d43e
| at::Tensor XLANativeFunctions::upsample_bilinear2d( |