Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[InferenceClient] Better handling of task parameters #2812

Merged
merged 11 commits into from
Jan 31, 2025

Conversation

hanouticelina
Copy link
Contributor

This PR:

  • Fixes some discrepancies in text-to-image parameters (particularly for Together AI).
  • Adds a new extra_parameters argument to text_to_image, text_to_speech and text_to_video to be able to pass a provider's unique parameters for these tasks.
  • Improves the test suite of inference providers.

@hanouticelina hanouticelina requested a review from Wauplin January 30, 2025 17:11
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Contributor

@Wauplin Wauplin left a comment

Choose a reason for hiding this comment

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

Haven't tested anything locally but it looks good to me. Thanks for handling these discrepancies!

@@ -2407,7 +2405,7 @@ def text_to_image(
scheduler: Optional[str] = None,
target_size: Optional[TextToImageTargetSize] = None,
seed: Optional[int] = None,
**kwargs,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a breaking change but hopefully totally fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'll mention this in the next release notes! but it should be fine, if users were previously using text_to_image with the HF Inference API, this shouldn't be an issue since all API parameters were exposed as explicit method arguments

Copy link
Contributor

Choose a reason for hiding this comment

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

this shouldn't be an issue since all API parameters were exposed as explicit method arguments

yes exactly

@@ -2443,6 +2441,9 @@ def text_to_image(
The size in pixel of the output image
seed (`int`, *optional*):
Seed for the random number generator.
extra_parameters (`Dict[str, Any]`, *optional*):
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a good example of how to use extra_parameters for a specific model on a specific provider? Would be good to add a least one example (either in text-to-image or text-to-video depending on what's best)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, added in 305c720

src/huggingface_hub/inference/_providers/fal_ai.py Outdated Show resolved Hide resolved
src/huggingface_hub/inference/_providers/fal_ai.py Outdated Show resolved Hide resolved
Comment on lines +64 to +66
@pytest.mark.parametrize(
"helper,inputs,parameters,expected_data,expected_json",
[
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for adding these!

Copy link
Contributor

@Wauplin Wauplin left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@@ -134,7 +134,7 @@ def __init__(self):

def _prepare_payload(self, inputs: Any, parameters: Dict[str, Any]) -> Dict[str, Any]:
parameters = {k: v for k, v in parameters.items() if v is not None}
if "image_size" not in parameters and "width" in parameters and "height" in parameters:
if "width" in parameters and "height" in parameters:
Copy link
Contributor

Choose a reason for hiding this comment

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

what if only one if passed btw?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we should be able to send only one if specified, the other one would be set to the default value. I'll fix that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no actually for fal-ai, you either send both, or neither.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there is no default values for each one of them, according to their documentation

Copy link
Contributor

Choose a reason for hiding this comment

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

ok thanks for checking 👍

Copy link
Contributor

@Wauplin Wauplin left a comment

Choose a reason for hiding this comment

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

approving, though I'm not sure to understand what's happening in utils/generate_inference_types.py. I trust it we result is correct :)

@hanouticelina
Copy link
Contributor Author

should be good now, let's merge!

@hanouticelina hanouticelina merged commit 07e1adb into main Jan 31, 2025
17 checks passed
@hanouticelina hanouticelina deleted the task-parameters branch January 31, 2025 11:05
Copy link
Member

@julien-c julien-c left a comment

Choose a reason for hiding this comment

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

(nit) i think OpenAI calls this param extra_body (https://docs.vllm.ai/en/latest/serving/openai_compatible_server.html#extra-parameters or from the Python openai sdk), but i think our name is probably fine too 🤷

@Wauplin
Copy link
Contributor

Wauplin commented Jan 31, 2025

Then I'm down to go with extra_body before making a release for consistency

@julien-c
Copy link
Member

julien-c commented Feb 1, 2025

up to you (i'm not sure it's exactly the same use case, but my brain is fried)

@hanouticelina
Copy link
Contributor Author

It's actually the same use case, you can send an extra parameter using openai client, but i'm not sure if it's extra_body or extra_query (they expose both). Let me double check and open a PR to use the same naming on our side.

@julien-c
Copy link
Member

julien-c commented Feb 1, 2025

extra_query goes into the URL query params no? (just guessing)

@hanouticelina
Copy link
Contributor Author

yep, just wanted to double check in their docstrings, since it's not really documented.
Indeed, extra_body -> adds parameters to the JSON body and extra_query -> adds parameters as query string to the URL.
Let's rename extra_parameters to extra_body then!

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.

4 participants