Skip to main content

Enflame Stable Diffusion XL

How to run Stable Diffusion XL Model on Enflame GPU

1.0 Creating a Container Instance

  • Login to OpenCSG Compute Platform
  • Create an enfalme instance
  • Select image 出图Stable Diffusion XL(topsrider2.5.136-ubuntu20.04-py310)

1.1 Quick Start

# Download ONNX Model
git clone https://www.opencsg.com//models/xzgan/stable-diffusion-xl-base-1.0_onnx.git
# Inference
python -m stable_diffusion.examples.stable_diffusion_xl.demo_text2image_topsinference --model stable-diffusion-xl-base-1.0_onnx/1024x1024/ --platform general --gcu 0 --image_num 1 --prompt "draw a dragon" --negative_prompt "not black" --seed 1000 --denoising_steps 20 --image_height 1024 --image_width 1024 --output output

Only need to choose one between Step 1 and Step 2

2.0 Converte to ONNX

2.1. Converte

git clone https://www.opencsg.com//models/AIWizards/stable-diffusion-xl-base-1.0.git

nohup python3.10 /usr/local/lib/python3.10/dist-packages/stable_diffusion/scripts/stable_diffusion_xl/generate_onnx_engine.py --base_model stable-diffusion-xl-base-1.0 --vae_model sdxl-vae-fp16-fix --platform general --model_type sd_xl_base_1_0 --gcu 0 --refit_mode need_refit_engine --output_path stable-diffusion-xl-base-1.0_onnx --resolutions 1024x1024 --export_onnx > output.log 2>&1 &

2.2.SD_XL 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 1024x1024, 1024x768, 768x1024.

2.2.1. Text-to-Image Inference

python -m stable_diffusion.examples.stable_diffusion_xl.demo_text2image_topsinference --model stable-diffusion-xl-base-1.0_onnx/1024x1024/ --platform general --gcu 0 --image_num 1 --prompt "draw a dragon" --negative_prompt "not black" --seed 1000 --denoising_steps 20 --image_height 1024 --image_width 1024 --output output

2.2.2. Image-to-Image Inference

python -m stable_diffusion.examples.stable_diffusion_xl.demo_image2image_topsinference --model stable-diffusion-xl-base-1.0_onnx/1024x1024/ --platform general --gcu 0 --image_num 1 --prompt "draw a dragon" --negative_prompt "not black" --seed 3000 --denoising_steps 20 --image_height 1024 --image_width 1024 --init_image text2image_out/1000.png --strength 1.0 --output image2image_out

2.2.3. lora inference

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_xl.demo_text2image_topsinference --model stable-diffusion-xl-base-1.0_onnx/1024x1024/ --platform general --gcu 0 --image_num 1 --prompt "draw a dragon" --negative_prompt "not black" --seed 1000 --denoising_steps 20 --image_height 1024 --image_width 1024 --output output --lora pokemon:1.0