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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions src/huggingface_hub/inference/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

temperature: Optional[float] = None,
top_k: Optional[int] = None,
top_n_tokens: Optional[int] = None,
Expand Down Expand Up @@ -1684,7 +1685,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
temperature: Optional[float] = None,
top_k: Optional[int] = None,
top_n_tokens: Optional[int] = None,
Expand Down Expand Up @@ -1713,7 +1715,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
temperature: Optional[float] = None,
top_k: Optional[int] = None,
top_n_tokens: Optional[int] = None,
Expand Down Expand Up @@ -1742,7 +1745,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
temperature: Optional[float] = None,
top_k: Optional[int] = None,
top_n_tokens: Optional[int] = None,
Expand Down Expand Up @@ -1771,7 +1775,8 @@ def text_generation(
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
temperature: Optional[float] = None,
top_k: Optional[int] = None,
top_n_tokens: Optional[int] = None,
Expand Down Expand Up @@ -1799,7 +1804,8 @@ def text_generation(
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
temperature: Optional[float] = None,
top_k: Optional[int] = None,
top_n_tokens: Optional[int] = None,
Expand Down Expand Up @@ -1864,8 +1870,10 @@ def text_generation(
Whether to prepend the prompt to the generated text
seed (`int`, *optional*):
Random sampling seed
stop (`List[str]`, *optional*):
Stop generating tokens if a member of `stop` is generated.
stop_sequences (`List[str]`, *optional*):
Stop generating tokens if a member of `stop_sequences` is generated
Deprecated argument. Use `stop` instead.
temperature (`float`, *optional*):
The value used to module the logits distribution.
top_n_tokens (`int`, *optional*):
Expand Down Expand Up @@ -2009,6 +2017,15 @@ def text_generation(
)
decoder_input_details = False

if stop_sequences is not None:
warnings.warn(
"`stop_sequences` is a deprecated argument for `text_generation` task"
" and will be removed in version '0.28.0'. Use `stop` instead.",
FutureWarning,
)
if stop is None:
stop = stop_sequences # use deprecated arg if provided

# Build payload
parameters = {
"adapter_id": adapter_id,
Expand All @@ -2022,7 +2039,7 @@ def text_generation(
"repetition_penalty": repetition_penalty,
"return_full_text": return_full_text,
"seed": seed,
"stop": stop_sequences if stop_sequences is not None else [],
"stop": stop if stop is not None else [],
"temperature": temperature,
"top_k": top_k,
"top_n_tokens": top_n_tokens,
Expand Down Expand Up @@ -2092,7 +2109,7 @@ def text_generation(
repetition_penalty=repetition_penalty,
return_full_text=return_full_text,
seed=seed,
stop_sequences=stop_sequences,
stop=stop,
temperature=temperature,
top_k=top_k,
top_n_tokens=top_n_tokens,
Expand Down
35 changes: 26 additions & 9 deletions src/huggingface_hub/inference/_generated/_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,8 @@ async 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
temperature: Optional[float] = None,
top_k: Optional[int] = None,
top_n_tokens: Optional[int] = None,
Expand Down Expand Up @@ -1717,7 +1718,8 @@ async 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
temperature: Optional[float] = None,
top_k: Optional[int] = None,
top_n_tokens: Optional[int] = None,
Expand Down Expand Up @@ -1746,7 +1748,8 @@ async 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
temperature: Optional[float] = None,
top_k: Optional[int] = None,
top_n_tokens: Optional[int] = None,
Expand Down Expand Up @@ -1775,7 +1778,8 @@ async 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
temperature: Optional[float] = None,
top_k: Optional[int] = None,
top_n_tokens: Optional[int] = None,
Expand Down Expand Up @@ -1804,7 +1808,8 @@ async def text_generation(
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
temperature: Optional[float] = None,
top_k: Optional[int] = None,
top_n_tokens: Optional[int] = None,
Expand Down Expand Up @@ -1832,7 +1837,8 @@ async def text_generation(
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
temperature: Optional[float] = None,
top_k: Optional[int] = None,
top_n_tokens: Optional[int] = None,
Expand Down Expand Up @@ -1897,8 +1903,10 @@ async def text_generation(
Whether to prepend the prompt to the generated text
seed (`int`, *optional*):
Random sampling seed
stop (`List[str]`, *optional*):
Stop generating tokens if a member of `stop` is generated.
stop_sequences (`List[str]`, *optional*):
Stop generating tokens if a member of `stop_sequences` is generated
Deprecated argument. Use `stop` instead.
temperature (`float`, *optional*):
The value used to module the logits distribution.
top_n_tokens (`int`, *optional*):
Expand Down Expand Up @@ -2043,6 +2051,15 @@ async def text_generation(
)
decoder_input_details = False

if stop_sequences is not None:
warnings.warn(
"`stop_sequences` is a deprecated argument for `text_generation` task"
" and will be removed in version '0.28.0'. Use `stop` instead.",
FutureWarning,
)
if stop is None:
stop = stop_sequences # use deprecated arg if provided

# Build payload
parameters = {
"adapter_id": adapter_id,
Expand All @@ -2056,7 +2073,7 @@ async def text_generation(
"repetition_penalty": repetition_penalty,
"return_full_text": return_full_text,
"seed": seed,
"stop": stop_sequences if stop_sequences is not None else [],
"stop": stop if stop is not None else [],
"temperature": temperature,
"top_k": top_k,
"top_n_tokens": top_n_tokens,
Expand Down Expand Up @@ -2126,7 +2143,7 @@ async def text_generation(
repetition_penalty=repetition_penalty,
return_full_text=return_full_text,
seed=seed,
stop_sequences=stop_sequences,
stop=stop,
temperature=temperature,
top_k=top_k,
top_n_tokens=top_n_tokens,
Expand Down
Loading