Skip to content

Installation on Intel Silicon

Yamini Nimmagadda edited this page Jul 21, 2023 · 31 revisions

Stable Diffusion WebUI Support (Preview)

Stable Diffusion WebUI can now be run on hardware like Intel CPUs and GPUs (both integrated and discrete Graphics) with Intel® Distribution of OpenVINO™ toolkit. This is a preview support in active development and we actively welcome feedback and contributions from the community.

Instructions to run WebUI with OpenVINO:

OpenVINO support is provided through a custom script [Link to custom scripts]. The custom script uses PyTorch's torch.compile feature and HuggingFace Diffusers library for improved performance. Below are the instructions to get started:

  • If you are familiar with the Automatic1111 workflow, use this fork from OpenVINOToolKit instead of Automatic1111 and follow the instructions. Alternatively, follow the below instructions
python -m venv sd_env
source sd_env/bin/activate
git clone -b openvino_custom_scripts https://github.com/openvinotoolkit/stable-diffusion-webui.git
cd stable-diffusion-webui
  • Install the prerequisites by following the instructions here
  • Install OpenVINO in the same python environment by following the instructions here
  • Set the environment variable COMMANDLINE_ARGS to "--skip-torch-cuda-test --precision full --no-half" . To access WebUI through a public URL from a remote machine, add additional arguments to COMMANDLINE_ARGS "--listen --share"
  • Launch the WebUI by running webui.sh in Linux or webui-user.bat in windows
  • Use the OpenVINO custom script by following the instructions here

Installation Instructions

Prerequisites

Diffusers

We use the diffusers library for improved performance with torch.compile. The recommended version is >= v0.17.0. Diffusers can be installed from PyPi: pip install diffusers

PyTorch

OpenVINO is integrated as a TorchDynamo backend in PyTorch and can be leveraged using "torch.compile". TorchDynamo is available from PyTorch 2.0 onwards.

Linux:

Install PyTorch from PyPi using pip install torch

Windows:

PyTorch doesn't support torch.compile officially on windows yet. However, the below workaround can be used to leverage torch.compile feature on windows:

  • Install the validated PyTorch nightly wheel file (2.1.0.dev20230713) from here [Add instruction]
  • Update the file at <conda_env_root>/Lib/site-packages/torch/_dynamo/eval_frames.py
  • Find the function called "check_if_dynamo_supported()" which looks like this (line 484):
def check_if_dynamo_supported():
    if sys.platform == "win32":
        raise RuntimeError("Windows not yet supported for torch.compile")
    if sys.version_info >= (3, 11):
        raise RuntimeError("Python 3.11+ not yet supported for torch.compile")
  • Comment out the first two lines of this function. It should look like this:
def check_if_dynamo_supported():
    #if sys.platform == "win32":
    #    raise RuntimeError("Windows not yet supported for torch.compile")
    if sys.version_info >= (3, 11):
        `raise RuntimeError("Python 3.11+ not yet supported for torch.compile")

Install OpenVINO:

Install from Pypi:

OpenVINO with torch.compile support is now available in preview in the OpenVINO prerelease package (version: Add Version). Install from Pypi: pip install openvino-<version>

Build and install from source:

OpenVINO can also be built from source using the instructions provided here

Known Issues

  • Changing the sampling method to DPM++ or Karras methods seems to recompile the model due to some modifications it makes to the graph. It is recommended to exclude the time for first image generation for any performance measurements
Clone this wiki locally