Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add Fabric #4201

Merged
merged 104 commits into from Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 95 commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
8e871c6
empty PR
shauray8 Jul 21, 2023
fbc3af9
init
shauray8 Jul 30, 2023
2c8a021
changes
shauray8 Aug 1, 2023
ccfc546
starting with the pipeline
shauray8 Aug 2, 2023
c815605
stable diff
shauray8 Aug 3, 2023
b65184b
prev
shauray8 Aug 3, 2023
1c4833c
more things, getting started
shauray8 Aug 4, 2023
c9eb420
more functions
shauray8 Aug 5, 2023
7bec286
makeing it more readable
shauray8 Aug 9, 2023
adebe8f
almost done testing
shauray8 Aug 10, 2023
a31699f
var changes
shauray8 Aug 10, 2023
b94cbf4
testing
shauray8 Aug 10, 2023
2999f40
device
shauray8 Aug 11, 2023
834ab80
device support
shauray8 Aug 11, 2023
39ea4f9
maybe
shauray8 Aug 11, 2023
fb59e24
device malfunctions
shauray8 Aug 11, 2023
1ac8004
new new
shauray8 Aug 11, 2023
4b3f1a6
register
shauray8 Aug 11, 2023
ad988f2
testing
shauray8 Aug 11, 2023
a1cf609
exec does not work
shauray8 Aug 11, 2023
27bb344
float
shauray8 Aug 11, 2023
b827bf3
change info
shauray8 Aug 11, 2023
4aa7aaa
change of architecture
shauray8 Aug 12, 2023
6e7ab4e
might work
shauray8 Aug 12, 2023
f9635d7
testing with colab
shauray8 Aug 12, 2023
cda85ed
more attn atuff
shauray8 Aug 12, 2023
9eb6459
stupid additions
shauray8 Aug 15, 2023
ef34c1a
documenting and testing
shauray8 Aug 15, 2023
f0efafa
writing tests
shauray8 Aug 15, 2023
88a5a9a
more docs
shauray8 Aug 15, 2023
9fa434f
tests and docs
shauray8 Aug 15, 2023
e3fc7ca
remove test
shauray8 Aug 15, 2023
af17f11
Merge branch 'main' into FABRIC
shauray8 Aug 15, 2023
d78fb6b
empty PR
shauray8 Jul 21, 2023
2fc9642
init
shauray8 Jul 30, 2023
fb525bf
changes
shauray8 Aug 1, 2023
2e6b75b
starting with the pipeline
shauray8 Aug 2, 2023
caa4bfe
stable diff
shauray8 Aug 3, 2023
87665a8
prev
shauray8 Aug 3, 2023
4f706a8
more things, getting started
shauray8 Aug 4, 2023
697a0b0
more functions
shauray8 Aug 5, 2023
bddf128
makeing it more readable
shauray8 Aug 9, 2023
5ab690f
almost done testing
shauray8 Aug 10, 2023
4f8bc73
var changes
shauray8 Aug 10, 2023
8476267
testing
shauray8 Aug 10, 2023
90e395b
device
shauray8 Aug 11, 2023
32a28b3
device support
shauray8 Aug 11, 2023
12f2772
maybe
shauray8 Aug 11, 2023
cf18db8
device malfunctions
shauray8 Aug 11, 2023
2480245
new new
shauray8 Aug 11, 2023
be6ddf3
register
shauray8 Aug 11, 2023
0463bd6
testing
shauray8 Aug 11, 2023
5b09784
exec does not work
shauray8 Aug 11, 2023
413d450
float
shauray8 Aug 11, 2023
e44e8ce
change info
shauray8 Aug 11, 2023
3e4965a
change of architecture
shauray8 Aug 12, 2023
1ab807d
might work
shauray8 Aug 12, 2023
f603f65
testing with colab
shauray8 Aug 12, 2023
99ab1bf
more attn atuff
shauray8 Aug 12, 2023
9f9810e
stupid additions
shauray8 Aug 15, 2023
4ea0d50
documenting and testing
shauray8 Aug 15, 2023
ed90191
writing tests
shauray8 Aug 15, 2023
7513416
more docs
shauray8 Aug 15, 2023
3a7a783
tests and docs
shauray8 Aug 15, 2023
897f067
remove test
shauray8 Aug 15, 2023
60de01f
Merge branch 'FABRIC' of https://github.com/shauray8/diffusers into F…
shauray8 Aug 16, 2023
3bc14e3
change cross attention
shauray8 Aug 16, 2023
dd6e9b2
revert back
shauray8 Aug 17, 2023
60e37a0
tests
shauray8 Aug 17, 2023
a9e5e4c
Merge branch 'main' into FABRIC
shauray8 Aug 17, 2023
ea2ada8
reverting back to orig
shauray8 Aug 17, 2023
994ba48
changes
shauray8 Aug 18, 2023
0025a20
test passing
shauray8 Aug 18, 2023
04697a0
pipeline changes
shauray8 Aug 18, 2023
79be7ff
before quality
shauray8 Aug 18, 2023
ba8aa35
quality checks pass
shauray8 Aug 18, 2023
77d97f7
Merge branch 'main' into FABRIC
shauray8 Aug 18, 2023
9d1297d
remove print statements
shauray8 Aug 19, 2023
c7b3522
doc fixes
shauray8 Aug 19, 2023
a166b55
__init__ error something
shauray8 Aug 19, 2023
6261e9d
update docs, working on dim
shauray8 Aug 21, 2023
913c69a
working on encoding
shauray8 Aug 21, 2023
83f744b
doc fix
shauray8 Aug 21, 2023
bda8c53
more fixes
shauray8 Aug 21, 2023
ffe80d0
no more dependent on 512*512
shauray8 Aug 21, 2023
4a1859a
update docs
shauray8 Aug 21, 2023
34ea6df
fixes
shauray8 Aug 21, 2023
2fe64ff
test passing
shauray8 Aug 22, 2023
ac517d3
remove comment
shauray8 Aug 22, 2023
882f1a1
fixes and migration
shauray8 Aug 22, 2023
b87efcc
simpler tests
shauray8 Aug 22, 2023
3304440
doc changes
shauray8 Aug 22, 2023
4a2b84a
green CI
shauray8 Aug 23, 2023
b9002ee
changes
shauray8 Aug 23, 2023
a75c412
more docs
shauray8 Aug 23, 2023
40df49a
changes
shauray8 Aug 25, 2023
8c3516b
new images
shauray8 Aug 25, 2023
8ac96a2
Merge branch 'main' into FABRIC
sayakpaul Aug 25, 2023
3a34767
to community examples
shauray8 Aug 26, 2023
4029b48
selete
shauray8 Aug 26, 2023
f747ef1
merge fixes
shauray8 Aug 26, 2023
40c0971
more fixes
shauray8 Aug 26, 2023
f05beca
changes
shauray8 Aug 27, 2023
aa96ed5
fix
shauray8 Aug 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/source/en/_toctree.yml
Expand Up @@ -212,6 +212,8 @@
title: DiffEdit
- local: api/pipelines/dit
title: DiT
- local: api/pipelines/fabric
title: FABRIC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- local: api/pipelines/fabric
title: FABRIC

- local: api/pipelines/pix2pix
title: InstructPix2Pix
- local: api/pipelines/kandinsky
Expand Down
43 changes: 43 additions & 0 deletions docs/source/en/api/pipelines/fabric.md
@@ -0,0 +1,43 @@
<!--Copyright 2023 The HuggingFace Team. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
-->

# FABRIC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we maybe also add this to the README.md in examples/community? :-)


[FABRIC: Personalizing Diffusion Models with Iterative Feedback](https://huggingface.co/papers/2307.10159) (FABRIC) is by Dimitri von Rütte, Elisabetta Fedele, Jonathan Thomm and Lukas Wolf.

FABRIC is a training-free approach that conditions the diffusion process on a set of feedback images, applicable to a wide range of popular diffusion models. It is created by researchers and engineers from [ETH Zürich, Switzerland](https://github.com/sd-fabric). The [`FabricPipeline`] can generate photo-realistic images given any text input using Stable Diffusion.

The abstract from the paper is:

*In an era where visual content generation is increasingly driven by machine learning, the integration of human feedback into generative models presents significant opportunities for enhancing user experience and output quality. This study explores strategies for incorporating iterative human feedback into the generative process of diffusion-based text-to-image models. We propose FABRIC, a training-free approach applicable to a wide range of popular diffusion models, which exploits the self-attention layer present in the most widely used architectures to condition the diffusion process on a set of feedback images. To ensure a rigorous assessment of our approach, we introduce a comprehensive evaluation methodology, offering a robust mechanism to quantify the performance of generative visual models that integrate human feedback. We show that generation results improve over multiple rounds of iterative feedback through exhaustive analysis, implicitly optimizing arbitrary user preferences. The potential applications of these findings extend to fields such as personalized content creation and customization*

The original codebase can be found at [sd-fabric/fabric](https://github.com/sd-fabric/fabric), and available checkpoints are [dreamlike-art/dreamlike-photoreal-2.0](https://huggingface.co/dreamlike-art/dreamlike-photoreal-2.0), [runwayml/stable-diffusion-v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5), and [stabilityai/stable-diffusion-2-1](https://huggingface.co/stabilityai/stable-diffusion-2-1) (may give unexpected results).

Let's have a look at the images (*512X512*)

| Without Feedback | With Feedback (1st image) |
|---------------------|---------------------|
| ![Image 1](https://drive.google.com/uc?export=view&id=12wxbikt7834eRTK40legR5PtJmFLNH34) | ![Feedback Image 1](https://drive.google.com/uc?export=view&id=1YcFPDHSRr2OE3hy-5lvr8An21Jum85D5) |
shauray8 marked this conversation as resolved.
Show resolved Hide resolved

shauray8 marked this conversation as resolved.
Show resolved Hide resolved
<Tip>

Make sure to check out the Stable Diffusion [Tips](overview#tips) section to learn how to explore the tradeoff between scheduler speed and quality, and how to reuse pipeline components efficiently!

</Tip>

shauray8 marked this conversation as resolved.
Show resolved Hide resolved
[[autodoc]] FabricPipeline
- all
- __call__
shauray8 marked this conversation as resolved.
Show resolved Hide resolved

## StableDiffusionPipelineOutput

[[autodoc]] pipelines.stable_diffusion.StableDiffusionPipelineOutput
14 changes: 13 additions & 1 deletion docs/source/en/using-diffusers/controlling_generation.md
Expand Up @@ -41,6 +41,7 @@ Unless otherwise mentioned, these are techniques that work with existing models
13. [Model Editing](#model-editing)
14. [DiffEdit](#diffedit)
15. [T2I-Adapter](#t2i-adapter)
16. [FABRIC](#fabric)

For convenience, we provide a table to denote which methods are inference-only and which require fine-tuning/training.

Expand All @@ -61,7 +62,7 @@ For convenience, we provide a table to denote which methods are inference-only a
| [Model Editing](#model-editing) | ✅ | ❌ | |
| [DiffEdit](#diffedit) | ✅ | ❌ | |
| [T2I-Adapter](#t2i-adapter) | ✅ | ❌ | |

| [Fabric](#fabric) | ✅ | ❌ | |
shauray8 marked this conversation as resolved.
Show resolved Hide resolved
## Instruct Pix2Pix

[Paper](https://arxiv.org/abs/2211.09800)
Expand Down Expand Up @@ -230,3 +231,14 @@ There are 8 canonical pre-trained adapters trained on different conditionings su
depth maps, and semantic segmentations.

See [here](../api/pipelines/stable_diffusion/adapter) for more information on how to use it.

## Fabric

[Paper](https://arxiv.org/abs/2307.10159)

[Fabric](../api/pipelines/fabric) is a training-free
approach applicable to a wide range of popular diffusion models, which exploits
the self-attention layer present in the most widely used architectures to condition
the diffusion process on a set of feedback images.

To know more details, check out the [official doc](../api/pipelines/fabric).
1 change: 1 addition & 0 deletions src/diffusers/__init__.py
Expand Up @@ -135,6 +135,7 @@
AltDiffusionPipeline,
AudioLDMPipeline,
CycleDiffusionPipeline,
FabricPipeline,
IFImg2ImgPipeline,
IFImg2ImgSuperResolutionPipeline,
IFInpaintingPipeline,
Expand Down
1 change: 1 addition & 0 deletions src/diffusers/pipelines/__init__.py
Expand Up @@ -87,6 +87,7 @@
from .shap_e import ShapEImg2ImgPipeline, ShapEPipeline
from .stable_diffusion import (
CycleDiffusionPipeline,
FabricPipeline,
StableDiffusionAttendAndExcitePipeline,
StableDiffusionDepth2ImgPipeline,
StableDiffusionDiffEditPipeline,
Expand Down
51 changes: 51 additions & 0 deletions src/diffusers/pipelines/stable_diffusion/README.md
Expand Up @@ -174,3 +174,54 @@ image = pipe(

image.save("black_to_blue.png")
```

### FABRIC using Stable Diffusion

```python
import requests
import torch
from PIL import Image
from io import BytesIO

from diffusers import FabricPipeline

# load the pipeline
# make sure you're logged in with `huggingface-cli login`
model_id_or_path = "runwayml/stable-diffusion-v1-5"
#can also be used with dreamlike-art/dreamlike-photoreal-2.0
pipe = FabricPipeline.from_pretrained(model_id_or_path, ).to("cuda")

# let's specify a prompt
prompt = "An astronaut riding an elephant"
negative_prompt = "lowres, cropped"

# call the pipeline
image = pipe(
prompt=prompt,
negative_prompt=negative_prompt,
num_inference_steps=20,
generator=torch.manual_seed(12)
).images[0]

image.save("horse_to_elephant.jpg")

# let's try another example with feedback
url = "https://raw.githubusercontent.com/ChenWu98/cycle-diffusion/main/data/dalle2/A%20black%20colored%20car.png"
response = requests.get(url)
init_image = Image.open(BytesIO(response.content)).convert("RGB")

prompt = "photo, A blue colored car, fish eye"
liked = [init_image]
## same goes with disliked

# call the pipeline
torch.manual_seed(0)
image = pipe(
prompt=prompt,
negative_prompt=negative_prompt,
liked = liked,
num_inference_steps=20,
).images[0]

image.save("black_to_blue.png")
```
1 change: 1 addition & 0 deletions src/diffusers/pipelines/stable_diffusion/__init__.py
Expand Up @@ -43,6 +43,7 @@ class StableDiffusionPipelineOutput(BaseOutput):
from ...utils.dummy_torch_and_transformers_objects import * # noqa F403
else:
from .pipeline_cycle_diffusion import CycleDiffusionPipeline
from .pipeline_fabric import FabricPipeline
from .pipeline_stable_diffusion import StableDiffusionPipeline
from .pipeline_stable_diffusion_attend_and_excite import StableDiffusionAttendAndExcitePipeline
from .pipeline_stable_diffusion_gligen import StableDiffusionGLIGENPipeline
Expand Down