Installing MKL and DNNL for PyTorch on Windows

Now, if you’ve ever tried to do this before, you know it can be a bit of a headache. But don’t freak out!

First off, what MKL and DNNL are in the first place. MKL stands for “Math Kernel Library”, which is a collection of optimized math functions that can be used with various programming languages like C++, Python, R, and more. It’s designed to improve performance by taking advantage of hardware acceleration (like Intel’s CPU or GPU) when possible.

DNNL, on the other hand, is a “Deep Neural Network Library” that provides optimized primitives for deep learning workloads. This means it can help you train and run your models faster than if you were using just PyTorch alone. And since MKL and DNNL are both open-source projects, they’re free to use!

So how do we install them on Windows? Well, first things first make sure you have the latest version of Python installed (we recommend using Anaconda for this). Then, head over to Intel’s website and download their MKL package. Once that’s done, open up a command prompt or terminal window and navigate to your PyTorch installation directory (usually something like C:\Program Files\Python38-32\Scripts).

Now, run the following commands:

# Install MKL for Python
pip install mkl-service # Installs the mkl-service package for Python

# Set up environment variables for DNNL and MKL (assuming you're using Anaconda)
conda config --set env_prefixes C:\anaconda3\envs # Sets the environment prefixes for Anaconda to the specified directory
conda create -n myenv python=3.8 anaconda # Creates a new environment named "myenv" with Python 3.8 and Anaconda packages
conda activate myenv # Activates the "myenv" environment
conda install mkl-service dnnl # Installs the mkl-service and dnnl packages in the "myenv" environment

That should do it! Now, whenever you start a new Python environment (using `conda create`) or activate your existing one (using `source activate myenv`), MKL and DNNL will be automatically loaded.

And that’s all there is to it! No more messing around with complicated installation scripts or trying to figure out why your models aren’t running as fast as they should be. With MKL and DNNL, you can enjoy the benefits of hardware acceleration without any extra hassle.

So go ahead give it a try and let us know how it works for you! And if you have any questions or suggestions, feel free to leave them in the comments below.

SICORPS