Skip to content

Commit 1fcb811

Browse files
MnCSSJ4xa-r-r-o-w
andauthored
Add Differential Diffusion to HunyuanDiT. (#9040)
* Add Differential Pipeline. * Fix Styling Issue using ruff -fix * Add details to Contributing.md * Revert "Fix Styling Issue using ruff -fix" This reverts commit d347de1. * Revert "Revert "Fix Styling Issue using ruff -fix"" This reverts commit ce7c3ff. * Revert README changes * Restore README.md * Update README.md * Resolved Comments: * Fix Readme based on review * Fix formatting after make style --------- Co-authored-by: Aryan <[email protected]>
1 parent ae026db commit 1fcb811

File tree

2 files changed

+1192
-3
lines changed

2 files changed

+1192
-3
lines changed

examples/community/README.md

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Please also check out our [Community Scripts](https://github.com/huggingface/dif
7171
| 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/) |
7272
| 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) |
7373
| 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/) |
74+
| HunyuanDiT Differential Diffusion Pipeline | Applies [Differential Diffsuion](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) |
7475

7576
To load a custom pipeline you just need to pass the `custom_pipeline` argument to `DiffusionPipeline`, as one of the files in `diffusers/examples/community`. Feel free to send a PR with your own pipelines, we will merge them quickly.
7677

@@ -1646,7 +1647,6 @@ from diffusers import DiffusionPipeline
16461647
scheduler = DDIMScheduler.from_pretrained("stabilityai/stable-diffusion-2-1",
16471648
subfolder="scheduler")
16481649

1649-
16501650
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1",
16511651
custom_pipeline="stable_diffusion_tensorrt_img2img",
16521652
variant='fp16',
@@ -1661,7 +1661,6 @@ pipe = pipe.to("cuda")
16611661
url = "https://pajoca.com/wp-content/uploads/2022/09/tekito-yamakawa-1.png"
16621662
response = requests.get(url)
16631663
input_image = Image.open(BytesIO(response.content)).convert("RGB")
1664-
16651664
prompt = "photorealistic new zealand hills"
16661665
image = pipe(prompt, image=input_image, strength=0.75,).images[0]
16671666
image.save('tensorrt_img2img_new_zealand_hills.png')
@@ -4209,6 +4208,52 @@ print("Latency of AnimateDiffPipelineIpex--fp32", latency, "s for total", step,
42094208
latency = elapsed_time(pipe4, num_inference_steps=step)
42104209
print("Latency of AnimateDiffPipeline--fp32",latency, "s for total", step, "steps")
42114210
```
4211+
### HunyuanDiT with Differential Diffusion
4212+
4213+
#### Usage
4214+
4215+
```python
4216+
import torch
4217+
from diffusers import FlowMatchEulerDiscreteScheduler
4218+
from diffusers.utils import load_image
4219+
from PIL import Image
4220+
from torchvision import transforms
4221+
4222+
from pipeline_hunyuandit_differential_img2img import (
4223+
HunyuanDiTDifferentialImg2ImgPipeline,
4224+
)
4225+
4226+
4227+
pipe = HunyuanDiTDifferentialImg2ImgPipeline.from_pretrained(
4228+
"Tencent-Hunyuan/HunyuanDiT-Diffusers", torch_dtype=torch.float16
4229+
).to("cuda")
4230+
4231+
4232+
source_image = load_image(
4233+
"https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/differential/20240329211129_4024911930.png"
4234+
)
4235+
map = load_image(
4236+
"https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/differential/gradient_mask_2.png"
4237+
)
4238+
prompt = "a green pear"
4239+
negative_prompt = "blurry"
4240+
4241+
image = pipe(
4242+
prompt=prompt,
4243+
negative_prompt=negative_prompt,
4244+
image=source_image,
4245+
num_inference_steps=28,
4246+
guidance_scale=4.5,
4247+
strength=1.0,
4248+
map=map,
4249+
).images[0]
4250+
```
4251+
4252+
| ![Gradient](https://github.com/user-attachments/assets/e38ce4d5-1ae6-4df0-ab43-adc1b45716b5) | ![Input](https://github.com/user-attachments/assets/9c95679c-e9d7-4f5a-90d6-560203acd6b3) | ![Output](https://github.com/user-attachments/assets/5313ff64-a0c4-418b-8b55-a38f1a5e7532) |
4253+
| ------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
4254+
| Gradient | Input | Output |
4255+
4256+
A colab notebook demonstrating all results can be found [here](https://colab.research.google.com/drive/1v44a5fpzyr4Ffr4v2XBQ7BajzG874N4P?usp=sharing). Depth Maps have also been added in the same colab.
42124257

42134258
# Perturbed-Attention Guidance
42144259

@@ -4285,4 +4330,4 @@ grid_image.save(grid_dir + "sample.png")
42854330

42864331
`pag_scale` : guidance scale of PAG (ex: 5.0)
42874332

4288-
`pag_applied_layers_index` : index of the layer to apply perturbation (ex: ['m0'])
4333+
`pag_applied_layers_index` : index of the layer to apply perturbation (ex: ['m0'])

0 commit comments

Comments
 (0)