The Intel® Extension for PyTorch* provides optimizations and features to improve performance on Intel® hardware. It provides easy GPU acceleration for Intel discrete GPUs via the PyTorch “XPU” device. This allows users to run PyTorch models on computers with Intel® GPUs and Windows* using Docker* Desktop and WSL2.
One of Docker’s key benefits is that it simplifies the installation process. It takes care of all the necessary steps, including installing the oneAPI graphics runtime, PyTorch dependencies, and any other required libraries. This makes the process of getting up and running with PyTorch models on Intel GPUs easy and efficient.
To demonstrate, we will run a popular AI text-to-image model with stable diffusion on Windows using Intel® Arc™ GPUs.
Setup
Prerequisites
If you want to follow along, please ensure that your Windows computer has the latest Intel Arc GPU drivers and that your Intel GPU is listed in the Windows Device Manager:
Enable Docker Desktop with WSL2
We will use Docker Desktop with WSL2, so ensure your computer has WSL2 enabled. You can check using the following command:
Now that we have WSL2 up and running, Install Docker Desktop for Windows and reboot.
After reboot, Docker Desktop will start automatically. You can run a simple “hello world” container to verify that it’s properly enabled with WSL2:
Running PyTorch Models on Windows with Intel Arc GPUs
The official containers for Intel Extension for PyTorch are accessible on Docker Hub. They are equipped with all the necessary components, including the Intel® Graphics runtime, oneAPI, and any dependencies required to run on Intel Arc GPUs. If the container is not stored locally, Docker can easily retrieve it from Docker Hub and launch it immediately.
Before we run the container for Stable Diffusion, it is recommended to download the offline stable diffusion model. Please first install git for windows if you don’t have it in your system yet.
You may encounter a hangup sometimes as the cloning command for the Hugging Face repository cannot exit cleanly after downloading the code. In this case, please press Ctrl+C for a force exit.
Next, run the container as follows:
We are exposing port 9999 for our Jupyter* notebook and the “data” folder where we previously downloaded the Stable Diffusion offline model. This allows us to reuse the model in future runs.
Inside the container prompt, we can first check if the Intel Arc GPU is detected by Intel Extension for PyTorch and enable the Jupyter notebook for remote access at port 9999:
Sample output for above commands is shown here for reference:
Open the Jupyter notebook in your browser using the URL from output, and run Stable Diffusion using Intel Arc GPUs:
Sample output is shown here for reference:
We can now load the model and run some sample text-to-image queries:
You can similarly run any other PyTorch model(s) on Windows WSL2 and Intel Arc GPUs using this approach.
Get the Software
We encourage you to check out Intel’s other AI Tools and Framework optimizations and learn about the open, standards-based oneAPI multiarchitecture, multivendor programming model that forms the foundation of Intel’s AI software portfolio.
For more details about 4th Gen Intel Xeon Scalable processor, visit AI Platform where you can learn about how Intel is empowering developers to run high-performance, efficient end-to-end AI pipelines.