Skip to content

add tensor and numpy array support for image input in Flux2KleinPipeline#13265

Open
abhixb wants to merge 1 commit intohuggingface:mainfrom
abhixb:fix/flux2-klein-tensor-input
Open

add tensor and numpy array support for image input in Flux2KleinPipeline#13265
abhixb wants to merge 1 commit intohuggingface:mainfrom
abhixb:fix/flux2-klein-tensor-input

Conversation

@abhixb
Copy link

@abhixb abhixb commented Mar 14, 2026

Fixed issue #13177

The problem

If you pass a tensor or numpy array as the image to the Klein pipeline, it errors even though the docstring explicitly says these types are supported. Three things cause this:

  • The image processor's validation method has a hard isinstance check for PIL and just rejects everything else on the spot
  • The image loop in the pipeline's call method does image_width, image_height = img.size which is PIL only on a tensor .size is a method, on a numpy array it's a single int, both explode when you try to unpack them
  • The type annotation on the image parameter only mentions PIL types, so your IDE would tell you not to even try

The fix

  • Added a to_pil helper on the image processor that converts tensors and numpy arrays into PIL images, PIL inputs just pass through
  • Wired it into the validation method so it converts first, validates second, and returns a guaranteed PIL image
  • The call method's image loop now uses that return value instead of throwing it away
  • Updated the type annotation to match the docstring

Nothing changes for people already passing PIL images, same code path as before.

Tests

Added tests for tensor input, numpy input, and a list of tensors for multi-reference editing. Existing PIL test still passes. All 4 green locally.

@abhixb abhixb changed the title This PR fixes ISSUE #13177 This PR adds tensor and numpy array support for image input in Flux2KleinPipeline Mar 14, 2026
@abhixb abhixb changed the title This PR adds tensor and numpy array support for image input in Flux2KleinPipeline added tensor and numpy array support for image input in Flux2KleinPipeline Mar 14, 2026
@abhixb
Copy link
Author

abhixb commented Mar 15, 2026

@sayakpaul hello can u please look into/review this

@abhixb abhixb changed the title added tensor and numpy array support for image input in Flux2KleinPipeline add tensor and numpy array support for image input in Flux2KleinPipeline Mar 16, 2026
@asomoza
Copy link
Member

asomoza commented Mar 19, 2026

thanks @abhixb, this is not correct and will need a complete rewrite, first you're changing a method in the image processor which this is not the only pipeline that calls it, you're creating unnecessary tests and one of those is completely wrong and you're converting tensors to a pil image, but then the pipeline has to convert it back to tensors...

Please provide a correct solution, and just in case, I won't review this issue again if it's done completely by the llm without you understanding what is it doing and what should be done to fix the issue.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants