-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Description
🐛 Describe the bug
Hello, I've encountered an issue while training a model that produces unusual output. Upon investigation, I discovered that the anomaly originates from an unexpected result from the 'interpolate' function.
import torch
from torch.nn.functional import interpolate
def get_grads(dtype, size):
input = torch.randn((2, 2, 1, 1), dtype=dtype, requires_grad=True).cuda()
output = interpolate(input, size=size, mode='bicubic', align_corners=True)
grad_outputs = [torch.ones_like(output)]
grads = torch.autograd.grad([output], [input], grad_outputs)
return grads[0]
print(get_grads(torch.float32, (128, 128)).flatten())
print(get_grads(torch.float16, (128, 128)).flatten())
print(get_grads(torch.float32, (64, 64)).flatten())
print(get_grads(torch.float16, (64, 64)).flatten())
print(get_grads(torch.float32, (32, 32)).flatten())
print(get_grads(torch.float16, (32, 32)).flatten())
The output is as follows:
tensor([16384., 16384., 16384., 16384.], device='cuda:0')
tensor([2048., 2048., 2048., 2048.], device='cuda:0', dtype=torch.float16)
tensor([4096., 4096., 4096., 4096.], device='cuda:0')
tensor([2048., 2048., 2048., 2048.], device='cuda:0', dtype=torch.float16)
tensor([1024., 1024., 1024., 1024.], device='cuda:0')
tensor([1024., 1024., 1024., 1024.], device='cuda:0', dtype=torch.float16)
Could this be a bug? It appears that the maximum value of the gradient is capped at 2048 for the float16 data type. If this is not a bug, could you please tell me why this is happening?
Furthermore, I'm wondering if you could implement a warning to alert users when this issue occurs.
Versions
Collecting environment information...
PyTorch version: 2.0.0a0+gitc263bd4
Is debug build: False
CUDA used to build PyTorch: 11.2
ROCM used to build PyTorch: N/A
OS: CentOS Linux 7 (Core) (x86_64)
GCC version: (GCC) 7.5.0
Clang version: Could not collect
CMake version: version 3.26.3
Libc version: glibc-2.17
Python version: 3.8.5 (default, Sep 4 2020, 07:30:14) [GCC 7.3.0] (64-bit runtime)
Python platform: Linux-3.10.0-693.el7.x86_64-x86_64-with-glibc2.10
Is CUDA available: True
CUDA runtime version: 11.2.67
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration:
GPU 0: Tesla V100-SXM2-32GB
GPU 1: Tesla V100-SXM2-32GB
GPU 2: Tesla V100-SXM2-32GB
GPU 3: Tesla V100-SXM2-32GB
GPU 4: Tesla V100-SXM2-32GB
GPU 5: Tesla V100-SXM2-32GB
GPU 6: Tesla V100-SXM2-32GB
GPU 7: Tesla V100-SXM2-32GB
Nvidia driver version: 460.73.01
cuDNN version: /usr/local/cuda-9.0/lib64/libcudnn.so.7.0.4
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
Byte Order: Little Endian
CPU(s): 48
On-line CPU(s) list: 0-47
Thread(s) per core: 2
Core(s) per socket: 12
Socket(s): 2
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 85
Model name: Intel(R) Xeon(R) Gold 6146 CPU @ 3.20GHz
Stepping: 4
CPU MHz: 3200.000
BogoMIPS: 6400.00
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 1024K
L3 cache: 25344K
NUMA node0 CPU(s): 0-11,24-35
NUMA node1 CPU(s): 12-23,36-47
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 aperfmperf eagerfpu pni pclmulqdq dtes64 ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm arat pln pts
Versions of relevant libraries:
[pip3] numpy==1.24.3
[pip3] torch==2.0.0a0+gitc263bd4
[pip3] torchvision==0.15.1a0
[conda] magma-cuda112 2.5.2 1
[conda] mkl 2023.1.0 pypi_0 pypi
[conda] mkl-include 2023.1.0 pypi_0 pypi
[conda] numpy 1.24.3 pypi_0 pypi
[conda] torch 2.0.0a0+gitc263bd4 pypi_0 pypi
[conda] torchvision 0.15.1a0 pypi_0 pypi