huggingface / huggingface/diffusers

FLUX.1-Kontext-dev batch inference throughput issue

Open
#12,459 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug stale
Dominant language
Python
Stars
34.5k
Forks
7.3k
Avg merge
3d 3h
Merged PRs (30d)
91

Description

Describe the bug

I am trying to use FLUX.1-Kontext-dev in batch inference, but the inference time for batch is linear to batch size, e.g., time of batch size 2 ~= 2* time of batch size 1. This makes me confused, did I get something wrong or this is the issue with this pipeline?

Reproduction
import torch
from diffusers import FluxKontextPipeline
from diffusers.utils import load_image


# Load the pipeline
pipe = FluxKontextPipeline.from_pretrained(
    "black-forest-labs/FLUX.1-Kontext-dev", 
    torch_dtype=torch.bfloat16
)
pipe.to("cuda")

input_images = [
    load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png"),
    load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png")
]

prompts = [
    "Make it look like a watercolor painting",
    "Add dramatic lighting and shadows",
]
with torch.inference_mode():
    images = pipe(
        image=input_images,
        prompt=prompts,
        guidance_scale=2.5,
        num_inference_steps=28,
        generator=[torch.Generator("cuda").manual_seed(42),torch.Generator("cuda").manual_seed(123)]
    ).images

for i, img in enumerate(images):
    img.save(f"output_i2i_batch_{i}.png")
Logs

System Info
  • 🤗 Diffusers version: 0.36.0.dev0
  • Platform: Linux-6.8.0-63-generic-x86_64-with-glibc2.39
  • Running on Google Colab?: No
  • Python version: 3.10.18
  • PyTorch version (GPU?): 2.8.0+cu128 (True)
  • Flax version (CPU?/GPU?/TPU?): not installed (NA)
  • Jax version: not installed
  • JaxLib version: not installed
  • Huggingface_hub version: 0.35.3
  • Transformers version: 4.57.0
  • Accelerate version: 1.10.1
  • PEFT version: not installed
  • Bitsandbytes version: not installed
  • Safetensors version: 0.6.2
  • xFormers version: not installed
  • Accelerator: NVIDIA H100 NVL, 95830 MiB
    NVIDIA H100 NVL, 95830 MiB
    NVIDIA H100 NVL, 95830 MiB
    NVIDIA H100 NVL, 95830 MiB
    NVIDIA H100 NVL, 95830 MiB
    NVIDIA H100 NVL, 95830 MiB
    NVIDIA H100 NVL, 95830 MiB
    NVIDIA H100 NVL, 95830 MiB
Who can help?

@yiyixuxu @DN6

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduced FluxKontextPipeline call in the issue and measure batch sizes 1 and 2 using the supplied environment and inputs. Trace the inference path to determine whether linear timing is expected or indicates a batching problem; done means the behavior is explained and the issue is corrected or documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.