Repository: pytorch
Issue: Different behaviors with torch.isfinite and torch.tril between eagermode and JIT
Labels: oncall: jit

### 🐛 Describe the bug

In JIT mode, the `torch.isfinite` function outputs an incorrect tensor shape(in eagermode the shape of the v3_0 is [3,10,1] which is expected. But in JIT, the shape is [3,10,1,10,9,1]) . Attempting to randomly generate an input tensor results in no error. Attempting to run the `torch.isfinite` function alone also results in no error. 
please check: [inputs.pkl.zip](https://github.com/pytorch/pytorch/files/14021295/inputs.pkl.zip)

```
from typing import Dict
import pickle
import torch
import torch.nn as nn

with open('inputs.pkl', 'rb') as f:
    inputs: Dict[str, torch.Tensor] = pickle.load(f) # 'v1_0': ..., 'v2_0': ...

class Model(nn.Module):
    def __init__(self):
        super().__init__()
        self.layer0 = torch.nn.LeakyReLU(0.01)

    def forward(self, v1_0, v0_0):
        v3_0 = torch.isfinite(input=v1_0)
        v2_0 = torch.tril(diagonal=9, input=v0_0, out=v1_0)
        v4_0 = self.layer0(v2_0)
        return v3_0, v4_0

model = Model().to(torch.device("cpu"))
for k, v in inputs.items():
    inputs[k] = v.to(torch.device("cpu"))
print('==== Eager mode ====')
ret_eager = model(**inputs)
print("eager :", [i.shape for i in inputs.values()], [i.shape for i in ret_eager])
print('==== JIT mode ====')
exported = torch.jit.trace(model, example_kwarg_inputs=inputs)
exported = torch.jit.optimize_for_inference(exported)
ret_exported = exported(**inputs)
print("eager :", [i.shape for i in inputs.values()], [i.shape for i in ret_exported])
```
error stacktrace
```
==== Eager mode ====
/home/guihuan/artifact/home/guihuan/artifact/gen/torch-constrinf-n3/bug-Symptom.EXCEPTION-Stage.VERIFICATION-0/prog.py:16: UserWarning: An output with one or more elements was resized since it had shape [3, 10, 1, 10, 9, 1], which does not match the required output shape [3, 10, 1]. This behavior is deprecated, and in a future PyTorch release outputs will not be resized unless they have zero elements. You can explicitly reuse an out tensor t by resizing it, inplace, to zero elements with t.resize_(0). (Triggered internally at ../aten/src/ATen/native/Resize.cpp:28.)
  v2_0 = torch.tril(diagonal=9, input=v0_0, out=v1_0)
eager : [torch.Size([3, 10, 1]), torch.Size([3, 10, 1])] [torch.Size([3, 10, 1, 10, 9, 1]), torch.Size([3, 10, 1])]
==== JIT mode ====
eager : [torch.Size([3, 10, 1]), torch.Size([3, 10, 1])] [torch.Size([3, 10, 1]), torch.Size([3, 10, 1])]
==== Check ====
Traceback (most recent call last):
  File "/home/guihuan/artifact/home/guihuan/artifact/gen/torch-constrinf-n3/bug-Symptom.EXCEPTION-Stage.VERIFICATION-0/prog.py", line 33, in <module>
    assert torch.allclose(r1, r2), (r1, r2)
RuntimeError: The size of tensor a (9) must match the size of tensor b (10) at non-singleton dimension 4
```

### Versions

PyTorch version: 2.3.0.dev20240110+cu118
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.3 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.22.1
Libc version: glibc-2.35

Python version: 3.9.17 (main, Jul 5 2023, 20:41:20) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.15.0-86-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 GeForce RTX 2070
GPU 1: NVIDIA GeForce RTX 2070
GPU 2: NVIDIA GeForce RTX 2070
GPU 3: NVIDIA GeForce RTX 2070

Nvidia driver version: 535.104.12
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): 32
On-line CPU(s) list: 0-31
Vendor ID: GenuineIntel
Model name: Intel(R) Xeon(R) CPU E5-2630 v3 @ 2.40GHz
CPU family: 6
Model: 63
Thread(s) per core: 2
Core(s) per socket: 8
Socket(s): 2
Stepping: 2
CPU max MHz: 3200.0000
CPU min MHz: 1200.0000
BogoMIPS: 4794.64
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 arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx 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 cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm xsaveopt cqm_llc cqm_occup_llc dtherm ida arat pln pts md_clear flush_l1d
Virtualization: VT-x
L1d cache: 512 KiB (16 instances)
L1i cache: 512 KiB (16 instances)
L2 cache: 4 MiB (16 instances)
L3 cache: 40 MiB (2 instances)
NUMA node(s): 2
NUMA node0 CPU(s): 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30
NUMA node1 CPU(s): 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31
Vulnerability Gather data sampling: Not affected
Vulnerability Itlb multihit: KVM: Mitigation: VMX disabled
Vulnerability L1tf: Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown: Mitigation; PTI
Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
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; Retpolines, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected

Versions of relevant libraries:
[pip3] numpy==1.24.3
[pip3] pytorch-triton==2.2.0+e28a256d71
[pip3] torch==2.3.0.dev20240110+cu118
[pip3] torchaudio==2.2.0.dev20240110+cu118
[pip3] torchvision==0.18.0.dev20240110+cu118
[conda] cudatoolkit 11.8.0 h6a678d5_0 defaults
[conda] numpy 1.24.3 pypi_0 pypi
[conda] pytorch-triton 2.2.0+e28a256d71 pypi_0 pypi
[conda] torch 2.3.0.dev20240110+cu118 pypi_0 pypi
[conda] torchaudio 2.2.0.dev20240110+cu118 pypi_0 pypi
[conda] torchvision 0.18.0.dev20240110+cu118 pypi_0 pypi

cc @EikanWang @jgong5 @wenzhe-nrv @sanchitintel