Segmentation fault with PyTorch 2.3

samueldmcdermott: <p>I’m getting a segmentation fault (core dump) when using functions on large arrays in torch after the recent update. So for instance</p>
<pre><code class="lang-auto">torch.tanh(torch.randn((1000,5)))
</code></pre>
<p>and</p>
<pre><code class="lang-auto">torch.randn((1000,5)).exp()
</code></pre>
<p>both dump with PyTorch 2.3 but run successfully with PyTorch 2.1</p>
<p>This behavior is limited to performing functional operations on the large arrays. I can do</p>
<pre><code class="lang-auto">torch.randn((1000,5)) @ torch.randn((5,1000))
</code></pre>
<p>successfully in both versions of PyTorch (and with larger arrays).</p>
<p>This is all occurring in a fresh venv. Please let me know what other information would be helpful (other library version information, etc)</p>

ptrblck: <p>A stacktrace would be needed as I cannot reproduce these issues.</p>

samueldmcdermott: <p>in ipython I only get <code>Segmentation fault: 11</code> and in a Jupyter notebook the kernel dies. There’s no trackback for the error. But I did just try in a regular python environment and the functions seem to work – so can this be an ipython issue? Odd that it fixes itself when I change PyTorch versions.</p>

ptrblck: <p>Yes, it seems to have at least a dependency on IPython. You could run it via:</p>
<pre data-code-wrap="python"><code class="lang-python">gdb --args ipython ...
...
run
...
bt
</code></pre>
<p>to get the backtrace after it segfaults.</p>

samueldmcdermott: <p>I don’t have <code>gdb</code> (M1 Mac Silicon), and I was getting weird errors with <code>lldb</code> (with any <code>process launch</code> command I got <code>error: invalid target, create a target using the 'target create' command</code>, which then failed with some weird <code>host</code> requirement that I couldn’t get around), but using the built-in <code>faulthandler</code> via <code>faulthandler.enable()</code> seemed to work. When I try <code>torch.randn((5000,)).exp()</code> I am getting for example</p>
<pre><code class="lang-auto">Fatal Python error: Segmentation fault

Thread 0x00000001709df000 (most recent call first):
  File "/Users/sammcd/micromamba/envs/s4/lib/python3.12/site-packages/IPython/core/history.py", line 836 in _writeout_input_cache
  File "/Users/sammcd/micromamba/envs/s4/lib/python3.12/site-packages/IPython/core/history.py", line 853 in writeout_cache
  File "/Users/sammcd/micromamba/envs/s4/lib/python3.12/site-packages/IPython/core/history.py", line 61 in only_when_enabled
  File Segmentation fault: 11
</code></pre>
<p>For <code>torch.tanh(torch.randn((5000,)))</code> the same lines print as do</p>
<pre><code class="lang-auto">  File "/Users/sammcd/micromamba/envs/s4/lib/python3.12/site-packages/decorator.py", line 232 in fun
  File "/Users/sammcd/micromamba/envs/s4/lib/python3.12/site-packages/IPython/core/history.py", line 908 in run
  File "/Users/sammcd/micromamba/envs/s4/lib/python3.12/site-packages/IPython/core/history.py", line 61 in only_when_enabled
  File "/Users/sammcd/micromamba/envs/s4/lib/python3.12/site-packages/decorator.py", line 232 in fun
  File "/Users/sammcd/micromamba/envs/s4/lib/python3.12/threading.py", line 1073 in _bootstrap_inner
</code></pre>