fix(image_processor): maintain 3-tuple return contract in InpaintProcessor.preprocess when mask is None - #14481
Conversation
|
I closed my duplicate #14807 in favor of this PR after comparing the diffs. This change covers the same no-mask contract and also tests masked and padding-crop paths with the precise optional-mask return type. Could a maintainer review or identify any remaining concern? |
| assert postprocessing_kwargs["original_image"] is None | ||
| assert postprocessing_kwargs["original_mask"] is None | ||
|
|
||
| def test_inpaint_processor_preprocess_with_padding_mask_crop(self): |
There was a problem hiding this comment.
can we just reduce to one test? you can use @pytest.mark.parametrize
There was a problem hiding this comment.
Thanks for the feedback, @yiyixuxu! Updated to consolidate into a single @pytest.mark.parametrize test covering the with-mask, without-mask, and crop configurations. Rebased cleanly on latest main, squashed to a single atomic commit, and verified all tests and linting pass locally.
8816fd2 to
b9bb68a
Compare
|
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. |
|
@bot /style |
…one (huggingface#14470) Ensure InpaintProcessor.preprocess returns (image, None, postprocessing_kwargs) when mask is None, preserving the expected 3-tuple return contract and signature consistency across all preprocess branches. Consolidate unit tests into a parameterized test covering with-mask, without-mask, and crop configurations.
b9bb68a to
eca79aa
Compare
|
Thanks for the review and approval, @yiyixuxu! I've formatted the imports to satisfy Ruff I001 and updated the branch cleanly. |
What does this PR do?
Fixes #14470.
InpaintProcessor.preprocessreturns a 3-tuple(image, mask, postprocessing_kwargs)across all masked execution paths, but whenmask is None, the early return returned only the processed image tensor directly. Callers unpacking the standard 3-value contract (image, mask, postprocessing_kwargs = processor.preprocess(...)) would raiseValueError: not enough values to unpack (expected 3, got 1).Root Cause
When the 3-value contract and
postprocessing_kwargswere introduced in commitf50b18eec(#12220), the early return formask is Nonewas not updated to return the consistent 3-tuple structure. Additionally, the return type annotation indicatedtuple[torch.Tensor, torch.Tensor], which did not reflect the 3-element return value or optional mask.Changes
InpaintProcessor.preprocessinsrc/diffusers/image_processor.pywhenmask is Noneto return(processed_image, None, postprocessing_kwargs)wherepostprocessing_kwargsis populated with{"crops_coords": None, "original_image": None, "original_mask": None}.tuple[torch.Tensor, torch.Tensor | None, dict[str, Any]].tests/others/test_image_processor.pycoveringpreprocesswith mask, without mask (mask=None), and withpadding_mask_crop.Before submitting
Who can review?
@DN6 @yiyixuxu