Fibo Edit: multi-reference conditioning and batching - #14566
Fibo Edit: multi-reference conditioning and batching#14566ShivamShrirao wants to merge 7 commits into
Conversation
07d3dd6 to
91796cd
Compare
…base/turbo ids briaai/FIBO-edit-prompt-to-JSON is retired in favor of briaai/FIBO-edit-gemini-prompt-to-JSON, which handles multiple reference images and masks. Also corrects the checkpoint ids to their canonical briaai/Fibo-Edit-1.5-base and briaai/Fibo-Edit-1.5-turbo spellings.
yiyixuxu
left a comment
There was a problem hiding this comment.
thanks for the PR! i left some small comments
| return tuple(max(multiple, int(round(side * scale / multiple)) * multiple) for side in (width, height)) | ||
|
|
||
|
|
||
| def _vae_safe_size(image, base_resolution=1024, multiple=16): |
There was a problem hiding this comment.
can we in-line this function?
There was a problem hiding this comment.
the image_processor.preprocess change below does the resize, so this helper is no longer needed.
| return image if target == image.size else image.resize(target, Image.LANCZOS) | ||
|
|
||
|
|
||
| def _as_reference_images(image): |
There was a problem hiding this comment.
can we put this code inside call directly?
There was a problem hiding this comment.
Moved into call. It had a second call site in check_inputs, so rather than duplicate the validation I normalize once at the top of call and pass the list down.
| """VAE-encode one PIL reference at its own size and pack it as an edit-context token stream.""" | ||
| vae_dtype = next(self.vae.parameters()).dtype | ||
| image = _vae_safe_size(image.convert("RGB")) | ||
| pixels = torch.from_numpy(np.array(image)).permute(2, 0, 1).unsqueeze(0) |
There was a problem hiding this comment.
can we use the self.image_processor.preprocess(...)?
There was a problem hiding this comment.
Done. I pass explicit height/width from _vae_safe_dims so the multiple-of-16 rounding and the 1024²-pixel cap are preserved. Verified the output is identical to the manual path.
|
@bot /style |
|
Style fix is beginning .... View the workflow run here. |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
- collapse the mask branch to `if not attention_mask.all():` in both Fibo pipelines - encode references via `self.image_processor.preprocess(...)`, dropping the manual numpy normalization and the `_vae_safe_size` helper - normalize `image` into a reference list once in `__call__`, pass it to `check_inputs`
|
@ShivamShrirao |
|
@yiyixuxu done! |
What does this PR do?
Adds multi-reference image conditioning to
BriaFiboEditPipelineand fixes the two remaining items from thebria_fiboreview issue.Fixes the remaining items (issues 2 and 5) of #13618, issues 1/3/4/6 were fixed by #13981.
Multi-reference conditioning
imagenow accepts aPIL.Image.Imageor a list of them. A list means multiple references, not a batch:iis placed on RoPE time planei(generated tokens stay on plane 0).height/widthstill override it.Batching
num_images_per_prompt > 1now works, upstream crashed at a latent reshape because reference latents were never duplicated (fixes issue 5 of bria_fibo model/pipeline review #13618).test_num_images_per_promptis un-skipped and passes.Other fixes
timestepsare now honored in bothBriaFiboPipelineandBriaFiboEditPipeline, they were accepted and documented but hard-coded toNonein theretrieve_timestepscall (fixes issue 2 of bria_fibo model/pipeline review #13618).(batch, 1, 1, seq)instead of a float outer-product matrix, and is dropped entirely when nothing is padded, this keeps backends without mask support (flash-attn 2/3) usable atguidance_scale <= 1.BriaFiboTransformer2DModeldeclares_repeated_blocksfor regional compilation.do_patching=Truepreviously produced mismatched token widths between generated and reference latents (references were always packed unpatched); reference packing now followsdo_patching.Intentional behavior changes (please review)
torch.Tensorimage input now raises. References are PIL-only, following the Flux2 / QwenImage Edit Plus convention. Tensor input only became functional recently (fix(bria_fibo): fix guidance_embeds, prompt_embeds, tensor-image and multi-image crashes #13981 fixed a crash);np.ndarraywas already rejected.preprocessas a batch; it now means multiple references.image=[img]behaves identically to before.height/width(taken from the reference) behavior is equivalent; it only diverges when an explicit output size differs from the reference.Validation
i→ time idi, per-reference variable resolution, target-first sequence order).bria_fibo+bria_fibo_edittests pass. The pre-existingtest_inference_batch_single_identicalfailure in the basebria_fibosuite reproduces on currentmainwithout this PR, not introduced here.make style,make fix-copiesclean.Docs: added a "Multiple reference images" section to
bria_fibo_edit.mdwith a runnable two-reference example; fixed and extendedEXAMPLE_DOC_STRING.Self-review notes (final round)
Rubric:
.ai/review-rules.md(+.ai/AGENTS.md,.ai/pipelines.md,.ai/testing.md,.ai/models.md, model-integration pitfalls). Scope: full diff vs upstream base.Verdict: READY
No blocking findings. Reference preparation is a single public lifecycle method (
prepare_reference_latents) called from__call__, one code path handles one or N references, and tests assert on public API and end-to-end outputs only.Checks: full
bria_fibo+bria_fibo_editfast suites pass (aside from the pre-existing failure noted below),make styleclean,check_copiesclean.Behavior changes (disclosed intentionally)
torch.Tensorimage input now raises (was supported upstream since fix(bria_fibo): fix guidance_embeds, prompt_embeds, tensor-image and multi-image crashes #13981). References are PIL-only, following the Flux2 / QwenImage Edit Plus convention.np.ndarraywas already rejected upstream, unchanged.preprocessas a batch; a list now means multiple references.image=[img]behaves identically to before;image=[a, b]is a two-reference edit.timestepsare now honored in both pipelines (fixes issue 2 of bria_fibo model/pipeline review #13618): they were accepted and documented but hard-coded toNonein theretrieve_timestepscall, silently falling back to the default schedule.num_images_per_prompt > 1now works in the edit pipeline (fixes issue 5 of bria_fibo model/pipeline review #13618): upstream crashed at a latent reshape because reference latents were never duplicated. Everything now keys off the encoded prompt batch (batch_size * num_images_per_prompt);test_num_images_per_promptis un-skipped and passes.Left for the reviewer
_vae_safe_dims/_vae_safe_sizecarrybase_resolution=1024/multiple=16defaults no caller overrides, named constants vs. unused knobs is a judgment call.test_inference_batch_single_identicalfailure in the basebria_fibopipeline reproduces onmainwithout this PR, not introduced here.Dead-code analysis (advisory)
Traced
__call__end to end:paste_mask_on_image,is_valid_mask,get_mask_size, and bothdo_patchingbranches are all reachable. No likely-dead code beyond the default params noted above.Docs
docs/source/en/api/pipelines/bria_fibo_edit.mdgained a "Multiple reference images" section (semantics + runnable two-reference example);EXAMPLE_DOC_STRINGfixed (imports) and extended with a multi-reference call.Before submitting
self-reviewskill on the diff?Who can review?
@yiyixuxu @sayakpaul