Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[torch.prod] Incorrect cpu calculation results for torch.prod #127866

Closed
wbscd opened this issue Jun 4, 2024 · 3 comments
Closed

[torch.prod] Incorrect cpu calculation results for torch.prod #127866

wbscd opened this issue Jun 4, 2024 · 3 comments
Assignees
Labels
high priority release notes: python_frontend python frontend release notes category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@wbscd
Copy link

wbscd commented Jun 4, 2024

🐛 Describe the bug

import torch

x = torch.zeros((1, 1, 16, 16), dtype=torch.bool)
y = torch.prod(x, dtype=torch.bool)

print(y)
# Get `tensor(True)` as result but the result should be `tensor(False)` obviously.

Versions

Collecting environment information...
PyTorch version: 2.3.0+cu121
Is debug build: False
CUDA used to build PyTorch: 12.1
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: 14.0.0-1ubuntu1.1
CMake version: version 3.28.1
Libc version: glibc-2.35

Python version: 3.9.16 (main, May 15 2023, 23:46:34) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.10.16.3-microsoft-standard-WSL2-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce MX570
Nvidia driver version: 546.80
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: 39 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: GenuineIntel
Model name: 12th Gen Intel(R) Core(TM) i7-1260P
CPU family: 6
Model: 154
Thread(s) per core: 2
Core(s) per socket: 8
Socket(s): 1
Stepping: 3
BogoMIPS: 4992.01
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 xtopology 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_single 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 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: 384 KiB (8 instances)
L1i cache: 256 KiB (8 instances)
L2 cache: 10 MiB (8 instances)
L3 cache: 18 MiB (1 instance)
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: 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 IBRS, IBPB conditional, RSB filling
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected

Versions of relevant libraries:
[pip3] numpy==1.21.5
[pip3] torch==2.3.0
[pip3] torchaudio==2.1.1+cu121
[pip3] torchvision==0.16.1+cu121
[pip3] triton==2.3.0
[conda] numpy 1.21.5 pypi_0 pypi
[conda] torch 2.3.0 pypi_0 pypi
[conda] torchaudio 2.1.1+cu121 pypi_0 pypi
[conda] torchvision 0.16.1+cu121 pypi_0 pypi
[conda] triton 2.3.0 pypi_0 pypi

cc @ezyang @gchanan @zou3519 @kadeng @msaroufim

@albanD
Copy link
Collaborator

albanD commented Jun 4, 2024

Note that this is due to the dtype= argument on torch.prod. Without this argument this works just fine.
Also the current code only fails if you have "nb_elem % 256 == 0"

@mingfeima
Copy link
Collaborator

@zhuhaozhe please help fix this one!

@zhuhaozhe
Copy link
Collaborator

zhuhaozhe commented Jun 5, 2024

Rootcaused here

__ubsan_ignore_undefined__ { return a && b; },

the && are not override for Vectorized<bool> and will return True here even both a and b are all Falses, will submit a PR for it.

@bdhirsh bdhirsh added triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module and removed triage review labels Jun 10, 2024
pytorch-bot bot pushed a commit that referenced this issue Sep 13, 2024
Chao1Han pushed a commit to Chao1Han/pytorch that referenced this issue Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
high priority release notes: python_frontend python frontend release notes category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
Status: Done
Development

No branches or pull requests

5 participants