Repository: pytorch
Issue: pytorch consuming all cpu cores 100% on ARM
Labels: module: binaries,triaged,module: openmp,module: arm

### 🐛 Describe the bug

We have a small-ish torch model and runs pretty fast and as expected on Intel x64. Although, even on Intel, setting `torch.set_num_threads(1)` reduces cpu usage.

But with ARM (16 core AWS graviton e.g.) it starts consuming 1600% cpu! Then setting `torch.set_num_threads(1)` tones it a bit down to around `1500%+`. Then setting `export OMP_NUM_THREADS=1` brings it down all the way to 25% cpu.

This seems like totally unexpected behavior.

### Versions

/usr/local/lib/python3.11/site-packages/torch/nn/modules/transformer.py:20: UserWarning: Failed to initialize NumPy: No module named 'numpy' (Triggered internally at /pytorch/torch/csrc/utils/tensor_numpy.cpp:84.)
  device: torch.device = torch.device(torch._C._get_default_device()),  # torch.device('cpu'),
Collecting environment information...
PyTorch version: 2.1.0
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Debian GNU/Linux 12 (bookworm) (aarch64)
GCC version: (Debian 12.2.0-14) 12.2.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.36

Python version: 3.11.4 (main, Aug 16 2023, 07:34:21) [GCC 12.2.0] (64-bit runtime)
Python platform: Linux-5.19.0-1025-aws-aarch64-with-glibc2.36
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:                    aarch64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
CPU(s):                          16
On-line CPU(s) list:             0-15
Vendor ID:                       ARM
Model name:                      Neoverse-V1
Model:                           1
Thread(s) per core:              1
Core(s) per cluster:             16
Socket(s):                       -
Cluster(s):                      1
Stepping:                        r1p1
BogoMIPS:                        2100.00
Flags:                           fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm ssbs paca pacg dcpodp svei8mm svebf16 i8mm bf16 dgh rng
L1d cache:                       1 MiB (16 instances)
L1i cache:                       1 MiB (16 instances)
L2 cache:                        16 MiB (16 instances)
L3 cache:                        32 MiB (1 instance)
NUMA node(s):                    1
NUMA node0 CPU(s):               0-15
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Mmio stale data:   Not affected
Vulnerability Retbleed:          Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:        Mitigation; __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; CSV2, BHB
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected

Versions of relevant libraries:
[pip3] torch==2.1.0
[pip3] torchaudio==2.1.0
[conda] Could not collect

cc @seemethere @malfet @osalpekar @atalman @snadampal