fix(flux): tighten check_inputs validation#13955
Conversation
…olnet img2img dims, redux scales
|
Hi @akshan-main, thanks for the PR! It does not appear to link an issue it fixes. If this PR addresses an existing issue, please add a closing keyword (e.g. |
| raise ValueError(f"The value of strength should in [0.0, 1.0] but is {strength}") | ||
|
|
||
| if height % self.vae_scale_factor * 2 != 0 or width % self.vae_scale_factor * 2 != 0: | ||
| if height % (self.vae_scale_factor * 2) != 0 or width % (self.vae_scale_factor * 2) != 0: |
There was a problem hiding this comment.
What value is this adding though?
There was a problem hiding this comment.
For consistency, all flux pipelines have the same 2 * (height // (vae_scale_factor * 2)) round-down in prepare_latents, but the others raise in check_inputs first, so an invalid size like 72 errors there and never reaches it. This is the only flux pipeline that silently resizes to 64 instead of erroring. Precedencies!
| if prompt_embeds is not None and negative_prompt_embeds is not None: | ||
| if prompt_embeds.shape != negative_prompt_embeds.shape: | ||
| raise ValueError( | ||
| "`prompt_embeds` and `negative_prompt_embeds` must have the same shape when passed directly, but" | ||
| f" got: `prompt_embeds` {prompt_embeds.shape} != `negative_prompt_embeds`" | ||
| f" {negative_prompt_embeds.shape}." | ||
| ) | ||
|
|
There was a problem hiding this comment.
I think this should also be checked when do_true_cfg is True? Otherwise, it's not used right?
There was a problem hiding this comment.
moved it into the do_true_cfg branch in both base flux and kontext, so the shape check only runs when the negative embeds are used.
What does this PR do?
Addresses part of the flux review (#13584) - three input-validation gaps in the flux pipelines:
FluxPipeline/FluxKontextPipelineacceptednegative_prompt_embedswith a different shape thanprompt_embeds. Added the shape check the img2img/inpaint variants already have (propagated to kontext via# Copied from).FluxControlNetImg2ImgPipelinecheckedheight % self.vae_scale_factor * 2, which parses as(height % vae_scale_factor) * 2, so invalid sizes like 72 passed. Added the parentheses to match every other flux pipeline.FluxPriorReduxPipelineonly validated scale length for list images and ignoredpooled_prompt_embeds_scale. Now computes the image batch size for tensors too and validates both scales.Verified each finding's repro now raises/flags, and that matching/valid inputs still pass.
Before submitting
Who can review?
@hlky @sayakpaul @yiyixuxu