Repository: pytorch
Issue: [apple M2]libc++abi: terminating due to uncaught exception of type c10::Error: Could not find schema for aten::randn
Labels: needs reproduction,module: build,module: cpp,triaged,module: macos

### 🐛 Describe the bug

buid script:`cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release ..`
```c++
#include <torch/torch.h>
#include <iostream>

int main() {
  torch::Tensor tensor = torch::rand({2, 3});
  std::cout << tensor << std::endl;
}
```
The build is packaged fine, but after running it reports an error。
```log
libc++abi: terminating due to uncaught exception of type c10::Error: Could not find schema for aten::randn.
Exception raised from findSchemaOrThrow at /Users/baiyue/mino/cpp/pytorch/aten/src/ATen/core/dispatch/Dispatcher.cpp:144 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>) + 52 (0x10534f4fc in inventix)
frame #1: c10::detail::torchCheckFail(char const*, char const*, unsigned int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) + 92 (0x10534da54 in inventix)
frame #2: c10::Dispatcher::findSchemaOrThrow(char const*, char const*) + 756 (0x10541f570 in inventix)
frame #3: at::_ops::create_randn_typed_handle() + 68 (0x1054f5fa8 in inventix)
frame #4: at::_ops::randn::call(c10::ArrayRef<c10::SymInt>, std::__1::optional<c10::ScalarType>, std::__1::optional<c10::Layout>, std::__1::optional<c10::Device>, std::__1::optional<bool>) + 660 (0x1054f5e98 in inventix)
frame #5: torch::randn(c10::ArrayRef<long long>, c10::TensorOptions) + 72 (0x1048354ec in inventix)
```


### Versions

<details>
<summary>latest version</summary>

PyTorch version: 2.3.1
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 14.5 (arm64)
GCC version: Could not collect
Clang version: 15.0.0 (clang-1500.0.40.1)
CMake version: version 3.27.6
Libc version: N/A

Python version: 3.10.9 (v3.10.9:1dd9be6584, Dec  6 2022, 14:37:36) [Clang 13.0.0 (clang-1300.0.29.30)] (64-bit runtime)
Python platform: macOS-14.5-arm64-arm-64bit
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:
Apple M2

Versions of relevant libraries:
[pip3] numpy==1.24.4
[pip3] onnx==1.16.1
[pip3] onnx-graphsurgeon==0.3.27
[pip3] onnx2torch==1.5.11
[pip3] onnxconverter-common==1.14.0
[pip3] onnxmltools==1.11.2
[pip3] onnxruntime==1.18.0
[pip3] onnxsim==0.4.36
[pip3] pytorch-lightning==1.9.3
[pip3] pytorch-wpe==0.0.1
[pip3] rotary-embedding-torch==0.2.7
[pip3] skl2onnx==1.15.0
[pip3] spo4onnx==1.0.3
[pip3] tf2onnx==1.15.1
[pip3] torch==2.3.1
[pip3] torch-complex==0.4.3
[pip3] torch-quant==0.4.0
[pip3] torch-stoi==0.1.2
[pip3] torchaudio==2.3.1
[pip3] torchmetrics==0.11.1
[pip3] torchvision==0.18.1
[pip3] vector-quantize-pytorch==1.14.24
[conda] Could not collect
</details>


cc @malfet @seemethere @jbschlosser @albanD