Skip to content

Flux Control LoRA #9999

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

Merged
merged 79 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
2829679
update
a-r-r-o-w Nov 21, 2024
be67dbd
Merge branch 'main' into flux-new
a-r-r-o-w Nov 21, 2024
f56ffb1
add
yiyixuxu Nov 21, 2024
7e4df06
update
a-r-r-o-w Nov 21, 2024
9ea52da
Merge remote-tracking branch 'origin/flux-fill-yiyi' into flux-new
a-r-r-o-w Nov 21, 2024
217e90c
add control-lora conversion script; make flux loader handle norms; fi…
a-r-r-o-w Nov 21, 2024
b4f1cbf
control lora updates
a-r-r-o-w Nov 22, 2024
414b30b
remove copied-from
a-r-r-o-w Nov 22, 2024
6b02ac2
create separate pipelines for flux control
a-r-r-o-w Nov 22, 2024
3169bf5
make fix-copies
a-r-r-o-w Nov 22, 2024
f7f006d
update docs
a-r-r-o-w Nov 22, 2024
8bb940e
add tests
a-r-r-o-w Nov 22, 2024
9e615fd
fix
a-r-r-o-w Nov 22, 2024
6d168db
Merge branch 'main' into flux-new
a-r-r-o-w Nov 22, 2024
89fd970
Apply suggestions from code review
a-r-r-o-w Nov 22, 2024
73cfc51
remove control lora changes
a-r-r-o-w Nov 22, 2024
c94966f
apply suggestions from review
a-r-r-o-w Nov 22, 2024
cfe13e7
Revert "remove control lora changes"
a-r-r-o-w Nov 22, 2024
0c959a7
update
a-r-r-o-w Nov 23, 2024
6ef2c8b
update
a-r-r-o-w Nov 23, 2024
42970ee
improve log messages
a-r-r-o-w Nov 23, 2024
2ec93ba
Merge branch 'main' into flux-control-lora
a-r-r-o-w Nov 23, 2024
993f3d3
Merge branch 'main' into flux-control-lora
sayakpaul Nov 25, 2024
6523fa6
updates.
sayakpaul Nov 25, 2024
81ab40b
updates
sayakpaul Nov 25, 2024
4432e73
Merge branch 'main' into flux-control-lora
sayakpaul Nov 25, 2024
0f747c0
Merge branch 'main' into flux-control-lora
sayakpaul Nov 26, 2024
6d0c6dc
Merge branch 'flux-control-lora' into sayak-flux-control-lora
sayakpaul Nov 26, 2024
1633619
support register_config.
sayakpaul Nov 26, 2024
b9039b1
fix
sayakpaul Nov 26, 2024
5f94d74
fix
sayakpaul Nov 26, 2024
bd31651
fix
sayakpaul Nov 26, 2024
e18b7ad
Merge branch 'main' into flux-control-lora
a-r-r-o-w Nov 27, 2024
f54ec56
updates
sayakpaul Nov 28, 2024
8032405
updates
sayakpaul Nov 28, 2024
6b70bf7
updates
sayakpaul Nov 28, 2024
3726e2d
fix-copies
sayakpaul Nov 28, 2024
b6ca9d9
Merge branch 'main' into flux-control-lora
sayakpaul Nov 28, 2024
908d151
fix
sayakpaul Nov 29, 2024
6af2097
Merge branch 'main' into flux-control-lora
sayakpaul Nov 29, 2024
07d44e7
apply suggestions from review
a-r-r-o-w Dec 1, 2024
b66e691
add tests
a-r-r-o-w Dec 1, 2024
66d7466
remove conversion script; enable on-the-fly conversion
a-r-r-o-w Dec 2, 2024
d827d1e
Merge branch 'main' into flux-control-lora
a-r-r-o-w Dec 2, 2024
64c821b
bias -> lora_bias.
sayakpaul Dec 2, 2024
30a89a6
fix-copies
sayakpaul Dec 2, 2024
bca1eaa
peft.py
sayakpaul Dec 2, 2024
6ce181b
Merge branch 'main' into flux-control-lora
sayakpaul Dec 2, 2024
e7df197
fix lora conversion
a-r-r-o-w Dec 2, 2024
5fd9fda
changes
sayakpaul Dec 3, 2024
a8c50ba
fix-copies
sayakpaul Dec 3, 2024
b12f797
updates for tests
sayakpaul Dec 3, 2024
f9bd3eb
fix
sayakpaul Dec 3, 2024
6b35c92
Merge branch 'main' into flux-control-lora
sayakpaul Dec 3, 2024
84c168c
alpha_pattern.
sayakpaul Dec 4, 2024
118ed9b
Merge branch 'main' into flux-control-lora
sayakpaul Dec 4, 2024
be1d788
add a test for varied lora ranks and alphas.
sayakpaul Dec 4, 2024
5b1bcd8
revert changes in num_channels_latents = self.transformer.config.in_c…
sayakpaul Dec 4, 2024
cde01e3
revert moe
sayakpaul Dec 4, 2024
79af91d
Merge branch 'main' into flux-control-lora
sayakpaul Dec 5, 2024
4b3efcc
Merge branch 'main' into flux-control-lora
sayakpaul Dec 5, 2024
f688ecf
add a sanity check on unexpected keys when loading norm layers.
sayakpaul Dec 5, 2024
d6518b7
Merge branch 'main' into flux-control-lora
sayakpaul Dec 6, 2024
ecbc4cb
fixes
sayakpaul Dec 6, 2024
55058e2
tests
sayakpaul Dec 6, 2024
a8bd03b
reviewer feedback
sayakpaul Dec 6, 2024
49c0242
fix
sayakpaul Dec 6, 2024
8b050ea
proper peft version for lora_bias
sayakpaul Dec 6, 2024
3204627
fix-copies
sayakpaul Dec 6, 2024
2b9bfa3
Merge branch 'main' into flux-control-lora
a-r-r-o-w Dec 6, 2024
130e592
remove debug code
a-r-r-o-w Dec 6, 2024
b20ec7d
update docs
a-r-r-o-w Dec 6, 2024
79d023a
Merge branch 'main' into flux-control-lora
sayakpaul Dec 7, 2024
d1715d3
integration tests
sayakpaul Dec 7, 2024
cbad4b3
nis
sayakpaul Dec 7, 2024
cd7c155
fuse and unload.
sayakpaul Dec 7, 2024
25616e2
fix
sayakpaul Dec 7, 2024
0b83deb
add slices.
sayakpaul Dec 7, 2024
60a68e2
Merge branch 'main' into flux-control-lora
a-r-r-o-w Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions docs/source/en/api/pipelines/flux.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,35 @@ image = pipe(
image.save("output.png")
```

Canny Control is also possible with a LoRA variant of this condition. The usage is as follows:

```python
# !pip install -U controlnet-aux
import torch
from controlnet_aux import CannyDetector
from diffusers import FluxControlPipeline
from diffusers.utils import load_image

pipe = FluxControlPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16).to("cuda")
pipe.load_lora_weights("black-forest-labs/FLUX.1-Canny-dev-lora")

prompt = "A robot made of exotic candies and chocolates of different kinds. The background is filled with confetti and celebratory gifts."
control_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/robot.png")

processor = CannyDetector()
control_image = processor(control_image, low_threshold=50, high_threshold=200, detect_resolution=1024, image_resolution=1024)

image = pipe(
prompt=prompt,
control_image=control_image,
height=1024,
width=1024,
num_inference_steps=50,
guidance_scale=30.0,
).images[0]
image.save("output.png")
```

### Depth Control

**Note:** `black-forest-labs/Flux.1-Depth-dev` is _not_ a ControlNet model. [`ControlNetModel`] models are a separate component from the UNet/Transformer whose residuals are added to the actual underlying model. Depth Control is an alternate architecture that achieves effectively the same results as a ControlNet model would, by using channel-wise concatenation with input control condition and ensuring the transformer learns structure control by following the condition as closely as possible.
Expand Down Expand Up @@ -174,6 +203,36 @@ image = pipe(
image.save("output.png")
```

Depth Control is also possible with a LoRA variant of this condition. The usage is as follows:

```python
# !pip install git+https://github.com/huggingface/image_gen_aux
import torch
from diffusers import FluxControlPipeline, FluxTransformer2DModel
from diffusers.utils import load_image
from image_gen_aux import DepthPreprocessor

pipe = FluxControlPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16).to("cuda")
pipe.load_lora_weights("black-forest-labs/FLUX.1-Depth-dev-lora")

prompt = "A robot made of exotic candies and chocolates of different kinds. The background is filled with confetti and celebratory gifts."
control_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/robot.png")

processor = DepthPreprocessor.from_pretrained("LiheYoung/depth-anything-large-hf")
control_image = processor(control_image)[0].convert("RGB")

image = pipe(
prompt=prompt,
control_image=control_image,
height=1024,
width=1024,
num_inference_steps=30,
guidance_scale=10.0,
generator=torch.Generator().manual_seed(42),
).images[0]
image.save("output.png")
```

### Redux

* Flux Redux pipeline is an adapter for FLUX.1 base models. It can be used with both flux-dev and flux-schnell, for image-to-image generation.
Expand Down
Loading
Loading