Two conda installs with vastly different pytorch performance

deepbrain: <p>I have two anaconda python installs - the older anaconda install runs my network 2-3x faster than the newer install. The pytorch is compiled from sources with identical options.  Both installs run on the same machine and have seemingly  the same packages installed with slightly different versions. I cant’t figure out why one of the conda installs is much more CPU intensive. The CPU on a slower install runs at 600-700% utilization while on a faster install it runs at 160% utilization. I could include the package lists and compile logs, but they are very large.</p>
<p>Does anyone have any ideas why it could behave like this?</p>
<p>I am curious what could be the reason of the slowdown.</p>

SimonW: <p>Try ldd and see which blas they bind to.</p>

deepbrain: <p>Thank you, this helped a lot! The faster version was using openblas while the slower used the MKL. The new conda by default uses the MKL. Once I run "conda install nomkl "on the MKL version to remove the MKL, the performance increased 2x and the CPU utilization dropped 5x. I wonder why would the default MKL version in conda be much slower than the openblas?</p>

SimonW: <p>Are you happening to use AMD CPUs by any chance?</p>

deepbrain: <p>Actually I used a variety of Intel CPUs: 3 or 4 Intel i7 Gen 6,7, and 8. I used Cuda 8.0, 9.0, 9.1, cudnn 7.0, 7.1 and Nvidia GTX 1080ti GPUs. In all cases the GPUs are all severely underutilized when MKL is used. If I switch to openblas, the performance improves.</p>
<p>I know that MKL is supposed to be faster than openblas, but in all instances I get much slower performance with pytorch - CPU usage spikes 3-5x and GPU utilization drops 2-3x. This is counter intuitive and I spent a lot of time trying to figure it out. Could it be a bug?</p>

colesbury: <p>Try adjusting the environment variable <code>OMP_NUM_THREADS</code> which affects the number of threads used by MKL (and usually OpenBLAS) for parallel workloads. The default is the number of virtual CPUs which is often too high on multi-core multi-socket systems. Try setting it to half the number of vCPUs or even fewer.</p>
<p>For example:</p>
<p><code>OMP_NUM_THREADS=8 python myscript.py</code></p>

deepbrain: <aside class="quote no-group" data-username="colesbury" data-post="6" data-topic="17706">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/colesbury/48/26_2.png" class="avatar"> colesbury:</div>
<blockquote>
<p>OMP_NUM_THREADS=8</p>
</blockquote>
</aside>
<p>Thank you! After some experimenting, I get almost the same speeds with the MKL. OMP_NUM_THREADS=1 or 2 works best for me. The default setting slows it a lot. I wonder why would the OMP_NUM_THREADS be too high by default? My setup could be specific to my research, but it seems that it could be slowing other jobs too. I guess with cuda and cudnn, MKL takes on very small chunks of data and if you split it in many threads, the thread setup overhead is killing the job.</p>

Zhang_Chi: <aside class="quote no-group" data-username="SimonW" data-post="2" data-topic="17706">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/simonw/48/1702_2.png" class="avatar"> SimonW:</div>
<blockquote>
<p>ldd and see which blas they bind to.</p>
</blockquote>
</aside>
<p>hi   how do you use ldd to check which blas they bind to?  what the command looks like?</p>