Repository: pytorch
Issue: [XPU] torch.nn.functional.pad brings wrong results with torch.compile on Intel GPU
Labels: triaged,oncall: pt2,module: inductor,module: xpu

### 🐛 Describe the bug

torch.nn.functional.pad brings wrong results with torch.compile on Intel GPU (XPU).

```python
import torch

class Model(torch.nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, *args):
        pad = torch.nn.functional.pad(args[0], (0, 1, 1, 0), mode = 'constant', value = 0.5)
        return pad

m = Model()

inp = torch.randn((1, 1), dtype=torch.float32)
print(inp)
# tensor([[-0.5137]])

m.to('cpu')
cpu_out = m(inp.to('cpu'))
print(cpu_out)
# tensor([[ 0.5000,  0.5000],
#         [-0.5137,  0.5000]])

m.to('xpu')
xpu_out = m(inp.to('xpu'))
print(xpu_out)
# tensor([[ 0.5000,  0.5000],
#         [-0.5137,  0.5000]], device='xpu:0')

opt = torch.compile(m, fullgraph=True, backend='inductor', mode=None)

opt.to('cpu')
cpu_out = opt(inp.to('cpu'))
print(cpu_out)
# tensor([[ 0.5000,  0.5000],
#         [-0.5137,  0.5000]])

opt.to('xpu')
xpu_out = opt(inp.to('xpu'))
print(xpu_out) # Different!
# tensor([[-0.5137, -0.5137],
#         [-0.5137, -0.5137]], device='xpu:0')
```

### **Error Logs**
```bash
tensor([[-0.5137]])
tensor([[ 0.5000,  0.5000],
        [-0.5137,  0.5000]])
tensor([[ 0.5000,  0.5000],
        [-0.5137,  0.5000]], device='xpu:0')
tensor([[ 0.5000,  0.5000],
        [-0.5137,  0.5000]])
tensor([[-0.5137, -0.5137],
        [-0.5137, -0.5137]], device='xpu:0')
```


### Versions

PyTorch version: 2.5.1+xpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.1 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.39

Python version: 3.10.16 | packaged by conda-forge | (main, Dec  5 2024, 14:16:10) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-5.15.167.4-microsoft-standard-WSL2-x86_64-with-glibc2.39
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
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):                               18
On-line CPU(s) list:                  0-17
Vendor ID:                            GenuineIntel
Model name:                           Intel(R) Core(TM) Ultra 5 125H
CPU family:                           6
Model:                                170
Thread(s) per core:                   2
Core(s) per socket:                   9
Socket(s):                            1
Stepping:                             4
BogoMIPS:                             5990.40
Flags:                                fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtop
ology tsc_reliable nonstop_tsc cpuid pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_sin
gle ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves avx_vnni umip waitpkg gfni vaes vpclmulqdq rdpid movdiri movdir64b fsrm md_clear serialize flush_l1d arch_capabilities
Virtualization:                       VT-x
Hypervisor vendor:                    Microsoft
Virtualization type:                  full
L1d cache:                            432 KiB (9 instances)
L1i cache:                            576 KiB (9 instances)
L2 cache:                             18 MiB (9 instances)
L3 cache:                             18 MiB (1 instance)
Vulnerability Gather data sampling:   Not affected
Vulnerability Itlb multihit:          Not affected
Vulnerability L1tf:                   Not affected
Vulnerability Mds:                    Not affected
Vulnerability Meltdown:               Not affected
Vulnerability Mmio stale data:        Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed:               Mitigation; Enhanced IBRS
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; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

Versions of relevant libraries:
[pip3] numpy==2.1.3
[pip3] onnx==1.17.0
[pip3] onnxruntime==1.20.1
[pip3] onnxscript==0.1.0.dev20241211
[pip3] pytorch-triton-xpu==3.1.0
[pip3] torch==2.5.1+xpu
[pip3] torchaudio==2.5.1+xpu
[pip3] torchvision==0.20.1+xpu
[conda] numpy                     2.1.3                    pypi_0    pypi
[conda] pytorch-triton-xpu        3.1.0                    pypi_0    pypi
[conda] torch                     2.5.1+xpu                pypi_0    pypi
[conda] torchaudio                2.5.1+xpu                pypi_0    pypi
[conda] torchvision               0.20.1+xpu               pypi_0    pypi

cc @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @ColinPeppler @amjames @desertfire @aakhundov @gujinghui @fengyuan14 @guangyey @kulinseth @albanD @malfet @DenisVieriu97 @jhavukainen