Skip to content

Commit 9bee9ff

Browse files
Un-deprecate timeout arg in pipelines (#34382)
* Un-deprecate timeout * Put "timeout" on the allowed list * make fixup
1 parent e4449bb commit 9bee9ff

File tree

7 files changed

+27
-23
lines changed

7 files changed

+27
-23
lines changed

src/transformers/pipelines/depth_estimation.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import warnings
21
from typing import List, Union
32

43
from ..utils import (
@@ -72,6 +71,9 @@ def __call__(self, inputs: Union[str, List[str], "Image.Image", List["Image.Imag
7271
A dictionary of argument names to parameter values, to control pipeline behaviour.
7372
The only parameter available right now is `timeout`, which is the length of time, in seconds,
7473
that the pipeline should wait before giving up on trying to download an image.
74+
timeout (`float`, *optional*, defaults to None):
75+
The maximum time in seconds to wait for fetching images from the web. If None, no timeout is set and
76+
the call may block forever.
7577
7678
Return:
7779
A dictionary or a list of dictionaries containing result. If the input is a single image, will return a
@@ -93,9 +95,6 @@ def __call__(self, inputs: Union[str, List[str], "Image.Image", List["Image.Imag
9395
def _sanitize_parameters(self, timeout=None, parameters=None, **kwargs):
9496
preprocess_params = {}
9597
if timeout is not None:
96-
warnings.warn(
97-
"The `timeout` argument is deprecated and will be removed in version 5 of Transformers", FutureWarning
98-
)
9998
preprocess_params["timeout"] = timeout
10099
if isinstance(parameters, dict) and "timeout" in parameters:
101100
preprocess_params["timeout"] = parameters["timeout"]

src/transformers/pipelines/image_classification.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
import warnings
1514
from typing import List, Union
1615

1716
import numpy as np
@@ -113,9 +112,6 @@ def __init__(self, *args, **kwargs):
113112
def _sanitize_parameters(self, top_k=None, function_to_apply=None, timeout=None):
114113
preprocess_params = {}
115114
if timeout is not None:
116-
warnings.warn(
117-
"The `timeout` argument is deprecated and will be removed in version 5 of Transformers", FutureWarning
118-
)
119115
preprocess_params["timeout"] = timeout
120116
postprocess_params = {}
121117
if top_k is not None:
@@ -159,6 +155,9 @@ def __call__(self, inputs: Union[str, List[str], "Image.Image", List["Image.Imag
159155
top_k (`int`, *optional*, defaults to 5):
160156
The number of top labels that will be returned by the pipeline. If the provided number is higher than
161157
the number of labels available in the model configuration, it will default to the number of labels.
158+
timeout (`float`, *optional*, defaults to None):
159+
The maximum time in seconds to wait for fetching images from the web. If None, no timeout is set and
160+
the call may block forever.
162161
163162
Return:
164163
A dictionary or a list of dictionaries containing result. If the input is a single image, will return a

src/transformers/pipelines/image_segmentation.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import warnings
21
from typing import Any, Dict, List, Union
32

43
import numpy as np
@@ -91,9 +90,6 @@ def _sanitize_parameters(self, **kwargs):
9190
if "overlap_mask_area_threshold" in kwargs:
9291
postprocess_kwargs["overlap_mask_area_threshold"] = kwargs["overlap_mask_area_threshold"]
9392
if "timeout" in kwargs:
94-
warnings.warn(
95-
"The `timeout` argument is deprecated and will be removed in version 5 of Transformers", FutureWarning
96-
)
9793
preprocess_kwargs["timeout"] = kwargs["timeout"]
9894

9995
return preprocess_kwargs, {}, postprocess_kwargs
@@ -122,6 +118,9 @@ def __call__(self, inputs=None, **kwargs) -> Union[Predictions, List[Prediction]
122118
Threshold to use when turning the predicted masks into binary values.
123119
overlap_mask_area_threshold (`float`, *optional*, defaults to 0.5):
124120
Mask overlap threshold to eliminate small, disconnected segments.
121+
timeout (`float`, *optional*, defaults to None):
122+
The maximum time in seconds to wait for fetching images from the web. If None, no timeout is set and
123+
the call may block forever.
125124
126125
Return:
127126
A dictionary or a list of dictionaries containing the result. If the input is a single image, will return a

src/transformers/pipelines/image_to_text.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
import warnings
1716
from typing import List, Union
1817

1918
from ..utils import (
@@ -81,9 +80,6 @@ def _sanitize_parameters(self, max_new_tokens=None, generate_kwargs=None, prompt
8180
if prompt is not None:
8281
preprocess_params["prompt"] = prompt
8382
if timeout is not None:
84-
warnings.warn(
85-
"The `timeout` argument is deprecated and will be removed in version 5 of Transformers", FutureWarning
86-
)
8783
preprocess_params["timeout"] = timeout
8884

8985
if max_new_tokens is not None:
@@ -118,6 +114,10 @@ def __call__(self, inputs: Union[str, List[str], "Image.Image", List["Image.Imag
118114
generate_kwargs (`Dict`, *optional*):
119115
Pass it to send all of these arguments directly to `generate` allowing full control of this function.
120116
117+
timeout (`float`, *optional*, defaults to None):
118+
The maximum time in seconds to wait for fetching images from the web. If None, no timeout is set and
119+
the call may block forever.
120+
121121
Return:
122122
A list or a list of list of `dict`: Each result comes as a dictionary with the following key:
123123

src/transformers/pipelines/object_detection.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import warnings
21
from typing import Any, Dict, List, Union
32

43
from ..utils import add_end_docstrings, is_torch_available, is_vision_available, logging, requires_backends
@@ -64,9 +63,6 @@ def __init__(self, *args, **kwargs):
6463
def _sanitize_parameters(self, **kwargs):
6564
preprocess_params = {}
6665
if "timeout" in kwargs:
67-
warnings.warn(
68-
"The `timeout` argument is deprecated and will be removed in version 5 of Transformers", FutureWarning
69-
)
7066
preprocess_params["timeout"] = kwargs["timeout"]
7167
postprocess_kwargs = {}
7268
if "threshold" in kwargs:
@@ -89,6 +85,9 @@ def __call__(self, *args, **kwargs) -> Union[Predictions, List[Prediction]]:
8985
same format: all as HTTP(S) links, all as local paths, or all as PIL images.
9086
threshold (`float`, *optional*, defaults to 0.5):
9187
The probability necessary to make a prediction.
88+
timeout (`float`, *optional*, defaults to None):
89+
The maximum time in seconds to wait for fetching images from the web. If None, no timeout is set and
90+
the call may block forever.
9291
9392
Return:
9493
A list of dictionaries or a list of list of dictionaries containing the result. If the input is a single

src/transformers/pipelines/zero_shot_image_classification.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ def __call__(self, image: Union[str, List[str], "Image", List["Image"]] = None,
9494
replacing the placeholder with the candidate_labels. Pass "{}" if *candidate_labels* are
9595
already formatted.
9696
97+
timeout (`float`, *optional*, defaults to None):
98+
The maximum time in seconds to wait for fetching images from the web. If None, no timeout is set and
99+
the call may block forever.
100+
97101
Return:
98102
A list of dictionaries containing one entry per proposed label. Each dictionary contains the
99103
following keys:
@@ -113,9 +117,6 @@ def _sanitize_parameters(self, tokenizer_kwargs=None, **kwargs):
113117
if "candidate_labels" in kwargs:
114118
preprocess_params["candidate_labels"] = kwargs["candidate_labels"]
115119
if "timeout" in kwargs:
116-
warnings.warn(
117-
"The `timeout` argument is deprecated and will be removed in version 5 of Transformers", FutureWarning
118-
)
119120
preprocess_params["timeout"] = kwargs["timeout"]
120121
if "hypothesis_template" in kwargs:
121122
preprocess_params["hypothesis_template"] = kwargs["hypothesis_template"]

tests/test_pipeline_mixin.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,8 @@ def parse_args_from_docstring_by_indentation(docstring):
916916

917917

918918
def compare_pipeline_args_to_hub_spec(pipeline_class, hub_spec):
919+
ALLOWED_TRANSFORMERS_ONLY_ARGS = ["timeout"]
920+
919921
docstring = inspect.getdoc(pipeline_class.__call__).strip()
920922
docstring_args = set(parse_args_from_docstring_by_indentation(docstring))
921923
hub_args = set(get_arg_names_from_hub_spec(hub_spec))
@@ -933,6 +935,11 @@ def compare_pipeline_args_to_hub_spec(pipeline_class, hub_spec):
933935
hub_args.remove(js_generate_args[0])
934936
docstring_args.remove(docstring_generate_args[0])
935937

938+
# Special casing 2: We permit some transformers-only arguments that don't affect pipeline output
939+
for arg in ALLOWED_TRANSFORMERS_ONLY_ARGS:
940+
if arg in docstring_args and arg not in hub_args:
941+
docstring_args.remove(arg)
942+
936943
if hub_args != docstring_args:
937944
error = [f"{pipeline_class.__name__} differs from JS spec {hub_spec.__name__}"]
938945
matching_args = hub_args & docstring_args

0 commit comments

Comments
 (0)