Giter Club home page Giter Club logo

fastsdxl's Introduction

FastSDXL

This is an efficient implementation of Stable-Diffusion-XL. I make the following improvements:

  • Reconstruct the architecture of UNet. This UNet implementation is faster than others (Diffusers, Fooocus, etc.). If you are interested in this implementation, please see FastSDXL/BlockUNet.py. The source code of this UNet is short and easy to understand. You can also use this component in your own projects.
  • Use a trainable scheduler named OLSS. The implementation of OLSS is based on this project. I find this scheduler can improve the quality of generated images with given steps but we need to train it first (the training process requires a few minutes). To synthesize images with a specific style, OLSS is a good choice.

Usage

The code is headless. I developed this project based on diffusers==0.21.3. If you find it cannot run with another version of diffusers, please open an issue and tell me.

pip install diffusers safetensors torch gradio

To launch a webui without OLSS scheduler, please run the following command.

python launch_without_olss.py

To train an OLSS scheduler, please see run_olss.py for more details.

I trained an OLSS scheduler with the style of "Slightly Cinematic". You can use it by running the following command.

python launch_with_olss.py

Efficiency of the reconstructed UNet

I tested my code using NVidia 3060 laptop (6G, 85W). The resolution is 1024*1024, and the model is converted to float16 format.

  • Diffusers: CUDA out of memory
  • Fooocus: 1.78s/it
  • FastSDXL (ours): 1.17s/it

Performance of OLSS scheduler

Here are some examples of OLSS.

Prompt template: cinematic still {prompt}. emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy Negative prompt: anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured

  • a young girl, black hair, white clothes, in a garden, the background is red and white flowers

In the image generated by OLSS, the details of flowers on the right are more realistic.

DDIM DPM OLSS
ddim dpmsolver olss
  • a forest in spring, birds

More birds.

DDIM DPM OLSS
ddim dpmsolver olss
  • an orange cat and a pink ball on a white sofa

In this example, the image generated by OLSS is completely different with others.

DDIM DPM OLSS
ddim dpmsolver olss
  • a robot, with blue lightsaber, in a city

Sometimes OLSS can modify the composition and fix the composition error.

DDIM DPM OLSS
ddim dpmsolver olss

fastsdxl's People

Contributors

artiprocher avatar

Stargazers

 avatar  avatar  avatar  avatar ChuRuaNho avatar zhaolion avatar  avatar  avatar Weilong Chen avatar  avatar Vadim Kulibaba avatar  avatar  avatar Richard Tseng avatar Ye Bai avatar YANHONG ZENG avatar Shivank Saxena avatar  avatar Shiqi Mei avatar Rick_Cao avatar  avatar fan avatar 42lux avatar 张驰 avatar william avatar 子龙 avatar Asa Louis avatar  avatar Crosstyan avatar  avatar  avatar _._._.. avatar licyk avatar Moon avatar  avatar elucida avatar For-My-Heart avatar  avatar  avatar  avatar blender avatar ZihengWu avatar Nauman Mustafa avatar simongao avatar  avatar

Watchers

 avatar

fastsdxl's Issues

Some examples of OLSS

Here are some examples of OLSS.

Prompt template: cinematic still {prompt}. emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy
Negative prompt: anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured

  • a young girl, black hair, white clothes, in a garden, the background is red and white flowers

In the image generated by OLSS, the details of flowers on the right are more realistic.

DDIM DPM OLSS
ddim dpmsolver olss
  • a forest in spring, birds

More birds.

DDIM DPM OLSS
ddim dpmsolver olss
  • an orange cat and a pink ball on a white sofa

In this example, the image generated by OLSS is completely different with others.

DDIM DPM OLSS
ddim dpmsolver olss
  • a robot, with blue lightsaber, in a city

Sometimes OLSS can modify the composition and fix the composition error.

DDIM DPM OLSS
ddim dpmsolver olss

linux上测试没有加速,反而更慢

是否有在linux上测试过了,我在linux上测试,显卡为3090,使用fastsdxl里的launch_without_olss.py测试运行:

相同的默认参数情况下:

使用重构的unet:平均耗时约为 2.88 it/s

注释掉代码中以下三行替换重构unet的代码,使用原版的unet
block_unet = BlockUNet().half().to("cuda")
block_unet.from_diffusers(state_dict=pipe.unet.state_dict())
pipe.unet = block_unet
平均耗时约为 3.02 it/s

原版的unet速度反而更快
ps:diffusion库(版本相同)似乎在windows和linux上有所差异
windows上迭代输出单位是 s/it , 而linux上则是 it/s

关于加速和生成质量

加速是因为重构的unet,重构的unet和原版的unet在生成效果上是否是一致的呢?(相同条件下,仅替换重构的unet,生成图像是否一样)
olss采样器是否比其他采样器速度更快,是否也起到加速作用呢?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.