Skip to main content

Enflame Stable Diffusion

How to run Stable Diffusion Model on Enflame GPU

1.0 Creating a Container Instance

  • Login to OpenCSG Compute Platform
  • Create an enfalme instance
  • Select image 出图Stable Diffusion(topsrider2.4.136-ubuntu20.04-py38-sd)

1.1 Quick Start

# Download ONNX Model
git clone --depth 1 https://www.opencsg.com//models/xzgan/stable-diffusion-2-1_onnx.git
# Inference
python -m stable_diffusion.examples.stable_diffusion.demo_text2image_topsinference --model stable-diffusion-2-1_onnx/768x768/ --image_num 5 --prompt "king kong in city" --negative_prompt "nsfw" --output ./output --model_type sd_v2_1 --image_height 768 --image_width 768 --platform general --scheduler dpm2 --denoising_steps 20 --seed 1111111 --gcu 0

Only need to choose one between Step 1 and Step 2

2.0 Converte to ONNX

2.1. Converte

# Download Model
git clone --depth 1 https://www.opencsg.com//models/AIWizards/stable-diffusion-v1-5.git
# Converte
nohup python /usr/local/lib/python3.8/dist-packages/stable_diffusion/scripts/stable_diffusion/generate_onnx_engine.py --model stable-diffusion-v1-5 --output_path stable-diffusion-v1-5_onnx --model_type sd_v1_5 --resolutions 512x512,680x512,512x680,1024x576,576x1024 --export_onnx --gcu 0 > output.log 2>&1 &

2.2.0 SD-1.5 Inference Test

-1: The generated image is saved in the directory defined by -output. The name is $see.png, where $seed is a random number seed. -2: Supported 1024x576, 512 x1024, 512 x512, 512 x680, 576 x1024, 680 x512.

2.2.1. Text to Image Inference

python -m stable_diffusion.examples.stable_diffusion.demo_text2image_topsinference --model stable-diffusion-v1-5_onnx/512x512/ --image_num 6 --prompt "Tyrannosaurus Rex in virgin forest" --negative_prompt "nsfw" --output ./output  --model_type sd_v1_5 --image_height 512 --image_width 512 --platform general --scheduler dpm2 --denoising_steps 20 --seed 1441787169 --gcu 0

2.2.2. inference with lora

create lora directory

mkdir -p pokemon/unet

copy lora model and copy to pokemon/unet/adapter_model.safetensors

copy xxx.safetensors pokemon/unet/adapter_model.safetensors

inference with lora

python -m stable_diffusion.examples.stable_diffusion.demo_text2image_topsinference --model stable-diffusion-v1-5_onnx/512x512/ --image_num 6 --prompt "Tyrannosaurus Rex in virgin forest" --negative_prompt "nsfw" --output ./output  --model_type sd_v1_5 --image_height 512 --image_width 512 --platform general --scheduler dpm2 --denoising_steps 20 --seed 1441787169 --gcu 0 --lora pokemon:1.0

3.1 SD-2.1

# Download
git clone --depth 1 https://www.opencsg.com//models/AIWizards/stable-diffusion-2-1.git
# Converte
python /usr/local/lib/python3.8/dist-packages/stable_diffusion/scripts/stable_diffusion/generate_onnx_engine.py --model stable-diffusion-2-1 --output_path stable-diffusion-2-1_onnx --model_type sd_v2_1 --resolutions 512x512,680x512,512x680,1024x576,576x1024 --export_onnx --gcu 1
# Inference
python -m stable_diffusion.examples.stable_diffusion.demo_text2image_topsinference --model stable-diffusion-2-1_onnx/1024x1024/ --image_num 16 --prompt "侏罗纪镰刀龙大战异特龙" --negative_prompt "nsfw" --output ./output --model_type sd_v2_1 --image_height 1024 --image_width 1024 --platform general --scheduler dpm2 --denoising_steps 20 --seed 1111111