Segfault in libtorch_cpu running fastai

g-clef: <p>Hello, all,</p>
<p>I’m trying to get a local install of fastai running…I was hoping that using the fastai docker images would spare me having to install and manage the fastai and pytorch libraries myself, but I’m running into a segfault in pytorch, which I’m not sure how to fix.</p>
<p>My setup:<br>
CPU: Intel® Core™ i7 CPU 950 @ 3.07GHz<br>
RAM: 12GB<br>
Video card: GeForce RTX 2070 SUPER<br>
OS: Ubuntu 20.04 (clean, just re-installed)<br>
Nvidia driver: Ubuntu-provided nvidia-450<br>
Followed instructions to install docker and nvidia-docker extensions.<br>
Running torch.cuda.is_available() in the fastai docker container returns True.</p>
<p>The error:<br>
In Jupyter the kernel crashes &amp; is restarted at the first “learn.fine_tune(1)” line.<br>
In dmesg, there’s a line that says: traps: python[1910] trap invalid opcode ip:7fc9d0d63869 sp:7fff30e315a0 error:0 in libtorch_cpu.so[7fc9cfa41000+6754000]</p>
<p>If it helps, I had fastai v1 working on this hardware back in March, but got derailed by life and just picked it back up now. So, I know this setup <em>can</em> work, but something’s changed since March that’s not agreeing with my setup.</p>
<p>Has anyone seen this before, or have an idea of what I did wrong?</p>

ptrblck: <p>Are you seeing this issue only with the FastAI installation / docker image or also if you install the PyTorch binaries?<br>
If I’m not mistaken these kind of errors are raised if your CPU encounters unsupported instructions, e.g. avx instructions on older CPUs.</p>

g-clef: <p>I tried installing pytorch via conda locally (outside the docker container) and I’m seeing the same thing, yeah.  Is there a way to configure/compile pytorch to not use those newer instructions?</p>
<p>I admit the CPU itself is a bit old (1st gen core i7, Nehalem)…I repurposed my old game machine and swapped out the GPU for something recent and powerful. I had hoped the CPU wouldn’t matter that much if the GPU was recent.</p>
<p>Thanks for your help.</p>

ptrblck: <p>If you build from source, cmake might automatically detect the CPU capability and might disable e.g. AVX, if it’s not supported.<br>
Could you try that and see if it would be working?</p>

g-clef: <p>I tried that, and got…mixed results.</p>
<p>The build finished properly when I ran it on <code>master</code>, but master is calling itself version 1.8.0, and FastAI apparently isn’t compatible with that version…it’s expecting 1.6. I tried loading it anyway, and it exceptions with an error about “FakeLoader” not having a “persistent_workers” attribute.</p>
<p>If I checkout the <code>v1.6.0</code> tag, the build fails with errors like:</p>
<pre><code class="lang-auto">../caffe2/quantization/server/conv_dnnlowp_op.cc:1211:55: error: ‘depthwise_3x3x3_per_channel_quantization_pad_1’ was not declared in this scope
         depthwise_3x3x3_per_channel_quantization_pad_1(
</code></pre>
<p>Is there something special I should be doing to build <code>1.6</code> instead of <code>master</code>?</p>
<p>Thanks again for the help.</p>

ptrblck: <p>Did you update all submodules after the <code>1.6</code> branch checkout?<br>
Also, did you clean the build via <code>python setup.py clean</code>?<br>
These types of error are often raised if the build is trying to reuse some temp. files from the previous builds.</p>

g-clef: <p>Rather than mess with cleanup, I just deleted the folder &amp; re-cloned it. I did:</p>
<blockquote>
<p>git clone --recursive <a href="https://github.com/pytorch/pytorch" class="inline-onebox" rel="noopener nofollow ugc">GitHub - pytorch/pytorch: Tensors and Dynamic neural networks in Python with strong GPU acceleration</a><br>
cd pytorch<br>
git pull<br>
git checkout tags/v1.6.0<br>
git pull<br>
python3 setup.py build</p>
</blockquote>
<p>and the end result was the same:</p>
<blockquote>
<p>…/caffe2/quantization/server/conv_dnnlowp_op.cc: In instantiation of ‘void caffe2::ConvDNNLowPOp&lt;T, ReluFused&gt;::ConvNHWCCore_(const T*, std::vector*) [with T = unsigned char; bool ReluFused = false]’:<br>
…/caffe2/quantization/server/conv_dnnlowp_op.cc:1752:16:   required from here<br>
…/caffe2/quantization/server/conv_dnnlowp_op.cc:1211:55: error: ‘depthwise_3x3x3_per_channel_quantization_pad_1’ was not declared in this scope<br>
depthwise_3x3x3_per_channel_quantization_pad_1(</p>
</blockquote>
<p>Any ideas what else I could try?</p>
<p>Thanks again.</p>

ptrblck: <p>After the branch checkout run:</p>
<pre><code class="lang-auto">git submodule update --init --recursive
</code></pre>

Corey_Cole: <p>I’ve got a similar CPU (Westmere Xeon) and have the same problem.  This appears to be PyTorch issue 43300 (<a href="https://github.com/pytorch/pytorch/issues/43300" rel="noopener nofollow ugc">https://github.com/pytorch/pytorch/issues/43300</a>).  I’ve tried the latest 1.7.0 nightly build and while I don’t get <em>this</em> problem, I get a different one that’s probably also AVX related.</p>
<p>FWIW, my new issue with the nightly is that NNPACK, while running nnp_initialize returns “unsupported hardware”</p>
<p>The exact error is:<br>
[W NNPACK.cpp:80] Could not initialize NNPACK! Reason: Unsupported hardware.</p>
<p>For a CPU as old as yours and mine, I think we’re going to have to build from source to ensure that no AVX support sneaks in.</p>

Corey_Cole: <p>I just tested the release of 1.7.0 on my Westmere Xeon and the NNPACK error is still present.  I’ve thrown in the towel and have some AVX hardware to replace it, but I think anyone who wants to continue with pre-AVX hardware will need to build from source to avoid the SIGILL issues.</p>

g-clef: <p>Thanks everyone for your help.</p>
<p>Fastai patched this weekend to support torch 1.7, and that seems to have been enough to support the <code>master</code> branch of pytorch. I manually built torch and torchvision from master, with <code>ENABLE_NNPACK=0</code> set as an environment variable to avoid the “Unsupported Hardware” error, and the <code>master</code> branch of fastai. That seems to be working for me.</p>