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

fix FlUX.1_dev guidance_batches bug for pad case in _split_inputs_int… #1607

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion optimum/habana/diffusers/pipelines/flux/pipeline_flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,11 @@ def _split_inputs_into_batches(cls, batch_size, latents, prompt_embeds, pooled_p

# Pad guidance if necessary
if guidance is not None:
guidance_batches[-1]=guidance_batches[-1].unsqueeze(1)
sequence_to_stack = (guidance_batches[-1],) + tuple(
torch.zeros_like(guidance_batches[-1][0][None, :]) for _ in range(num_dummy_samples)
)
guidance_batches[-1] = torch.vstack(sequence_to_stack)
guidance_batches[-1] = torch.vstack(sequence_to_stack).squeeze(1)

# Stack batches in the same tensor
latents_batches = torch.stack(latents_batches)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,11 @@ def _split_inputs_into_batches(cls, batch_size, latents, prompt_embeds, pooled_p

# Pad guidance if necessary
if guidance is not None:
guidance_batches[-1]=guidance_batches[-1].unsqueeze(1)
sequence_to_stack = (guidance_batches[-1],) + tuple(
torch.zeros_like(guidance_batches[-1][0][None, :]) for _ in range(num_dummy_samples)
)
guidance_batches[-1] = torch.vstack(sequence_to_stack)
guidance_batches[-1] = torch.vstack(sequence_to_stack).squeeze(1)

# Stack batches in the same tensor
latents_batches = torch.stack(latents_batches)
Expand Down Expand Up @@ -623,14 +624,14 @@ def __call__(
f"After adjusting the num_inference_steps by strength parameter: {strength}, the number of pipeline"
f"steps is {num_inference_steps} which is < 1 and not appropriate for this pipeline."
)
latent_timestep = timesteps[:1].repeat(batch_size * num_images_per_prompt)
latent_timestep = timesteps[:1].repeat(num_prompts * num_images_per_prompt)

# 6. Prepare latent variables
num_channels_latents = self.transformer.config.in_channels // 4
latents, latent_image_ids = self.prepare_latents(
init_image,
latent_timestep,
batch_size * num_images_per_prompt,
num_prompts * num_images_per_prompt,
num_channels_latents,
height,
width,
Expand Down