Technically Impossible

Lets look at the weak link in your statement. Anything "Technically Impossible" basically means we haven't figured out how yet.

Stable Diffusion on Windows PC with 8GB RAM, No GPU, No Container - case of Anaconda

2023-05-06

To a person needs GUI

Solution in this post doesn't provide GUI. If GUI is required, recommend to install as GIMP plugin. The next post introduces its how-to.
FYI, regardless of with or without GUI, time for image output has no change.

impsbl.hatenablog.jp

To user of Python, not Anaconda

This post uses Anaconda, not normal Python. The following post describes the procedure in case of normal Python instead. If you are interested, please refer to it.
impsbl.hatenablog.jp

Abstract

Running "AI" on PC requires rich computational resources as GPU with VRAM, and storage for its model. "bes-dev/stable_diffusion.openvino"*1 made running Stable Diffusion on poor consumer PC.

This post introduce how to run it on Windows PC only with 8GB RAM without GPU, and its performance. Even Microsoft Surface Pro 4 with specs below can run and output a single image per 10~12min.

OS Windows 11 Pro 22H2
CPU Intel Core i7-6650U
RAM 8GB
Storage SSD: 256GB
SD card: 32GB (D drive in this post)

Container and WSL are not used in this post. On limited resource environment, it is better run SDOV directly than to use them. Actually, SDOV can run stably even on a PC with RAM=8GB.

Computational resource assignment is done by Windows OS to them, and it sometime causes OOM kill, which a process is killed forcibly due to out of memory. Although there are workaround to avoid it, they are not recommended.

You should not try to circumvent these safeguards by manually setting --oom-score-adj to an extreme negative number on the daemon or a container, or by setting --oom-kill-disable on a container.

Runtime options with Memory, CPUs, and GPUs | Docker Documentation

Tools

To proceed the work below, following tools are required. "version" is the one in this post.

version
Visual Studio 2022 17.5.1
Anaconda 3.9
GitHub Desktop
Git command
3.2.0
Visual Studio and C++ build tools

C++ builder is required to install Python packages. This tool is included in Visual Studio, or "Build Tools for Visual Studio". In advance of starting procedure below, one of both must be installed with appropriate options.

In case of Visual Studio, access the next menu item, and install "Desktop development with C++" with default options.

Tools > Get Tools and Features...

visualstudio.microsoft.com

Anaconda

www.anaconda.com
If this is the initial installation, don't forget to run next command on "Anaconda Powershell Prompt (anaconda3)".

conda update conda -y
cond aupdate anaconda -y


At the moment of this post, Anaconda provides Python 3.9.16. Although the latest Python is version 3.11, it has not been supported by Intel OpenVINO*2 yet. The next version of OpenVINO may support 3.11.

Python 3.11 is in progress and will be available in 2023.0 release.

Failed install - following step by step instructions - no requirements of Python mentioned upfront. It fails on Python 3.11 · Issue #15287 · openvinotoolkit/openvino · GitHub

GitHub Desktop or Git command

This is required to download "bes-dev/stable_diffusion.openvino" (hereinafter SDOV). If Git command is not available, download and install GitHub Desktop.
desktop.github.com

Folders

In this post, all works are done under the next folder. Call this folder as "project folder" in this post.

d:\2023\testrun\

If the Anaconda is installed at "d:\myapp\anaconda3\", its Python virtual environment is hosted under the "envs" folder there. If the name of this project environment is "myenv", its path will be

d:\myapp\anaconda3\envs\myenv\

and cloned SDOV will be downloaded under the next folder. Call this folder "SDOV folder" in this post.

d:\2023\testrun\stable_diffusion.openvino\

Images are also output there as

d:\2023\testrun\stable_diffusion.openvino\output.png

If the same named flle is existed, it is overwritten.

"bes-dev/stable_diffusion.openvino"

Use GitHub Desktop to clone (download) SDOV,

or run the next command at the project folder. The folder of SDOV is automatically created.

git clone https://github.com/bes-dev/stable_diffusion.openvino

Edit requirements.txt

"requirements.txt" under SDOV folder specifies certain versions of required Python packages. To avoid dependency mismatching, update this file to

  • use latest numpy
  • add "openvino-dev"
  • use scipy older than version 1.9.0

🔎Descriptions of new "requirements.txt"

diffusers==0.2.4
ftfy==6.1.1
huggingface_hub==0.9.0
numpy
opencv-python==4.5.5.64
openvino==2022.3.0
openvino-dev[onnx,pytorch]==2022.3.0
piexif==1.1.3
pillow==9.0.1
scipy<1.9.0
streamlit_drawable_canvas==0.9.1
streamlit==1.12.0
tqdm==4.64.0
transformers==4.16.2
watchdog==2.1.9

Administrator privileges


Command operation from here is performed on "Anaconda Powershell Prompt (anaconda3)". Especially execution of "demo.py" requires administrator privileges. Don't forget to run it as Administrator.

Build environment

Run next commands to enter the project folder, create Python virtual environment "myenv", and enter there.

cd d:\2023\testrun\
conda create -n myenv python=3.9 -y
conda activate myenv

In Anaconda, mixed usage of "conda" and "pip" together is not recommended*3. One best practice is to use only either one. In this post, use only "pip" to install Python packages.

Run next commands to enter the SDOV folder and install required packages.

cd .\stable_diffusion.openvino\
pip install -r ./requirements.txt
Run Stable Diffusion

Run the command with prompts the picture you want.

python demo.py --seed 1 --num-inference-steps 18 --prompt "Emilia Clarke in style of MuCha"
python demo.py --seed 1 --num-inference-steps 18 --prompt "Emilia Clarke in style of Utamaro"
python demo.py --seed 1 --num-inference-steps 18 --prompt "Emilia Clarke in style of MuCha and Utamaro"

The default value of "num-inference-steps" is 32. To make processing time shorter, inference step is reduced this time. After some downloads of models, it will output images as them.

Starting with small inference number to catch direction earlier, and go deeper if it is ok. To reproduce a common inference deeper, set the seed number and reuse it.

python demo.py --seed 1 --num-inference-step 6 --prompt "AI painter in style of MuCha"
python demo.py --seed 1 --prompt "AI painter in style of MuCha"

6 x inference for 2 min outputs the 1st image, and 32 x inference for 8 min outputs the 2nd one. The woman becomes more MuCha with deeper inference.