fix(image_processor): maintain 3-tuple return contract in InpaintProcessor.preprocess when mask is None - #14481
Open
patrickswedish wants to merge 2 commits into
Conversation
…reprocess when mask is None (huggingface#14470)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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