Skip to content

Commit b058a04

Browse files
Wauplingithub-actions[bot]
authored andcommitted
Update inference types (automated commit)
1 parent 6983a4d commit b058a04

33 files changed

+562
-399
lines changed

src/huggingface_hub/inference/_client.py

Lines changed: 158 additions & 81 deletions
Large diffs are not rendered by default.

src/huggingface_hub/inference/_generated/_async_client.py

Lines changed: 158 additions & 81 deletions
Large diffs are not rendered by default.

src/huggingface_hub/inference/_generated/types/audio_classification.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class AudioClassificationParameters(BaseInferenceType):
1717

1818
function_to_apply: Optional["AudioClassificationOutputTransform"] = None
1919
"""The function to apply to the model outputs in order to retrieve the scores."""
20-
top_k: int | None = None
20+
top_k: Optional[int] = None
2121
"""When specified, limits the output to the top K most probable classes."""
2222

2323

@@ -29,7 +29,7 @@ class AudioClassificationInput(BaseInferenceType):
2929
"""The input audio data as a base64-encoded string. If no `parameters` are provided, you can
3030
also provide the audio data as a raw bytes payload.
3131
"""
32-
parameters: AudioClassificationParameters | None = None
32+
parameters: Optional[AudioClassificationParameters] = None
3333
"""Additional inference parameters for Audio Classification"""
3434

3535

src/huggingface_hub/inference/_generated/types/automatic_speech_recognition.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# See:
44
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
55
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
6-
from typing import Literal, Union
6+
from typing import Literal, Optional, Union
77

88
from .base import BaseInferenceType, dataclass_with_extra
99

@@ -15,17 +15,17 @@
1515
class AutomaticSpeechRecognitionGenerationParameters(BaseInferenceType):
1616
"""Parametrization of the text generation process"""
1717

18-
do_sample: bool | None = None
18+
do_sample: Optional[bool] = None
1919
"""Whether to use sampling instead of greedy decoding when generating new tokens."""
20-
early_stopping: Union[bool, "AutomaticSpeechRecognitionEarlyStoppingEnum"] | None = None
20+
early_stopping: Optional[Union[bool, "AutomaticSpeechRecognitionEarlyStoppingEnum"]] = None
2121
"""Controls the stopping condition for beam-based methods."""
22-
epsilon_cutoff: float | None = None
22+
epsilon_cutoff: Optional[float] = None
2323
"""If set to float strictly between 0 and 1, only tokens with a conditional probability
2424
greater than epsilon_cutoff will be sampled. In the paper, suggested values range from
2525
3e-4 to 9e-4, depending on the size of the model. See [Truncation Sampling as Language
2626
Model Desmoothing](https://hf.co/papers/2210.15191) for more details.
2727
"""
28-
eta_cutoff: float | None = None
28+
eta_cutoff: Optional[float] = None
2929
"""Eta sampling is a hybrid of locally typical sampling and epsilon sampling. If set to
3030
float strictly between 0 and 1, a token is only considered if it is greater than either
3131
eta_cutoff or sqrt(eta_cutoff) * exp(-entropy(softmax(next_token_logits))). The latter
@@ -34,50 +34,50 @@ class AutomaticSpeechRecognitionGenerationParameters(BaseInferenceType):
3434
See [Truncation Sampling as Language Model Desmoothing](https://hf.co/papers/2210.15191)
3535
for more details.
3636
"""
37-
max_length: int | None = None
37+
max_length: Optional[int] = None
3838
"""The maximum length (in tokens) of the generated text, including the input."""
39-
max_new_tokens: int | None = None
39+
max_new_tokens: Optional[int] = None
4040
"""The maximum number of tokens to generate. Takes precedence over max_length."""
41-
min_length: int | None = None
41+
min_length: Optional[int] = None
4242
"""The minimum length (in tokens) of the generated text, including the input."""
43-
min_new_tokens: int | None = None
43+
min_new_tokens: Optional[int] = None
4444
"""The minimum number of tokens to generate. Takes precedence over min_length."""
45-
num_beam_groups: int | None = None
45+
num_beam_groups: Optional[int] = None
4646
"""Number of groups to divide num_beams into in order to ensure diversity among different
4747
groups of beams. See [this paper](https://hf.co/papers/1610.02424) for more details.
4848
"""
49-
num_beams: int | None = None
49+
num_beams: Optional[int] = None
5050
"""Number of beams to use for beam search."""
51-
penalty_alpha: float | None = None
51+
penalty_alpha: Optional[float] = None
5252
"""The value balances the model confidence and the degeneration penalty in contrastive
5353
search decoding.
5454
"""
55-
temperature: float | None = None
55+
temperature: Optional[float] = None
5656
"""The value used to modulate the next token probabilities."""
57-
top_k: int | None = None
57+
top_k: Optional[int] = None
5858
"""The number of highest probability vocabulary tokens to keep for top-k-filtering."""
59-
top_p: float | None = None
59+
top_p: Optional[float] = None
6060
"""If set to float < 1, only the smallest set of most probable tokens with probabilities
6161
that add up to top_p or higher are kept for generation.
6262
"""
63-
typical_p: float | None = None
63+
typical_p: Optional[float] = None
6464
"""Local typicality measures how similar the conditional probability of predicting a target
6565
token next is to the expected conditional probability of predicting a random token next,
6666
given the partial text already generated. If set to float < 1, the smallest set of the
6767
most locally typical tokens with probabilities that add up to typical_p or higher are
6868
kept for generation. See [this paper](https://hf.co/papers/2202.00666) for more details.
6969
"""
70-
use_cache: bool | None = None
70+
use_cache: Optional[bool] = None
7171
"""Whether the model should use the past last key/values attentions to speed up decoding"""
7272

7373

7474
@dataclass_with_extra
7575
class AutomaticSpeechRecognitionParameters(BaseInferenceType):
7676
"""Additional inference parameters for Automatic Speech Recognition"""
7777

78-
generation_parameters: AutomaticSpeechRecognitionGenerationParameters | None = None
78+
generation_parameters: Optional[AutomaticSpeechRecognitionGenerationParameters] = None
7979
"""Parametrization of the text generation process"""
80-
return_timestamps: bool | None = None
80+
return_timestamps: Optional[bool] = None
8181
"""Whether to output corresponding timestamps with the generated text"""
8282

8383

@@ -89,7 +89,7 @@ class AutomaticSpeechRecognitionInput(BaseInferenceType):
8989
"""The input audio data as a base64-encoded string. If no `parameters` are provided, you can
9090
also provide the audio data as a raw bytes payload.
9191
"""
92-
parameters: AutomaticSpeechRecognitionParameters | None = None
92+
parameters: Optional[AutomaticSpeechRecognitionParameters] = None
9393
"""Additional inference parameters for Automatic Speech Recognition"""
9494

9595

@@ -107,7 +107,7 @@ class AutomaticSpeechRecognitionOutput(BaseInferenceType):
107107

108108
text: str
109109
"""The recognized text."""
110-
chunks: list[AutomaticSpeechRecognitionOutputChunk] | None = None
110+
chunks: Optional[list[AutomaticSpeechRecognitionOutputChunk]] = None
111111
"""When returnTimestamps is enabled, chunks contains a list of audio chunks identified by
112112
the model.
113113
"""

src/huggingface_hub/inference/_generated/types/depth_estimation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# See:
44
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
55
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
6-
from typing import Any
6+
from typing import Any, Optional
77

88
from .base import BaseInferenceType, dataclass_with_extra
99

@@ -14,7 +14,7 @@ class DepthEstimationInput(BaseInferenceType):
1414

1515
inputs: Any
1616
"""The input image data"""
17-
parameters: dict[str, Any] | None = None
17+
parameters: Optional[dict[str, Any]] = None
1818
"""Additional inference parameters for Depth Estimation"""
1919

2020

src/huggingface_hub/inference/_generated/types/document_question_answering.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# See:
44
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
55
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
6-
from typing import Any
6+
from typing import Any, Optional, Union
77

88
from .base import BaseInferenceType, dataclass_with_extra
99

@@ -22,31 +22,31 @@ class DocumentQuestionAnsweringInputData(BaseInferenceType):
2222
class DocumentQuestionAnsweringParameters(BaseInferenceType):
2323
"""Additional inference parameters for Document Question Answering"""
2424

25-
doc_stride: int | None = None
25+
doc_stride: Optional[int] = None
2626
"""If the words in the document are too long to fit with the question for the model, it will
2727
be split in several chunks with some overlap. This argument controls the size of that
2828
overlap.
2929
"""
30-
handle_impossible_answer: bool | None = None
30+
handle_impossible_answer: Optional[bool] = None
3131
"""Whether to accept impossible as an answer"""
32-
lang: str | None = None
32+
lang: Optional[str] = None
3333
"""Language to use while running OCR. Defaults to english."""
34-
max_answer_len: int | None = None
34+
max_answer_len: Optional[int] = None
3535
"""The maximum length of predicted answers (e.g., only answers with a shorter length are
3636
considered).
3737
"""
38-
max_question_len: int | None = None
38+
max_question_len: Optional[int] = None
3939
"""The maximum length of the question after tokenization. It will be truncated if needed."""
40-
max_seq_len: int | None = None
40+
max_seq_len: Optional[int] = None
4141
"""The maximum length of the total sentence (context + question) in tokens of each chunk
4242
passed to the model. The context will be split in several chunks (using doc_stride as
4343
overlap) if needed.
4444
"""
45-
top_k: int | None = None
45+
top_k: Optional[int] = None
4646
"""The number of answers to return (will be chosen by order of likelihood). Can return less
4747
than top_k answers if there are not enough options available within the context.
4848
"""
49-
word_boxes: list[list[float] | str] | None = None
49+
word_boxes: Optional[list[Union[list[float], str]]] = None
5050
"""A list of words and bounding boxes (normalized 0->1000). If provided, the inference will
5151
skip the OCR step and use the provided bounding boxes instead.
5252
"""
@@ -58,7 +58,7 @@ class DocumentQuestionAnsweringInput(BaseInferenceType):
5858

5959
inputs: DocumentQuestionAnsweringInputData
6060
"""One (document, question) pair to answer"""
61-
parameters: DocumentQuestionAnsweringParameters | None = None
61+
parameters: Optional[DocumentQuestionAnsweringParameters] = None
6262
"""Additional inference parameters for Document Question Answering"""
6363

6464

src/huggingface_hub/inference/_generated/types/feature_extraction.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# See:
44
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
55
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
6-
from typing import Literal, Optional
6+
from typing import Literal, Optional, Union
77

88
from .base import BaseInferenceType, dataclass_with_extra
99

@@ -19,10 +19,10 @@ class FeatureExtractionInput(BaseInferenceType):
1919
https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-tei-import.ts.
2020
"""
2121

22-
inputs: list[str] | str
22+
inputs: Union[list[str], str]
2323
"""The text or list of texts to embed."""
24-
normalize: bool | None = None
25-
prompt_name: str | None = None
24+
normalize: Optional[bool] = None
25+
prompt_name: Optional[str] = None
2626
"""The name of the prompt that should be used by for encoding. If not set, no prompt
2727
will be applied.
2828
Must be a key in the `sentence-transformers` configuration `prompts` dictionary.
@@ -32,5 +32,5 @@ class FeatureExtractionInput(BaseInferenceType):
3232
"query: What is the capital of France?" because the prompt text will be prepended before
3333
any text to encode.
3434
"""
35-
truncate: bool | None = None
35+
truncate: Optional[bool] = None
3636
truncation_direction: Optional["FeatureExtractionInputTruncationDirection"] = None

src/huggingface_hub/inference/_generated/types/fill_mask.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# See:
44
# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts
55
# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.
6-
from typing import Any
6+
from typing import Any, Optional
77

88
from .base import BaseInferenceType, dataclass_with_extra
99

@@ -12,13 +12,13 @@
1212
class FillMaskParameters(BaseInferenceType):
1313
"""Additional inference parameters for Fill Mask"""
1414

15-
targets: list[str] | None = None
15+
targets: Optional[list[str]] = None
1616
"""When passed, the model will limit the scores to the passed targets instead of looking up
1717
in the whole vocabulary. If the provided targets are not in the model vocab, they will be
1818
tokenized and the first resulting token will be used (with a warning, and that might be
1919
slower).
2020
"""
21-
top_k: int | None = None
21+
top_k: Optional[int] = None
2222
"""When passed, overrides the number of predictions to return."""
2323

2424

@@ -28,7 +28,7 @@ class FillMaskInput(BaseInferenceType):
2828

2929
inputs: str
3030
"""The text with masked tokens"""
31-
parameters: FillMaskParameters | None = None
31+
parameters: Optional[FillMaskParameters] = None
3232
"""Additional inference parameters for Fill Mask"""
3333

3434

@@ -43,5 +43,5 @@ class FillMaskOutputElement(BaseInferenceType):
4343
token: int
4444
"""The predicted token id (to replace the masked one)."""
4545
token_str: Any
46-
fill_mask_output_token_str: str | None = None
46+
fill_mask_output_token_str: Optional[str] = None
4747
"""The predicted token (to replace the masked one)."""

src/huggingface_hub/inference/_generated/types/image_classification.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ImageClassificationParameters(BaseInferenceType):
1717

1818
function_to_apply: Optional["ImageClassificationOutputTransform"] = None
1919
"""The function to apply to the model outputs in order to retrieve the scores."""
20-
top_k: int | None = None
20+
top_k: Optional[int] = None
2121
"""When specified, limits the output to the top K most probable classes."""
2222

2323

@@ -29,7 +29,7 @@ class ImageClassificationInput(BaseInferenceType):
2929
"""The input image data as a base64-encoded string. If no `parameters` are provided, you can
3030
also provide the image data as a raw bytes payload.
3131
"""
32-
parameters: ImageClassificationParameters | None = None
32+
parameters: Optional[ImageClassificationParameters] = None
3333
"""Additional inference parameters for Image Classification"""
3434

3535

src/huggingface_hub/inference/_generated/types/image_segmentation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
class ImageSegmentationParameters(BaseInferenceType):
1616
"""Additional inference parameters for Image Segmentation"""
1717

18-
mask_threshold: float | None = None
18+
mask_threshold: Optional[float] = None
1919
"""Threshold to use when turning the predicted masks into binary values."""
20-
overlap_mask_area_threshold: float | None = None
20+
overlap_mask_area_threshold: Optional[float] = None
2121
"""Mask overlap threshold to eliminate small, disconnected segments."""
2222
subtask: Optional["ImageSegmentationSubtask"] = None
2323
"""Segmentation task to be performed, depending on model capabilities."""
24-
threshold: float | None = None
24+
threshold: Optional[float] = None
2525
"""Probability threshold to filter out predicted masks."""
2626

2727

@@ -33,7 +33,7 @@ class ImageSegmentationInput(BaseInferenceType):
3333
"""The input image data as a base64-encoded string. If no `parameters` are provided, you can
3434
also provide the image data as a raw bytes payload.
3535
"""
36-
parameters: ImageSegmentationParameters | None = None
36+
parameters: Optional[ImageSegmentationParameters] = None
3737
"""Additional inference parameters for Image Segmentation"""
3838

3939

@@ -47,5 +47,5 @@ class ImageSegmentationOutputElement(BaseInferenceType):
4747
"""The label of the predicted segment."""
4848
mask: str
4949
"""The corresponding mask as a black-and-white image (base64-encoded)."""
50-
score: float | None = None
50+
score: Optional[float] = None
5151
"""The score or confidence degree the model has."""

0 commit comments

Comments
 (0)