Skip to content

Commit c89c318

Browse files
authored
Merge branch 'main' into lora-load-adapter
2 parents c28d6f3 + 09b8aeb commit c89c318

File tree

57 files changed

+8034
-144
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+8034
-144
lines changed

.github/workflows/ssh-runner.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ on:
44
workflow_dispatch:
55
inputs:
66
runner_type:
7-
description: 'Type of runner to test (aws-g6-4xlarge-plus: a10 or aws-g4dn-2xlarge: t4)'
7+
description: 'Type of runner to test (aws-g6-4xlarge-plus: a10, aws-g4dn-2xlarge: t4, aws-g6e-xlarge-plus: L40)'
88
type: choice
99
required: true
1010
options:
1111
- aws-g6-4xlarge-plus
1212
- aws-g4dn-2xlarge
13+
- aws-g6e-xlarge-plus
1314
docker_image:
1415
description: 'Name of the Docker image'
1516
required: true

docs/source/en/_toctree.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@
188188
title: Metal Performance Shaders (MPS)
189189
- local: optimization/habana
190190
title: Habana Gaudi
191+
- local: optimization/neuron
192+
title: AWS Neuron
191193
title: Optimized hardware
192194
title: Accelerate inference and reduce memory
193195
- sections:
@@ -250,6 +252,8 @@
250252
title: SparseControlNetModel
251253
title: ControlNets
252254
- sections:
255+
- local: api/models/allegro_transformer3d
256+
title: AllegroTransformer3DModel
253257
- local: api/models/aura_flow_transformer2d
254258
title: AuraFlowTransformer2DModel
255259
- local: api/models/cogvideox_transformer3d
@@ -298,6 +302,8 @@
298302
- sections:
299303
- local: api/models/autoencoderkl
300304
title: AutoencoderKL
305+
- local: api/models/autoencoderkl_allegro
306+
title: AutoencoderKLAllegro
301307
- local: api/models/autoencoderkl_cogvideox
302308
title: AutoencoderKLCogVideoX
303309
- local: api/models/asymmetricautoencoderkl
@@ -316,6 +322,8 @@
316322
sections:
317323
- local: api/pipelines/overview
318324
title: Overview
325+
- local: api/pipelines/allegro
326+
title: Allegro
319327
- local: api/pipelines/amused
320328
title: aMUSEd
321329
- local: api/pipelines/animatediff
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
# AllegroTransformer3DModel
13+
14+
A Diffusion Transformer model for 3D data from [Allegro](https://github.com/rhymes-ai/Allegro) was introduced in [Allegro: Open the Black Box of Commercial-Level Video Generation Model](https://huggingface.co/papers/2410.15458) by RhymesAI.
15+
16+
The model can be loaded with the following code snippet.
17+
18+
```python
19+
from diffusers import AllegroTransformer3DModel
20+
21+
vae = AllegroTransformer3DModel.from_pretrained("rhymes-ai/Allegro", subfolder="transformer", torch_dtype=torch.bfloat16).to("cuda")
22+
```
23+
24+
## AllegroTransformer3DModel
25+
26+
[[autodoc]] AllegroTransformer3DModel
27+
28+
## Transformer2DModelOutput
29+
30+
[[autodoc]] models.modeling_outputs.Transformer2DModelOutput
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
# AutoencoderKLAllegro
13+
14+
The 3D variational autoencoder (VAE) model with KL loss used in [Allegro](https://github.com/rhymes-ai/Allegro) was introduced in [Allegro: Open the Black Box of Commercial-Level Video Generation Model](https://huggingface.co/papers/2410.15458) by RhymesAI.
15+
16+
The model can be loaded with the following code snippet.
17+
18+
```python
19+
from diffusers import AutoencoderKLAllegro
20+
21+
vae = AutoencoderKLCogVideoX.from_pretrained("rhymes-ai/Allegro", subfolder="vae", torch_dtype=torch.float32).to("cuda")
22+
```
23+
24+
## AutoencoderKLAllegro
25+
26+
[[autodoc]] AutoencoderKLAllegro
27+
- decode
28+
- encode
29+
- all
30+
31+
## AutoencoderKLOutput
32+
33+
[[autodoc]] models.autoencoders.autoencoder_kl.AutoencoderKLOutput
34+
35+
## DecoderOutput
36+
37+
[[autodoc]] models.autoencoders.vae.DecoderOutput
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
# Allegro
13+
14+
[Allegro: Open the Black Box of Commercial-Level Video Generation Model](https://huggingface.co/papers/2410.15458) from RhymesAI, by Yuan Zhou, Qiuyue Wang, Yuxuan Cai, Huan Yang.
15+
16+
The abstract from the paper is:
17+
18+
*Significant advancements have been made in the field of video generation, with the open-source community contributing a wealth of research papers and tools for training high-quality models. However, despite these efforts, the available information and resources remain insufficient for achieving commercial-level performance. In this report, we open the black box and introduce Allegro, an advanced video generation model that excels in both quality and temporal consistency. We also highlight the current limitations in the field and present a comprehensive methodology for training high-performance, commercial-level video generation models, addressing key aspects such as data, model architecture, training pipeline, and evaluation. Our user study shows that Allegro surpasses existing open-source models and most commercial models, ranking just behind Hailuo and Kling. Code: https://github.com/rhymes-ai/Allegro , Model: https://huggingface.co/rhymes-ai/Allegro , Gallery: https://rhymes.ai/allegro_gallery .*
19+
20+
<Tip>
21+
22+
Make sure to check out the Schedulers [guide](../../using-diffusers/schedulers.md) to learn how to explore the tradeoff between scheduler speed and quality, and see the [reuse components across pipelines](../../using-diffusers/loading.md#reuse-a-pipeline) section to learn how to efficiently load the same components into multiple pipelines.
23+
24+
</Tip>
25+
26+
## AllegroPipeline
27+
28+
[[autodoc]] AllegroPipeline
29+
- all
30+
- __call__
31+
32+
## AllegroPipelineOutput
33+
34+
[[autodoc]] pipelines.allegro.pipeline_output.AllegroPipelineOutput

docs/source/en/optimization/neuron.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
# AWS Neuron
14+
15+
Diffusers functionalities are available on [AWS Inf2 instances](https://aws.amazon.com/ec2/instance-types/inf2/), which are EC2 instances powered by [Neuron machine learning accelerators](https://aws.amazon.com/machine-learning/inferentia/). These instances aim to provide better compute performance (higher throughput, lower latency) with good cost-efficiency, making them good candidates for AWS users to deploy diffusion models to production.
16+
17+
[Optimum Neuron](https://huggingface.co/docs/optimum-neuron/en/index) is the interface between Hugging Face libraries and AWS Accelerators, including AWS [Trainium](https://aws.amazon.com/machine-learning/trainium/) and AWS [Inferentia](https://aws.amazon.com/machine-learning/inferentia/). It supports many of the features in Diffusers with similar APIs, so it is easier to learn if you're already familiar with Diffusers. Once you have created an AWS Inf2 instance, install Optimum Neuron.
18+
19+
```bash
20+
python -m pip install --upgrade-strategy eager optimum[neuronx]
21+
```
22+
23+
<Tip>
24+
25+
We provide pre-built [Hugging Face Neuron Deep Learning AMI](https://aws.amazon.com/marketplace/pp/prodview-gr3e6yiscria2) (DLAMI) and Optimum Neuron containers for Amazon SageMaker. It's recommended to correctly set up your environment.
26+
27+
</Tip>
28+
29+
The example below demonstrates how to generate images with the Stable Diffusion XL model on an inf2.8xlarge instance (you can switch to cheaper inf2.xlarge instances once the model is compiled). To generate some images, use the [`~optimum.neuron.NeuronStableDiffusionXLPipeline`] class, which is similar to the [`StableDiffusionXLPipeline`] class in Diffusers.
30+
31+
Unlike Diffusers, you need to compile models in the pipeline to the Neuron format, `.neuron`. Launch the following command to export the model to the `.neuron` format.
32+
33+
```bash
34+
optimum-cli export neuron --model stabilityai/stable-diffusion-xl-base-1.0 \
35+
--batch_size 1 \
36+
--height 1024 `# height in pixels of generated image, eg. 768, 1024` \
37+
--width 1024 `# width in pixels of generated image, eg. 768, 1024` \
38+
--num_images_per_prompt 1 `# number of images to generate per prompt, defaults to 1` \
39+
--auto_cast matmul `# cast only matrix multiplication operations` \
40+
--auto_cast_type bf16 `# cast operations from FP32 to BF16` \
41+
sd_neuron_xl/
42+
```
43+
44+
Now generate some images with the pre-compiled SDXL model.
45+
46+
```python
47+
>>> from optimum.neuron import NeuronStableDiffusionXLPipeline
48+
49+
>>> stable_diffusion_xl = NeuronStableDiffusionXLPipeline.from_pretrained("sd_neuron_xl/")
50+
>>> prompt = "a pig with wings flying in floating US dollar banknotes in the air, skyscrapers behind, warm color palette, muted colors, detailed, 8k"
51+
>>> image = stable_diffusion_xl(prompt).images[0]
52+
```
53+
54+
<img
55+
src="https://huggingface.co/datasets/Jingya/document_images/resolve/main/optimum/neuron/sdxl_pig.png"
56+
width="256"
57+
height="256"
58+
alt="peggy generated by sdxl on inf2"
59+
/>
60+
61+
Feel free to check out more guides and examples on different use cases from the Optimum Neuron [documentation](https://huggingface.co/docs/optimum-neuron/en/inference_tutorials/stable_diffusion#generate-images-with-stable-diffusion-models-on-aws-inferentia)!

examples/advanced_diffusion_training/train_dreambooth_lora_flux_advanced.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,8 @@ def save_model_hook(models, weights, output_dir):
16501650
elif isinstance(model, type(unwrap_model(text_encoder_one))):
16511651
if args.train_text_encoder: # when --train_text_encoder_ti we don't save the layers
16521652
text_encoder_one_lora_layers_to_save = get_peft_model_state_dict(model)
1653+
elif isinstance(model, type(unwrap_model(text_encoder_two))):
1654+
pass # when --train_text_encoder_ti and --enable_t5_ti we don't save the layers
16531655
else:
16541656
raise ValueError(f"unexpected save model: {model.__class__}")
16551657

@@ -2198,8 +2200,8 @@ def get_sigmas(timesteps, n_dim=4, dtype=torch.float32):
21982200

21992201
latent_image_ids = FluxPipeline._prepare_latent_image_ids(
22002202
model_input.shape[0],
2201-
model_input.shape[2],
2202-
model_input.shape[3],
2203+
model_input.shape[2] // 2,
2204+
model_input.shape[3] // 2,
22032205
accelerator.device,
22042206
weight_dtype,
22052207
)
@@ -2253,8 +2255,8 @@ def get_sigmas(timesteps, n_dim=4, dtype=torch.float32):
22532255
)[0]
22542256
model_pred = FluxPipeline._unpack_latents(
22552257
model_pred,
2256-
height=int(model_input.shape[2] * vae_scale_factor / 2),
2257-
width=int(model_input.shape[3] * vae_scale_factor / 2),
2258+
height=model_input.shape[2] * vae_scale_factor,
2259+
width=model_input.shape[3] * vae_scale_factor,
22582260
vae_scale_factor=vae_scale_factor,
22592261
)
22602262

examples/community/README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Please also check out our [Community Scripts](https://github.com/huggingface/dif
7373
| Stable Diffusion BoxDiff Pipeline | Training-free controlled generation with bounding boxes using [BoxDiff](https://github.com/showlab/BoxDiff) | [Stable Diffusion BoxDiff Pipeline](#stable-diffusion-boxdiff) | - | [Jingyang Zhang](https://github.com/zjysteven/) |
7474
| FRESCO V2V Pipeline | Implementation of [[CVPR 2024] FRESCO: Spatial-Temporal Correspondence for Zero-Shot Video Translation](https://arxiv.org/abs/2403.12962) | [FRESCO V2V Pipeline](#fresco) | - | [Yifan Zhou](https://github.com/SingleZombie) |
7575
| AnimateDiff IPEX Pipeline | Accelerate AnimateDiff inference pipeline with BF16/FP32 precision on Intel Xeon CPUs with [IPEX](https://github.com/intel/intel-extension-for-pytorch) | [AnimateDiff on IPEX](#animatediff-on-ipex) | - | [Dan Li](https://github.com/ustcuna/) |
76+
PIXART-α Controlnet pipeline | Implementation of the controlnet model for pixart alpha and its diffusers pipeline | [PIXART-α Controlnet pipeline](#pixart-α-controlnet-pipeline) | - | [Raul Ciotescu](https://github.com/raulc0399/) |
7677
| HunyuanDiT Differential Diffusion Pipeline | Applies [Differential Diffusion](https://github.com/exx8/differential-diffusion) to [HunyuanDiT](https://github.com/huggingface/diffusers/pull/8240). | [HunyuanDiT with Differential Diffusion](#hunyuandit-with-differential-diffusion) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1v44a5fpzyr4Ffr4v2XBQ7BajzG874N4P?usp=sharing) | [Monjoy Choudhury](https://github.com/MnCSSJ4x) |
7778
| [🪆Matryoshka Diffusion Models](https://huggingface.co/papers/2310.15111) | A diffusion process that denoises inputs at multiple resolutions jointly and uses a NestedUNet architecture where features and parameters for small scale inputs are nested within those of the large scales. See [original codebase](https://github.com/apple/ml-mdm). | [🪆Matryoshka Diffusion Models](#matryoshka-diffusion-models) | [![Hugging Face Space](https://img.shields.io/badge/🤗%20Hugging%20Face-Space-yellow)](https://huggingface.co/spaces/pcuenq/mdm) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/gist/tolgacangoz/1f54875fc7aeaabcf284ebde64820966/matryoshka_hf.ipynb) | [M. Tolga Cangöz](https://github.com/tolgacangoz) |
7879

@@ -4445,3 +4446,94 @@ grid_image.save(grid_dir + "sample.png")
44454446
`pag_scale` : guidance scale of PAG (ex: 5.0)
44464447

44474448
`pag_applied_layers_index` : index of the layer to apply perturbation (ex: ['m0'])
4449+
4450+
# PIXART-α Controlnet pipeline
4451+
4452+
[Project](https://pixart-alpha.github.io/) / [GitHub](https://github.com/PixArt-alpha/PixArt-alpha/blob/master/asset/docs/pixart_controlnet.md)
4453+
4454+
This the implementation of the controlnet model and the pipelne for the Pixart-alpha model, adapted to use the HuggingFace Diffusers.
4455+
4456+
## Example Usage
4457+
4458+
This example uses the Pixart HED Controlnet model, converted from the control net model as trained by the authors of the paper.
4459+
4460+
```py
4461+
import sys
4462+
import os
4463+
import torch
4464+
import torchvision.transforms as T
4465+
import torchvision.transforms.functional as TF
4466+
4467+
from pipeline_pixart_alpha_controlnet import PixArtAlphaControlnetPipeline
4468+
from diffusers.utils import load_image
4469+
4470+
from diffusers.image_processor import PixArtImageProcessor
4471+
4472+
from controlnet_aux import HEDdetector
4473+
4474+
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
4475+
from pixart.controlnet_pixart_alpha import PixArtControlNetAdapterModel
4476+
4477+
controlnet_repo_id = "raulc0399/pixart-alpha-hed-controlnet"
4478+
4479+
weight_dtype = torch.float16
4480+
image_size = 1024
4481+
4482+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
4483+
4484+
torch.manual_seed(0)
4485+
4486+
# load controlnet
4487+
controlnet = PixArtControlNetAdapterModel.from_pretrained(
4488+
controlnet_repo_id,
4489+
torch_dtype=weight_dtype,
4490+
use_safetensors=True,
4491+
).to(device)
4492+
4493+
pipe = PixArtAlphaControlnetPipeline.from_pretrained(
4494+
"PixArt-alpha/PixArt-XL-2-1024-MS",
4495+
controlnet=controlnet,
4496+
torch_dtype=weight_dtype,
4497+
use_safetensors=True,
4498+
).to(device)
4499+
4500+
images_path = "images"
4501+
control_image_file = "0_7.jpg"
4502+
4503+
prompt = "battleship in space, galaxy in background"
4504+
4505+
control_image_name = control_image_file.split('.')[0]
4506+
4507+
control_image = load_image(f"{images_path}/{control_image_file}")
4508+
print(control_image.size)
4509+
height, width = control_image.size
4510+
4511+
hed = HEDdetector.from_pretrained("lllyasviel/Annotators")
4512+
4513+
condition_transform = T.Compose([
4514+
T.Lambda(lambda img: img.convert('RGB')),
4515+
T.CenterCrop([image_size, image_size]),
4516+
])
4517+
4518+
control_image = condition_transform(control_image)
4519+
hed_edge = hed(control_image, detect_resolution=image_size, image_resolution=image_size)
4520+
4521+
hed_edge.save(f"{images_path}/{control_image_name}_hed.jpg")
4522+
4523+
# run pipeline
4524+
with torch.no_grad():
4525+
out = pipe(
4526+
prompt=prompt,
4527+
image=hed_edge,
4528+
num_inference_steps=14,
4529+
guidance_scale=4.5,
4530+
height=image_size,
4531+
width=image_size,
4532+
)
4533+
4534+
out.images[0].save(f"{images_path}//{control_image_name}_output.jpg")
4535+
4536+
```
4537+
4538+
In the folder examples/pixart there is also a script that can be used to train new models.
4539+
Please check the script `train_controlnet_hf_diffusers.sh` on how to start the training.

examples/controlnet/train_controlnet_flux.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,8 +1256,8 @@ def get_sigmas(timesteps, n_dim=4, dtype=torch.float32):
12561256

12571257
latent_image_ids = FluxControlNetPipeline._prepare_latent_image_ids(
12581258
batch_size=pixel_latents_tmp.shape[0],
1259-
height=pixel_latents_tmp.shape[2],
1260-
width=pixel_latents_tmp.shape[3],
1259+
height=pixel_latents_tmp.shape[2] // 2,
1260+
width=pixel_latents_tmp.shape[3] // 2,
12611261
device=pixel_values.device,
12621262
dtype=pixel_values.dtype,
12631263
)

0 commit comments

Comments
 (0)