How to use xformers to reduce the generation time of Stable Diffusion

  • It takes a long time to generate illustrations with Stable Diffusion
  • Is there a way to make it move more smoothly?
  • I want to make more illustrations faster!

We will answer these questions for you.

How to use xformers to reduce the generation time of Stable Diffusion
How to use xformers to reduce the generation time of Stable Diffusion

How to use xformers to reduce the generation time of Stable Diffusion

Many people would like to reduce the illustration generation time of Stable Diffusion. The long generation time means that the number of illustrations that can be created is reduced accordingly.

AI illustrations have a strong gacha element, so generation speed is important to increase the probability of getting the illustrations you like.

In this article, I'm going to explain these things :

  • What is xformers: An option that speeds up Stable Diffusion illustration generation
  • [Read before introduction] 3 points to note when accelerating Stable Diffusion with xformers
  • [Speeding up] How to introduce xformers to reduce the generation time of Stable Diffusion
  • Generation speed nearly doubled after introducing xformers
  • If you want to generate illustrations more smoothly...
  • How to easily manage a large number of generated illustrations

I'm going to explain these things, so by the end, you'll find out how to speed up Stable Diffusion generation and reduce the time it takes.

If you are a beginner or have any questions about Stable Diffusion, please read the following articles. It explains in detail how to download and use Stable Diffusion.

>> [Complete Beginner's Guide] Thorough explanation of how to use Stable Diffusion!

What is xformers: An option that speeds up illustration generation

What is xformers
What is xformers
Many of you may have heard the word "xformers" for the first time.


The Xformers library is an optional way to speed up image generation (translated by Chrome).


The great advantage of xformers is that it not only speeds up generation but also reduces VRAM usage. I would definitely like to make use of it.

Originally Stable Diffusion has a function called xformers, but it is disabled by default. The purpose of this article is to say, "If enabled, illustration generation will be faster."

Some people may think, "If it's such a useful function, just enable it from the beginning." Not all grabbers are supported, and there are disadvantages.

Before introducing xformers, I would like to understand the points to note.

Three points to note when accelerating Stable Diffusion with xformers :


Although xformers is enabled, there are three points to note as follows.
  • Illustration generation results are inconsistent (apparently)
  • There are environments where xformers cannot be used
  • Gravo's performance difference is overwhelmingly larger
I will explain in order.

Illustration generation results are inconsistent (apparently)

It seems that with xformers enabled, the results can be inconsistent when generating illustrations with Stable Diffusion.


There is a new xformers optimization that prevents generating the same image given the same parameters for generation (translated by Chrome).

There is a description :

Contents that different illustrations are generated even if the same illustration should be output, such as matching the seed value.


There is also a screenshot of the reporter on the relevant page , so if you are interested, please take a look.

(Although not in the screenshot) There were some things that actually turned out to be completely different images.

There was also a write-up, so when I was generating it, I thought, 'Huh? ’, you may think.

In such a case, I would be honored if you could remember this article and come up with the possibility that "xformers may be the cause". Disabling xformers is easy and should be a quick fix.

There are environments where xformers cannot be used

Gravo you are using :
  • too old
  • Has a non-NVIDIA GPU (e.g. Radeon)
If this applies, it will not be subject to speedup by xformers (source: official page of Web UI (AUTOMATIC1111) ).

The "too old Grabo" case should not be considered. In the first place, it has the specs to run Stable Diffusion.

On the other hand, it's a disappointing result for those using AMD's Radeon series and MacBook. If you are going to add or replace, we recommend a Grabo equipped with an NVIDIA GPU.

Also, even if there is no problem with the graphics board, how much xformers speed up depends on your environment (other parts, etc.). I was able to experience the speedup, but please understand that you may not necessarily get the same results.

[Speeding up] How to use xformers to reduce the generation time of Stable Diffusion

How to use xformers to reduce the generation time of Stable Diffusion
How to use xformers to reduce the generation time of Stable Diffusion

It is recommended to back up "webui-user.bat" before enabling xformers. It worked fine in my environment, but an error may occur depending on the environment. Also, future updates may cause unexpected problems.


Specifically, the batch file "webui-user.bat" to be edited (that you always click when starting Stable Diffusion)

It would be nice to copy and paste like this.

Now let's enable xformers. Right-click this "webui-user.bat" and select Edit.
This should open a window in Notepad :
Let's write " -xformers " to the right of the string "set COMMANDLINE_ARGS=".

If you have already entered a command in the "set COMMANDLINE_ARGS=" line, enter "-xformers" after inserting a half-width space.

Once you have completed the entry, close Notepad with File → Overwrite and you are done. Let's start Stable Diffusion while praying that there will be no errors.

Installing xformers
Installing xformers

If "Installing xformers" is displayed at startup, xformers is properly installed. Thank you for your hard work.

Generation speed nearly doubled after introducing xformers :


As explained in the notes section, in my environment (when using RTX 3060), it took about 8 seconds to generate one illustration.

When I generated the illustration under the same conditions after enabling xformers, the generation time was 4.5 seconds! It was a very happy result that the speed was almost doubled.

By all means, please enable xformers and generate illustrations more quickly than ever before.
Next Post Previous Post
No Comment
Add Comment
comment url