-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Flux - soft inpainting via differential diffusion #9268
Conversation
Question, would this work as an alternative to FluxInpaint to be able to do outpainting with the inner mask blurred, or do I wait for FluxDifferentialInpaintPipeline? I've been trying to add Flux in my Infinite Zoom implementation, and while I got it working, it's just not blending the masked area well and each outstep is framed. Works nicely with SD 1.5 Inpainting. I've tried to blur the mask_image black/white and didn't help. I also notice with this Differential mask_image that the masked area is black instead of white as it is in the normal Inpainting, correct? Can be tested on my app at DiffusionDeluxe.com if you're curious. |
@asomoza can you take a look and help merge this? |
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
HI @ryanlyn, sorry for this late review, did you update the pipeline with the latest changes from the img2img pipeline? This work ok and we don't really enforce too much of the guidelines here, but it will be nice if the copied lines are the same from the img2img. Let's merge this soon! |
Thanks for great work! Looks like It fails when batch_size > 1?
|
@asomoza yes, merging the latest updates can fix this. @@ -554,6 +554,17 @@ class FluxDifferentialImg2ImgPipeline(DiffusionPipeline, FluxLoraLoaderMixin):
else:
image_latents = latents
+ if batch_size > image_latents.shape[0] and batch_size % image_latents.shape[0] == 0:
+ # expand init_latents for batch_size
+ additional_image_per_prompt = batch_size // image_latents.shape[0]
+ image_latents = torch.cat([image_latents] * additional_image_per_prompt, dim=0)
+ elif batch_size > image_latents.shape[0] and batch_size % image_latents.shape[0] != 0:
+ raise ValueError(
+ f"Cannot duplicate `image` of batch size {image_latents.shape[0]} to {batch_size} text prompts."
+ )
+ else:
+ image_latents = torch.cat([image_latents], dim=0)
+
noise = randn_tensor(shape, generator=generator, device=device, dtype=dtype)
latents = noise if is_strength_max else self.scheduler.scale_noise(image_latents, timestep, noise)
noise = self._pack_latents(noise, batch_size, num_channels_latents, height, width)
@@ -882,7 +893,7 @@ class FluxDifferentialImg2ImgPipeline(DiffusionPipeline, FluxLoraLoaderMixin):
mask_thresholds = mask_thresholds.unsqueeze(1).unsqueeze(1).to(device)
masks = (original_mask > mask_thresholds)
masks = self._pack_latents(
- masks.repeat(num_channels_latents, 1, 1, 1).permute(1, 0, 2, 3),
+ masks.repeat(num_channels_latents // num_images_per_prompt, 1, 1, 1).permute(1, 0, 2, 3),
len(mask_thresholds),
num_channels_latents,
2 * (int(height) // self.vae_scale_factor), |
thanks for this work! What are the use cases for using this pipe with a For example, a fully dark pixel in the change map would no longer be totally overriden in the output image's corresponding pixel. |
Probably @exx8 can give you a more detailed answer, but for me, it's the same as when you use img2img or inpainting, if you use a strength of If you use a lower strength, the generation tries to adapt more to what was before and also diff-diff makes it that it merges better with the old part. This is IMO what makes great diff-diff, you can use it as inpainting or just to gradually change some parts of the image like in the demo or like I did here . In the same post you can also see what I did with the crow example, using 0.8 works great in that image because I didn't want to completely Apart from the strength you can also play with the brightness of the mask, IMO people don't really understand the versatility of what you can do with diff-diff, partially because the UIs don't have the kind of tools to work with masks and gradients. |
* Flux - soft inpainting via differential diffusion * . * track changes to FluxInpaintPipeline * make mask arrangement simplier * make style --------- Co-authored-by: YiYi Xu <[email protected]> Co-authored-by: Álvaro Somoza <[email protected]> Co-authored-by: asomoza <[email protected]>
What does this PR do?
Adds a new community pipeline that brings Differential Diffusion to the Flux.1 family of models (currently Flux.1-schnell and Flux.1-dev).
Builds right on top of the fantastic work of #9135. My additions pertain only to the various
diff diff
annotations.Things to do:
Testing
Flux.1-schnell
The schnell model can be used following this example:
A red strawberry, black background
(12 steps at 0.9 strength):Blending with the schnell model is hard to get right
Flux.1-dev
I expect the Dev model to be used via this if there is sufficient vram:
My tests/usages, however, were all done on the FP8 quantized version (https://huggingface.co/Kijai/flux-fp8/blob/main/flux1-dev-fp8.safetensors):
A green pear, black background
(50 steps at 1.0 strength):painting of a mountain landscape with a meadow and a forest, meadow background, anime countryside landscape, anime nature wallpap, anime landscape wallpaper, studio ghibli landscape, anime landscape, mountain behind meadow, anime background art, studio ghibli environment, background of flowery hill, anime beautiful peace scene, forrest background, anime scenery, landscape background, background art, anime scenery concept art
(20 steps at 1.0 strength):Before submitting
Who can review?