Repository: pytorch
Issue: nn.interpolate scale_factor floors output size with floating 
Labels: module: nn,triaged,module: edge cases

## Issue description
nn.interpolate(data, scale_factor) is affected by floating point error

for instance if input image is shape (1,3,88,88) and scale_factor=120/88, resulting image is  (1,3,119,119) 
This probably results from the floating point error in 88*(120/88) = 119.99999999999999

This is not a problem when using the `size` argument. 

### Possible desired solutions
* introduce an `atol` kwarg
* introduce float->int behaviour options, 'round' 'floor' 'ceil'

This can be fixed by bypassing the scale->size calculation.

## Code example

```python
from torch.nn.functional import interpolate
def test_interpolate():
    size = 120
    scale_modes = ['bicubic', 'bilinear', 'nearest']
    devices = ['cpu', 'cuda']
    dtypes = [torch.float32, torch.float16, torch.float64]
    for mode in scale_modes:
        for device in devices:
            for dtype in dtypes:
                for _s in range(size//2 -1, size*2 + 1):
                    out = torch.randn(1,3,_s,_s, device=device, dtype=dtype)
                    scale = size/out.shape[-2]
                    _h, _w = interpolate(out, scale_factor=scale, mode=mode).shape[2:]
                    _msg = f"interpolate (x:(N,C,{_s},{_s}), scale={scale}) -> (N,C,{_h},{_w}) "
                    _msg += f"dtype {dtype}, device {device}"
                    assert _h == _w == size, _msg
```
```bash
>>> test_interpolate()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/z/work/ubuso/test/test_imgio.py", line 55, in test_interpolate
    assert _h == _w == size, _msg
AssertionError: interpolate (x:(N,C,88,88), scale=1.3636363636363635) -> (N,C,119,119) dtype torch.float32, device cpu
```
## System Info
Collecting environment information...
PyTorch version: 1.13.1
Is debug build: False
CUDA used to build PyTorch: 11.7
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.2 LTS (x86_64)
GCC version: (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Clang version: Could not collect
CMake version: version 3.22.1
Libc version: glibc-2.35

Python version: 3.9.15 | packaged by conda-forge | (main, Nov 22 2022, 15:55:03)  [GCC 10.4.0] (64-bit runtime)
Python platform: Linux-5.19.0-35-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 11.7.99
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3080 Ti Laptop GPU
Nvidia driver version: 525.85.05
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Address sizes:                   46 bits physical, 48 bits virtual
Byte Order:                      Little Endian
CPU(s):                          20
On-line CPU(s) list:             0-19
Vendor ID:                       GenuineIntel
Model name:                      12th Gen Intel(R) Core(TM) i7-12800H
CPU family:                      6
Model:                           154
Thread(s) per core:              2
Core(s) per socket:              14
Socket(s):                       1
Stepping:                        3
CPU max MHz:                     4800.0000
CPU min MHz:                     400.0000
BogoMIPS:                        5606.40
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi umip pku ospke waitpkg gfni vaes vpclmulqdq tme rdpid movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr ibt flush_l1d arch_capabilities
Virtualization:                  VT-x
L1d cache:                       544 KiB (14 instances)
L1i cache:                       704 KiB (14 instances)
L2 cache:                        11.5 MiB (8 instances)
L3 cache:                        24 MiB (1 instance)
NUMA node(s):                    1
NUMA node0 CPU(s):               0-19
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Mmio stale data:   Not affected
Vulnerability Retbleed:          Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected

Versions of relevant libraries:
[pip3] numpy==1.24.1
[pip3] pytorch3d==0.7.2
[pip3] torch==1.13.1
[pip3] torchaudio==0.13.1
[pip3] torchvision==0.14.1
[conda] blas                      1.0                         mkl    conda-forge
[conda] cudatoolkit               11.8.0              h37601d7_11    conda-forge
[conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
[conda] libblas                   3.9.0            16_linux64_mkl    conda-forge
[conda] libcblas                  3.9.0            16_linux64_mkl    conda-forge
[conda] liblapack                 3.9.0            16_linux64_mkl    conda-forge
[conda] mkl                       2022.2.1         h84fe81f_16997    conda-forge
[conda] numpy                     1.22.4                   pypi_0    pypi
[conda] pytorch                   1.13.1          py3.9_cuda11.7_cudnn8.5.0_0    pytorch
[conda] pytorch-cuda              11.7                 h67b0de4_1    pytorch
[conda] pytorch-mutex             1.0                        cuda    pytorch
[conda] pytorch3d                 0.7.2           py39_cu117_pyt1131    pytorch3d
[conda] torchaudio                0.13.1               py39_cu117    pytorch
[conda] torchvision               0.14.1               py39_cu117    pytorch

cc @albanD @mruberry @jbschlosser @walterddr @saketh-are