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

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 Anaconda user

This post uses Python distributed at the Microsoft Store. The following post describes the procedure in case of Anaconda 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
Python 3.10.10
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

Python


Python can be directly downloaded and installed from Microsoft Store. This time, install version "3.10". The version at this post is "3.10.10"

Although the latest one 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

www.microsoft.com

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 name of Python virtual environment is "myenv", its path will be

d:\2023\testrun\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 Windows Terminal (PowerShell). Especially execution of "demo.py" requires administrator privileges. Don't forget to run Terminal as Administrator.

Build environment


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

cd d:\2023\testrun\
python -m venv myenv
.\myenv\Scripts\Activate.ps1

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

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

Run the command with prompts the picture you want. "Example Text-To-Image" on "bes-dev/stable_diffusion.openvino" is

python demo.py --prompt "Street-art painting of Emilia Clarke in style of Banksy, photorealism"

After some downloads of models, it will output images as them.

The image at the top of this post is based on this command.

python demo.py --prompt "Stable Diffusion on 8GB Windows PC, no GPU, no container"

They were output around 10min.