Skip to content

Commit b83c0a3

Browse files
authored
Merge branch 'main' into pipeline_marigold_intrinsics
2 parents 5a4196e + 64af74f commit b83c0a3

File tree

18 files changed

+340
-194
lines changed

18 files changed

+340
-194
lines changed

docs/source/en/_toctree.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,8 @@
551551
title: DDIMInverseScheduler
552552
- local: api/schedulers/ddim
553553
title: DDIMScheduler
554+
- local: api/schedulers/ddim_cogvideox
555+
title: CogVideoXDDIMScheduler
554556
- local: api/schedulers/ddpm
555557
title: DDPMScheduler
556558
- local: api/schedulers/deis
@@ -563,6 +565,8 @@
563565
title: DPMSolverSDEScheduler
564566
- local: api/schedulers/singlestep_dpm_solver
565567
title: DPMSolverSinglestepScheduler
568+
- local: api/schedulers/multistep_dpm_solver_cogvideox
569+
title: CogVideoXDPMScheduler
566570
- local: api/schedulers/edm_multistep_dpm_solver
567571
title: EDMDPMSolverMultistepScheduler
568572
- local: api/schedulers/edm_euler

docs/source/en/api/pipelines/flux.md

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,74 @@ image.save('flux_ip_adapter_output.jpg')
359359
<figcaption class="mt-2 text-sm text-center text-gray-500">IP-Adapter examples with prompt "wearing sunglasses"</figcaption>
360360
</div>
361361

362+
## Optimize
362363

363-
## Running FP16 inference
364+
Flux is a very large model and requires ~50GB of RAM/VRAM to load all the modeling components. Enable some of the optimizations below to lower the memory requirements.
365+
366+
### Group offloading
367+
368+
[Group offloading](../../optimization/memory#group-offloading) lowers VRAM usage by offloading groups of internal layers rather than the whole model or weights. You need to use [`~hooks.apply_group_offloading`] on all the model components of a pipeline. The `offload_type` parameter allows you to toggle between block and leaf-level offloading. Setting it to `leaf_level` offloads the lowest leaf-level parameters to the CPU instead of offloading at the module-level.
369+
370+
On CUDA devices that support asynchronous data streaming, set `use_stream=True` to overlap data transfer and computation to accelerate inference.
371+
372+
> [!TIP]
373+
> It is possible to mix block and leaf-level offloading for different components in a pipeline.
374+
375+
```py
376+
import torch
377+
from diffusers import FluxPipeline
378+
from diffusers.hooks import apply_group_offloading
379+
380+
model_id = "black-forest-labs/FLUX.1-dev"
381+
dtype = torch.bfloat16
382+
pipe = FluxPipeline.from_pretrained(
383+
model_id,
384+
torch_dtype=dtype,
385+
)
386+
387+
apply_group_offloading(
388+
pipe.transformer,
389+
offload_type="leaf_level",
390+
offload_device=torch.device("cpu"),
391+
onload_device=torch.device("cuda"),
392+
use_stream=True,
393+
)
394+
apply_group_offloading(
395+
pipe.text_encoder,
396+
offload_device=torch.device("cpu"),
397+
onload_device=torch.device("cuda"),
398+
offload_type="leaf_level",
399+
use_stream=True,
400+
)
401+
apply_group_offloading(
402+
pipe.text_encoder_2,
403+
offload_device=torch.device("cpu"),
404+
onload_device=torch.device("cuda"),
405+
offload_type="leaf_level",
406+
use_stream=True,
407+
)
408+
apply_group_offloading(
409+
pipe.vae,
410+
offload_device=torch.device("cpu"),
411+
onload_device=torch.device("cuda"),
412+
offload_type="leaf_level",
413+
use_stream=True,
414+
)
415+
416+
prompt="A cat wearing sunglasses and working as a lifeguard at pool."
417+
418+
generator = torch.Generator().manual_seed(181201)
419+
image = pipe(
420+
prompt,
421+
width=576,
422+
height=1024,
423+
num_inference_steps=30,
424+
generator=generator
425+
).images[0]
426+
image
427+
```
428+
429+
### Running FP16 inference
364430

365431
Flux can generate high-quality images with FP16 (i.e. to accelerate inference on Turing/Volta GPUs) but produces different outputs compared to FP32/BF16. The issue is that some activations in the text encoders have to be clipped when running in FP16, which affects the overall image. Forcing text encoders to run with FP32 inference thus removes this output difference. See [here](https://github.com/huggingface/diffusers/pull/9097#issuecomment-2272292516) for details.
366432

@@ -389,7 +455,7 @@ out = pipe(
389455
out.save("image.png")
390456
```
391457

392-
## Quantization
458+
### Quantization
393459

394460
Quantization helps reduce the memory requirements of very large models by storing model weights in a lower precision data type. However, quantization may have varying impact on video quality depending on the video model.
395461

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
the License. You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
specific language governing permissions and limitations under the License.
11+
-->
12+
13+
# CogVideoXDDIMScheduler
14+
15+
`CogVideoXDDIMScheduler` is based on [Denoising Diffusion Implicit Models](https://huggingface.co/papers/2010.02502), specifically for CogVideoX models.
16+
17+
## CogVideoXDDIMScheduler
18+
19+
[[autodoc]] CogVideoXDDIMScheduler
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
the License. You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
specific language governing permissions and limitations under the License.
11+
-->
12+
13+
# CogVideoXDPMScheduler
14+
15+
`CogVideoXDPMScheduler` is based on [DPM-Solver: A Fast ODE Solver for Diffusion Probabilistic Model Sampling in Around 10 Steps](https://huggingface.co/papers/2206.00927) and [DPM-Solver++: Fast Solver for Guided Sampling of Diffusion Probabilistic Models](https://huggingface.co/papers/2211.01095), specifically for CogVideoX models.
16+
17+
## CogVideoXDPMScheduler
18+
19+
[[autodoc]] CogVideoXDPMScheduler

0 commit comments

Comments
 (0)