Is nomkl still recommended for OMP issue on Mac?

builder173: <p>Hi, I’ve seen this covered on SO but there’s a lot of contradictory info so hoping a best practice exists among users here.</p>
<p>Background:<br>
MacOs 12.4 on 2016 MacBook Pro (16Gb, 2.7GHz)<br>
Clean install of Anaconda then installed PyTorch per Getting Started</p>
<blockquote>
<p>conda create --prefix ./envs<br>
conda install pytorch torchvision torchaudio -c pytorch<br>
conda install ipython ipykernel<br>
conda install matplotlib</p>
</blockquote>
<p>Working in VSCode. Above python env activated/selected for notebooks<br>
Was able to run all the .ipynb notebooks from “Introduction to PyTorch” tutorials</p>
<p>Issue:<br>
Trying to run the notebook for <a href="https://pytorch.org/tutorials/beginner/nn_tutorial.html" class="inline-onebox" rel="noopener nofollow ugc">What is torch.nn really? — PyTorch Tutorials 2.1.1+cu121 documentation</a><br>
led to kernel crash with no meaningful error at:</p>
<pre><code class="lang-auto">import torch

x_train, y_train, x_valid, y_valid = map(
    torch.tensor, (x_train, y_train, x_valid, y_valid)
)
n, c = x_train.shape
print(x_train, y_train)
print(x_train.shape)
print(y_train.min(), y_train.max())
</code></pre>
<p>Attempted:<br>
Ran the commands from an ipython session and got this error:<br>
<em>OMP: Error <span class="hashtag-raw">#15:</span> Initializing libiomp5.dylib, but found libomp.dylib already initialized.</em><br>
<em>OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see <a href="http://www.intel.com/software/products/support/." rel="noopener nofollow ugc">http://www.intel.com/software/products/support/.</a></em></p>
<p>I saw proposed solution to use:</p>
<blockquote>
<p>conda install nomkl<br>
I gave this a shot but it failed with conflicts in my environment so looking to see if this is the right track.</p>
</blockquote>

builder173: <p>I had some progress here, at least addressing the kernel crash with the above tutorial code. A fresh conda install as below appeared to work. It’s still a bit unclear to me why it works, because the PyTorch install did list an mkl package as being installed and I see it in the environment package list. I would have thought installing the mutex package “nomkl” would have forced everything to be an OpenBlas per:<br>
<a href="https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/packages.html?highlight=nomkl#installing-numpy-with-blas-variants" class="onebox" target="_blank" rel="noopener nofollow ugc">https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/packages.html?highlight=nomkl#installing-numpy-with-blas-variants</a></p>
<p>In any case, if a moderator/admin type sees this: would be great to make this all really explicit in a MacOs subsection of getting started pathway.</p>
<pre><code class="lang-auto">conda create --prefix ./envs nomkl
conda activate ./envs
conda install pytorch torchvision torchaudio -c pytorch
conda install ipython ipykernel
</code></pre>
<p>Then:</p>
<blockquote>
<p>conda list|grep mkl<br>
mkl                       2022.0.0           hecd8cb5_105<br>
nomkl                     3.0                           0</p>
</blockquote>