Repository: pytorch
Issue: Unexpected behavior comparing uint8 tensor to value greater than 255
Labels: triaged,module: type promotion,module: edge cases

### 🐛 Describe the bug

Unexpected behavior comparing uint8 tensor to value greater than 255. This appears to be an overflow issue. Behavior is not consistent with how numpy addresses this issue. I would expect it to be consistent with numpy or throw a runtime error (it actually does throw a runtime error with my install of pytorch==1.0.0 but not in recent versions of pytorch).


```
tensor_float = torch.tensor([1.0])
tensor_uint8 = tensor_float.type(torch.uint8)

print(f"tensor_float < 256: {tensor_float < 256}")
print(f"tensor_uint8 < 256: {tensor_uint8 < 256}")
print(f"tensor_float.numpy() < 256: {tensor_float.numpy() < 256}")
print(f"tensor_uint8.numpy() < 256: {tensor_uint8.numpy() < 256}")

print(f"tensor_float > 256: {tensor_float > 256}")
print(f"tensor_uint8 > 256: {tensor_uint8 > 256}")
print(f"tensor_float.numpy() > 256: {tensor_float.numpy() > 256}")
print(f"tensor_uint8.numpy() > 256: {tensor_uint8.numpy() > 256}")
```

Output in 1.13.1 and 2.0.1:
```
tensor_float < 256: tensor([True])                                                                                                                                                 
tensor_uint8 < 256: tensor([False])                                                                                                                                                
tensor_float.numpy() < 256: [ True]                                                                                                                                                
tensor_uint8.numpy() < 256: [ True]
tensor_float > 256: tensor([False])
tensor_uint8 > 256: tensor([True])
tensor_float.numpy() > 256: [False]
tensor_uint8.numpy() > 256: [False]
```

Output in 1.0.0
```
tensor_float < 256: tensor([1], dtype=torch.uint8)
Traceback (most recent call last):
  File "/home/xsy/code/torchcloud/minimum_example.py", line 7, in <module>
    print(f"tensor_uint8 < 256: {tensor_uint8 < 256}")
RuntimeError: value cannot be converted to type uint8_t without overflow: 256
```

### Versions

Collecting environment information...
PyTorch version: 2.0.1
Is debug build: False
CUDA used to build PyTorch: 11.8
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.18.2
Libc version: glibc-2.35

Python version: 3.11.3 | packaged by conda-forge | (main, Apr  6 2023, 08:57:19) [GCC 11.3.0] (64-bit runtime)
Python platform: Linux-5.15.0-71-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 12.1.105
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA TITAN V
GPU 1: NVIDIA TITAN V

Nvidia driver version: 530.30.02
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.0
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):                          16
On-line CPU(s) list:             0-15
Vendor ID:                       GenuineIntel
Model name:                      Intel(R) Core(TM) i7-7820X CPU @ 3.60GHz
CPU family:                      6
Model:                           85
Thread(s) per core:              2
Core(s) per socket:              8
Socket(s):                       1
Stepping:                        4
CPU max MHz:                     4500.0000
CPU min MHz:                     1200.0000
BogoMIPS:                        7200.00
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 pni pclmulqdq dtes64 monitor ds_cpl est tm2 ssse3 sdbg 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 cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti ssbd mba ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req md_clear flush_l1d arch_capabilities
L1d cache:                       256 KiB (8 instances)
L1i cache:                       256 KiB (8 instances)
L2 cache:                        8 MiB (8 instances)
L3 cache:                        11 MiB (1 instance)
NUMA node(s):                    1
NUMA node0 CPU(s):               0-15
Vulnerability Itlb multihit:     KVM: Mitigation: VMX unsupported
Vulnerability L1tf:              Mitigation; PTE Inversion
Vulnerability Mds:               Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown:          Mitigation; PTI
Vulnerability Mmio stale data:   Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Retbleed:          Mitigation; IBRS
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Mitigation; Clear CPU buffers; SMT vulnerable

Versions of relevant libraries:
[pip3] numpy==1.24.3
[pip3] torch==2.0.1
[pip3] torchaudio==2.0.2
[pip3] torchvision==0.15.2
[pip3] triton==2.0.0
[conda] blas                      2.116                       mkl    conda-forge
[conda] blas-devel                3.9.0            16_linux64_mkl    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] liblapacke                3.9.0            16_linux64_mkl    conda-forge
[conda] mkl                       2022.1.0           h84fe81f_915    conda-forge
[conda] mkl-devel                 2022.1.0           ha770c72_916    conda-forge
[conda] mkl-include               2022.1.0           h84fe81f_915    conda-forge
[conda] numpy                     1.24.3          py311h64a7726_0    conda-forge
[conda] pytorch                   2.0.1           py3.11_cuda11.8_cudnn8.7.0_0    pytorch
[conda] pytorch-cuda              11.8                 h7e8668a_5    pytorch
[conda] pytorch-mutex             1.0                        cuda    pytorch
[conda] torchaudio                2.0.2               py311_cu118    pytorch
[conda] torchtriton               2.0.0                     py311    pytorch
[conda] torchvision               0.15.2              py311_cu118    pytorch

cc @nairbv @mruberry