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

Flux Image-To-Image pipeline #1524

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dsocek
Copy link
Contributor

@dsocek dsocek commented Nov 25, 2024

FLUX Image-to-Image Pipeline

List of Contributions in this PR

  • FLUX.1 image-to-image pipeline Gaudi added
  • Added support for FLUX.1 inference in examples/stable-diffusion/image_to_image_generation.py sample
  • Updated documentation with FLUX.1 image-to-image examples/command-lines
  • Added FLUX.1 image-to-image CI tests

Quality Check

Quality of output image shows good guidance from the input image and accompanying prompt.

Input image:
input

Input prompt:

"cat wizard, gandalf, lord of the rings, detailed, fantasy, cute, adorable, Pixar, Disney, 8k"

Simple inference script:

import torch
from diffusers.utils import load_image
from optimum.habana.diffusers import GaudiFluxImg2ImgPipeline

pipe = GaudiFluxImg2ImgPipeline.from_pretrained(
    "black-forest-labs/FLUX.1-dev",
    torch_dtype=torch.bfloat16,
    use_habana=True,
    use_hpu_graphs=True,
    gaudi_config="Habana/stable-diffusion",
)

url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png"
init_image = load_image(url).resize((1024, 1024))

prompt = "cat wizard, gandalf, lord of the rings, detailed, fantasy, cute, adorable, Pixar, Disney, 8k"

image = pipe(
    prompt=prompt, image=init_image, num_inference_steps=30, strength=0.9, guidance_scale=3.5
).images[0]
image.save("flux_img2img.png")

Output image:
output

Performance

Performance matches the Gaudi FLUX.1 text-to-image pipeline performance.

Tests

The added CI tests for Gaudi FLUX.1 image-to-image pipeline PASSED:

python -m pytest tests/test_diffusers.py -v -s -k "GaudiFluxImg2ImgPipelineTester"
...
============ 2 passed, 162 deselected, 1 warning in 11.50s =============

dsocek and others added 2 commits November 25, 2024 19:36
* Enabled and tested FLUX pipeline on Gaudi for FLUX.1 class of models
* Enabled HPU graphs mode
* Enabled batching in inference
* Added support for quantization (fp8 and hybrid)
* Incorporated Gaudi profiler and HPU Synchronization for performance analysis
* Boosted performance with Fused SDPA
* Added Fused RoPE
* Documented FLUX.1 samples
* Upgraded and pinned diffusers in Optimum-Habana to official release 0.31.0
* Resolved issues in other pipelines due to diffusers upgrade
* Added CI tests (2 unit tests, 1 slow test for perf and quality)

Signed-off-by: Daniel Socek <[email protected]>
Co-authored-by: Baochen Yang <[email protected]>
Co-authored-by: Huijuan Zhou <[email protected]>
Co-authored-by: Sergey Plotnikov <[email protected]>
Co-authored-by: Deepak Narayana <[email protected]>
Signed-off-by: Daniel Socek <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant