Skip to content

Generate Different Number of Images Without Recompilation #5

@liorRabkin

Description

@liorRabkin

I'm trying to generate a different number of images without recompilation. For example, warm up with 1 image and then generate with 2 images. I tried with dynamic=True, but I still get recompilation when changing num_images_per_prompt:

with torch._dynamo.config.patch(error_on_recompile=True):
      pipe = DiffusionPipeline.from_pretrained(
          "black-forest-labs/FLUX.1-dev,
          torch_dtype=torch.bfloat16,
      ).to("cuda")

      pipe.transformer = torch.compile(pipe.transformer, dynamic=True)

      # warmup
      image = pipe(prompt="A cat holding a sign that says hello world",
                   width=1024,
                   height=1024,
                   num_inference_steps=10,
                   num_images_per_prompt=1,
                   ).images[0]

      # inference
      image = pipe(prompt="A cat holding a sign that says hello world",
                   width=1024,
                   height=1024,
                   num_inference_steps=10,
                   num_images_per_prompt=2,
                   ).images[0]

The error:

torch._dynamo.exc.RecompileError: Recompiling function forward in /root/PycharmProjects/project/.venv/lib/python3.10/site-packages/diffusers/models/transformers/transformer_flux.py:389
    triggered by the following guard failure(s):
    - 0/0: tensor 'guidance' size mismatch at index 0. expected 1, actual 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions