fix: parameters order assumption in diffuser#706
Conversation
This change ensures that the inference handler is compatible with diffuser pipelines that do not have a leading positional `prompt` argument, such as Flux2KleinPipeline.
|
@begumcig What do you think about reusing I see that you have made such a change in some other metrics a year ago (e.g., here) and wondered whether there was a particular reason why these two were not changed. One small concern with metric_energy is that the current code avoids constantly moving the batch to the "device" and preparing the inputs (as it does it only once - code here. In case we use AFAIU, the metric_model_architecture would not be affected. |
gsprochette
left a comment
There was a problem hiding this comment.
Looks good, @begumcig knows more than me about the inference handler so maybe she'll find missing edge cases but I didn't see one :) Thanks a lot !
This change is necessary to ensure Flux2KleinPipeline is supported.

Description
This change ensures that the inference handler is compatible with diffuser pipelines that do not have "prompt" as a first parameter, such as Flux2KleinPipeline.
Extra
DiffuserHandler, specifying the expected behavior forprepare_inputs.collate.pymodule, elaborating on the return types for each collate method.Related Issue
Many diffusers pipelines, such as QwenImagePipeline, have "prompt" as a first parameter. The existing code relied on this assumption - as we can see here,
However, not all diffusers pipelines have the same signature. Flux2KleinPipeline for example expects model on first position and prompt on second.
Running a pruna evaluation with the Flux2 model resulted in an error
Important
This change is backward compatible and does not break any existing working scenarios. It expands the usecases to diffusion models which do not expect
prompton first position (e.g., Flux2KleinPipeline), but does NOT resolve the following hypothetical problems/limitations.run_inferencewould expect the model inputs to be the first element in the batch passed as argument.Neither the old implementation nor the new code handle these.
How?
The change in the metrics follows the already established patter to unwrap the prepared inputs - the way it's done in PrunaModel.run_inference used in evaluation_agent, the elapsed time metric, and handlethe memory metric.
Type of Change
Testing
handler_diffusersmodule. They exercise theprepare_inputsbehavior underimage_generation_collate,prompt_collate, andprompt_with_auxiliaries_collate),uv run pytest -m "cpu and not slow")For full setup and testing instructions, see the Contributing Guide.
Checklist
TL;DR
I explored all the pruna native datasets (resolvable through
PrunaDataModule.fromString) and the way they are processed (i.e., the collate functions). Here is a list with their groups by collate:Considering our scope - diffusion models, only Image Generation tasks are relevant. This limits the datasets to 1, 2, and 3. The audio collate is not appropriate for audio generation as it provides only the original audio and its transcription, without any description of what's in the audio.
Furthermore, diffusion models can also be used for the other tasks (image classification, text generation, or Q&A), even though they are not really popular and require careful manipulation. The structure provided by 5, 6, and 7 does not match the desired custom structure requested by these models and thus we do not support them.
Thanks for contributing to Pruna! We're excited to review your work.
New to contributing? Check out our Contributing Guide for everything you need to get started.