DEV Community

Cover image for Use Stable Diffusion openvino with poetry

Posted on

Use Stable Diffusion openvino with poetry

Photo by Andrea De Santis on Unsplash

If you use social media, you may see an image or images generated by machine learning technology recently.

You can use DALLE 2 for free, but you may need to wait for a month maybe more.

Then recently another one has been released. That is Stable Diffusion. It is pretty similar to DALLE 2. If you give text and some parameters, it generates pretty nice image. You can use Stable Diffusion without waiting for a month which is super nice, right? However, it requires a GPU. If you don't have a GPU or cannot access to a GPU probably you 😭 (What am I supposed to do?)

About Stable Diffusion

GitHub logo CompVis / stable-diffusion

A latent text-to-image diffusion model

Stable Diffusion

Stable Diffusion was made possible thanks to a collaboration with Stability AI and Runway and builds upon our previous work:

High-Resolution Image Synthesis with Latent Diffusion Models
Robin Rombach* Andreas Blattmann* Dominik Lorenz Patrick Esser, Björn Ommer
CVPR '22 Oral | GitHub | arXiv | Project page

txt2img-stable2 Stable Diffusion is a latent text-to-image diffusion model. Thanks to a generous compute donation from Stability AI and support from LAION, we were able to train a Latent Diffusion Model on 512x512 images from a subset of the LAION-5B database. Similar to Google's Imagen, this model uses a frozen CLIP ViT-L/14 text encoder to condition the model on text prompts. With its 860M UNet and 123M text encoder, the model is relatively lightweight and runs on a GPU with at least 10GB VRAM. See this section below and the model card.


A suitable…

Then you can try stable_diffusion.openvino. You don't need a GPU to run this!!!


Implementation of Text-To-Image generation using Stable Diffusion on Intel CPU or GPU.


  • Linux, Windows, MacOS
  • Python <= 3.9.0
  • CPU or GPU compatible with OpenVINO.

Install requirements

  • Set up and update PIP to the highest version
  • Install OpenVINO™ Development Tools 2022.3.0 release with PyPI
  • Download requirements
python -m pip install --upgrade pip
pip install openvino-dev[onnx,pytorch]==2022.3.0
pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

Generate image from text description

usage: [-h] [--model MODEL] [--device DEVICE] [--seed SEED] [--beta-start BETA_START] [--beta-end BETA_END] [--beta-schedule BETA_SCHEDULE]
               [--num-inference-steps NUM_INFERENCE_STEPS] [--guidance-scale GUIDANCE_SCALE] [--eta ETA] [--tokenizer TOKENIZER] [--prompt PROMPT] [--params-from PARAMS_FROM]
               [--init-image INIT_IMAGE] [--strength STRENGTH] [--mask MASK] [--output OUTPUT]
optional arguments:
  -h, --help            show this help message and exit
  --model MODEL         model name
  --device DEVICE       inference device [CPU, GPU]
  --seed SEED           random seed for generating consistent images per prompt
  --beta-start BETA_START
  --beta-end BETA_END   LMSDiscreteScheduler::beta_end
  --beta-schedule BETA_SCHEDULE
  --num-inference-steps NUM_INFERENCE_STEPS
                        num inference steps
  --guidance-scale GUIDANCE_SCALE
                        guidance scale
  --eta ETA
Enter fullscreen mode Exit fullscreen mode

The readme is very straightforward, so probably you won't have any issues to run the and try a python script for streamlit.

However, there might be an issue if you use python already with python version manager and anaconda or etc.

Then, you can use poetry to avoid messing up and keep your python dev env clean.

install poetry

There are 2 ways to install poetry.

  1. using pip
  2. using curl


Create a project folder

$ poetry new poetry-stable-diffusion
Enter fullscreen mode Exit fullscreen mode

Install packages

$ poetry add package_name@package_version
Enter fullscreen mode Exit fullscreen mode

However, you don't need to do this. You can use the following pyproject.toml I tested already.

In this case, I used python 3.8.12.
If you don't have python 3.8, I highly recommend you to install it with [pyenv](

name = "stablediffusion"
version = "0.1.0"
description = "test Stable Diffusion"
authors = ["koji"]

python = "^3.8"
numpy = "1.19.5"
transformers = "4.16.2"
diffusers = "0.2.4"
tqdm = "4.64.0"
openvino = "2022.1.0"
huggingface-hub = "0.9.0"
streamlit = "1.12.0"
watchdog = "2.1.9"
opencv-python = ""
scipy = "1.6.1"


requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Enter fullscreen mode Exit fullscreen mode

What you need to do set up the env is to run one command!

$ poetry install
Enter fullscreen mode Exit fullscreen mode

Clone repo

$ git clone
$ cd stable_diffusion.openvino
Enter fullscreen mode Exit fullscreen mode


$ poetry run python --prompt "cyberpunk New York City"
Enter fullscreen mode Exit fullscreen mode

generated image

cyberpunk new york city

The generating process will take a few minutes (in my case it takes around 3 minutes)

my mac spec

$ system_profiler SPHardwareDataType

    Hardware Overview:

      Model Name: MacBook Pro
      Model Identifier: MacBookPro16,1
      Processor Name: 8-Core Intel Core i9
      Processor Speed: 2.3 GHz
      Number of Processors: 1
      Total Number of Cores: 8
      L2 Cache (per Core): 256 KB
      L3 Cache: 16 MB
      Hyper-Threading Technology: Enabled
      Memory: 16 GB
      System Firmware Version: 1916. (iBridge: 20.16.365.5.4,0)
      OS Loader Version: 564.
      Serial Number (system): C02CP2ESMD6Q
      Hardware UUID: FFCE331E-4543-5DBE-8F98-E329E0A69F91
      Provisioning UDID: FFCE331E-4543-5DBE-8F98-E329E0A69F91
      Activation Lock Status: Disabled
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

starkraving profile image
Mike Ritchie

Just set this up yesterday in fact!

On my Mac it takes about 3 minutes to generate an image. Brand new feature released now allows you to supply a starter image, and it now comes with a web interface to make things easier. Only 512px x 512px at the moment, but arguments for height and width are on his roadmap.

Considering how new this project is, he’s done an amazing job!

0xkoji profile image

Yeah agree!