Skip to content

fix(image_processor): maintain 3-tuple return contract in InpaintProcessor.preprocess when mask is None - #14481

Open
patrickswedish wants to merge 2 commits into
huggingface:mainfrom
patrickswedish:fix-inpaint-processor-preprocess-contract
Open

patrickswedish wants to merge 2 commits into
huggingface:mainfrom
patrickswedish:fix-inpaint-processor-preprocess-contract

Conversation

@patrickswedish

Copy link
Copy Markdown

What does this PR do?

Fixes #14470.

InpaintProcessor.preprocess returns a 3-tuple (image, mask, postprocessing_kwargs) across all masked execution paths, but when mask 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 raise ValueError: not enough values to unpack (expected 3, got 1).

Root Cause

When the 3-value contract and postprocessing_kwargs were introduced in commit f50b18eec (#12220), the early return for mask is None was not updated to return the consistent 3-tuple structure. Additionally, the return type annotation indicated tuple[torch.Tensor, torch.Tensor], which did not reflect the 3-element return value or optional mask.

Changes

  • Updated InpaintProcessor.preprocess in src/diffusers/image_processor.py when mask is None to return (processed_image, None, postprocessing_kwargs) where postprocessing_kwargs is populated with {"crops_coords": None, "original_image": None, "original_mask": None}.
  • Updated return type annotation to tuple[torch.Tensor, torch.Tensor | None, dict[str, Any]].
  • Added unit tests in tests/others/test_image_processor.py covering preprocess with mask, without mask (mask=None), and with padding_mask_crop.

Before submitting

Who can review?

@DN6 @yiyixuxu

@lindicaphxag-tech

Copy link
Copy Markdown

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?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M PR with diff < 200 LOC tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InpaintProcessor.preprocess returns a bare tensor when no mask is passed, breaking its own 3-value contract

2 participants