Diffusers documentation

Installing xFormers

You are viewing v0.18.2 version. A newer version v0.31.0 is available.
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Installing xFormers

We recommend the use of xFormers for both inference and training. In our tests, the optimizations performed in the attention blocks allow for both faster speed and reduced memory consumption.

Starting from version 0.0.16 of xFormers, released on January 2023, installation can be easily performed using pre-built pip wheels:

pip install xformers

The xFormers PIP package requires the latest version of PyTorch (1.13.1 as of xFormers 0.0.16). If you need to use a previous version of PyTorch, then we recommend you install xFormers from source using the project instructions.

After xFormers is installed, you can use enable_xformers_memory_efficient_attention() for faster inference and reduced memory consumption, as discussed here.

According to this issue, xFormers v0.0.16 cannot be used for training (fine-tune or Dreambooth) in some GPUs. If you observe that problem, please install a development version as indicated in that comment.