text stringlengths 0 5.54k |
|---|
slice_size (str or int, optional, defaults to "auto") — |
When "auto", halves the input to the attention heads, so attention will be computed in two steps. If |
"max", maximum amount of memory will be saved by running only one slice at a time. If a number is |
provided, uses as many slices as attention_head_dim // slice_size. In this case, attention_head_dim |
must be a multiple of slice_size. |
Enable sliced attention computation. |
When this option is enabled, the attention module will split the input tensor in slices, to compute attention |
in several steps. This is useful to save some memory in exchange for a small speed decrease. |
disable_attention_slicing |
< |
source |
> |
( |
) |
Disable sliced attention computation. If enable_attention_slicing was previously invoked, this method will go |
back to computing attention in one step. |
enable_xformers_memory_efficient_attention |
< |
source |
> |
( |
attention_op: typing.Optional[typing.Callable] = None |
) |
Parameters |
attention_op (Callable, optional) — |
Override the default None operator for use as op argument to the |
memory_efficient_attention() |
function of xFormers. |
Enable memory efficient attention as implemented in xformers. |
When this option is enabled, you should observe lower GPU memory usage and a potential speed up at inference |
time. Speed up at training time is not guaranteed. |
Warning: When Memory Efficient Attention and Sliced attention are both enabled, the Memory Efficient Attention |
is used. |
Examples: |
Copied |
>>> import torch |
>>> from diffusers import DiffusionPipeline |
>>> from xformers.ops import MemoryEfficientAttentionFlashAttentionOp |
>>> pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1", torch_dtype=torch.float16) |
>>> pipe = pipe.to("cuda") |
>>> pipe.enable_xformers_memory_efficient_attention(attention_op=MemoryEfficientAttentionFlashAttentionOp) |
>>> # Workaround for not accepting attention shape using VAE for Flash Attention |
>>> pipe.vae.enable_xformers_memory_efficient_attention(attention_op=None) |
disable_xformers_memory_efficient_attention |
< |
source |
> |
( |
) |
Disable memory efficient attention as implemented in xformers. |
enable_model_cpu_offload |
< |
source |
> |
( |
gpu_id = 0 |
) |
Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared |
to enable_sequential_cpu_offload, this method moves one whole model at a time to the GPU when its forward |
method is called, and the model remains in GPU until the next model runs. Memory savings are lower than with |
enable_sequential_cpu_offload, but performance is much better due to the iterative execution of the unet. |
enable_sequential_cpu_offload |
< |
source |
> |
( |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.