Skip to content

Conversation

@williamberman
Copy link
Contributor

@williamberman williamberman commented Feb 27, 2023

Currently used test config

allowed_required_args

  • testing that all required parameters on all pipelines are from a subset of variable names -> ends up not really testing much because when we add a new pipeline with a new required parameter, we just add it to the list. this isn't really checking an invariant or anything.
  • also being used to configure what parameters to batch in another location -> this is really separate configuration as there's no real requirement that required parameters are batched
  • This also gets a bit confusing as we don't have consistent treatment of required parameters and in many cases don't have any required parameters. I.e. prompt which you would think is the canonical required parameter is really technically optional in most pipelines as we allow overriding it with prompt_embeddings.

required_optional_params

This is a good config but we could add a few more of the commonly included optional parameters

num_inference_steps_args

This was a bad hack that I added for testing batching on the unclip pipelines with many different inference stages.

Refactor

num_inference_steps_args -> remove and pass as argument to test helper function

required_optional_parameters is good but we want to add a few more of the default optional parameters i.e. callback/callback_steps.

Really we want to separate allowed_required_args into two parts:

  • A config for a set of parameters that are included in all (optional and required) paramers -> params
  • A config for batched parameters -> batch_params

Both params and batch_params are generally determined by the type of pipeline -- i.e. text to image, image variation. They are configured on the specific pipeline subclass with a good error message explaining why and how to configure them when they are not set. Because we don't have strict interfaces (i.e. not all image variation pipelines take height and width) on pipelines nor families of pipelines, params are easily tweaked from provided defaults with operations on frozenset.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Feb 27, 2023

The documentation is not available anymore as the PR was closed or merged.

@williamberman williamberman force-pushed the pipeline_argument_tests branch 6 times, most recently from 0c1420a to bf21775 Compare February 27, 2023 06:07
@williamberman williamberman changed the title wip argument tests PipelineTesterMixin argument configuration refactor Feb 27, 2023
@williamberman williamberman changed the title PipelineTesterMixin argument configuration refactor PipelineTesterMixin parameter configuration refactor Feb 27, 2023
@williamberman williamberman force-pushed the pipeline_argument_tests branch from bf21775 to e788d12 Compare February 27, 2023 06:42
Comment on lines +1 to +23
# These are canonical sets of parameters for different types of pipelines.
# They are set on subclasses of `PipelineTesterMixin` as `params` and
# `batch_params`.
#
# If a pipeline's set of arguments has minor changes from one of the common sets
# of arguments, do not make modifications to the existing common sets of arguments.
# I.e. a text to image pipeline with non-configurable height and width arguments
# should set its attribute as `params = TEXT_TO_IMAGE_PARAMS - {'height', 'width'}`.

TEXT_TO_IMAGE_PARAMS = frozenset(
[
"prompt",
"height",
"width",
"guidance_scale",
"negative_prompt",
"prompt_embeds",
"negative_prompt_embeds",
"cross_attention_kwargs",
]
)

TEXT_TO_IMAGE_BATCH_PARAMS = frozenset(["prompt", "negative_prompt"])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default param values for families of pipelines

Comment on lines +45 to +47
params = TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"height", "width"}
required_optional_params = PipelineTesterMixin.required_optional_params - {"latents"}
batch_params = TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example modifying default params

Comment on lines 38 to 53
# Canonical parameters that are passed to `__call__` regardless
# of the type of pipeline. They are always optional and have common
# sense default values.
required_optional_params = frozenset(
[
"num_inference_steps",
"num_images_per_prompt",
"eta",
"generator",
"latents",
"output_type",
"return_dict",
"callback",
"callback_steps",
]
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new set of required_optional_params

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it.

Comment on lines +99 to +111
@property
def batch_params(self) -> frozenset:
raise NotImplementedError(
"You need to set the attribute `batch_params` in the child test class. "
"`batch_params` are the parameters required to be batched when passed to the pipeline's "
"`__call__` method. `pipeline_params.py` provides some common sets of parameters such as "
"`TEXT_TO_IMAGE_BATCH_PARAMS`, `IMAGE_VARIATION_BATCH_PARAMS`, etc... If your pipeline's "
"set of batch arguments has minor changes from one of the common sets of batch arguments, "
"do not make modifications to the existing common sets of batch arguments. I.e. a text to "
"image pipeline `negative_prompt` is not batched should set the attribute as "
"`batch_params = TEXT_TO_IMAGE_BATCH_PARAMS - {'negative_prompt'}`. "
"See existing pipeline tests for reference."
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

batch_params with error message/docs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool!

@williamberman
Copy link
Contributor Author

note failing onnx tests seem unrelated

Comment on lines 37 to 42
"callback",
"latents",
"callback_steps",
"output_type",
"eta",
"num_images_per_prompt",
Copy link
Member

@sayakpaul sayakpaul Feb 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd group them into variable and then use it instead of defining ad-hoc. Applies here and elsewhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually ok for me as is - I'd just move "eta" out of the "required" optional base params. ETA is too specific & we shouldn't incentivize adding it in the future

Copy link
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very nice! My only suggestion is to move "eta" out of the required/default list of optional parameters. ETA is only relevant for DDIM and is also generally not used.

Going forward I actually don't think it's a good idea to have a "eta" argument for pipelines

[
"num_inference_steps",
"num_images_per_prompt",
"eta",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"eta",

I'd remove "eta" here. "eta" is a very specific case that doesn't apply to all pipelines. We probably shouldn't have added this at all in the first place

Comment on lines +99 to +111
@property
def batch_params(self) -> frozenset:
raise NotImplementedError(
"You need to set the attribute `batch_params` in the child test class. "
"`batch_params` are the parameters required to be batched when passed to the pipeline's "
"`__call__` method. `pipeline_params.py` provides some common sets of parameters such as "
"`TEXT_TO_IMAGE_BATCH_PARAMS`, `IMAGE_VARIATION_BATCH_PARAMS`, etc... If your pipeline's "
"set of batch arguments has minor changes from one of the common sets of batch arguments, "
"do not make modifications to the existing common sets of batch arguments. I.e. a text to "
"image pipeline `negative_prompt` is not batched should set the attribute as "
"`batch_params = TEXT_TO_IMAGE_BATCH_PARAMS - {'negative_prompt'}`. "
"See existing pipeline tests for reference."
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool!

Comment on lines 37 to 42
"callback",
"latents",
"callback_steps",
"output_type",
"eta",
"num_images_per_prompt",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually ok for me as is - I'd just move "eta" out of the "required" optional base params. ETA is too specific & we shouldn't incentivize adding it in the future


UNCONDITIONAL_AUDIO_GENERATION_PARAMS = frozenset(["batch_size"])

UNCONDITIONAL_AUDIO_GENERATION_BATCH_PARAMS = frozenset([])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nice! This is really helpful to classify the pipelines into certain tasks and should help us write new tests going forward

@williamberman williamberman merged commit 1a6fa69 into huggingface:main Mar 1, 2023
mengfei25 pushed a commit to mengfei25/diffusers that referenced this pull request Mar 27, 2023
* attend and excite batch test causing timeouts

* PipelineTesterMixin argument configuration refactor

* error message text re: @yiyixuxu

* remove eta re: @patrickvonplaten
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
* attend and excite batch test causing timeouts

* PipelineTesterMixin argument configuration refactor

* error message text re: @yiyixuxu

* remove eta re: @patrickvonplaten
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.

5 participants