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

[Inference] Support stop parameter in text-generation instead of stop_sequences #2473

Merged
merged 5 commits into from
Aug 26, 2024

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Aug 21, 2024

Fix #2471 cc @sadra-barikbin.

This PR deprecates stop_sequences in favor of the stop parameter for the text_generation task.

Context: in both TGI and the text_generation specs the stop parameter is provide stop tokens to the model. However historically transformers was using the stop_sequences parameter which had been propagated to Inference API and InferenceClient. Since we are now TGI-first (i.e. even transformers models are served with TGI), let's just expose stop.

>>> from huggingface_hub import InferenceClient
>>> InferenceClient("gpt2").text_generation("The capital of France is", stop=["Republic"])
 the capital of the French Republic

@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
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Makes sense! cc @gante @ArthurZucker maybe at some point we'll want to align stop_sequences to stop if that's what's used everywhere else

Copy link
Contributor

@osanseviero osanseviero left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -1655,7 +1655,8 @@ def text_generation( # type: ignore
repetition_penalty: Optional[float] = None,
return_full_text: Optional[bool] = False, # Manual default value
seed: Optional[int] = None,
stop_sequences: Optional[List[str]] = None, # Same as `stop`
stop: Optional[List[str]] = None,
stop_sequences: Optional[List[str]] = None, # Deprecated, use `stop` instead
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that transformers now uses stop_strings but as you mention, transformers will be deployed with TGI so not big deal

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually this will be an issue with IE deployment if not using TGI right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes and no, it's harder than that as you found out (private gdoc)

@Wauplin Wauplin merged commit 3be2afb into main Aug 26, 2024
15 of 17 checks passed
@Wauplin Wauplin deleted the 2471-support-stop-parameter-in-text-generation branch August 26, 2024 13:06
@Wauplin
Copy link
Contributor Author

Wauplin commented Aug 26, 2024

Thanks both for the reviews!

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.

To unify text_generation()'s stop_sequences and TextGenerationInput's stop params
4 participants