Un-deprecate timeout arg in pipelines (#34382)
* Un-deprecate timeout * Put "timeout" on the allowed list * make fixup
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
import warnings
|
|
||||||
from typing import List, Union
|
from typing import List, Union
|
||||||
|
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
@@ -72,6 +71,9 @@ class DepthEstimationPipeline(Pipeline):
|
|||||||
A dictionary of argument names to parameter values, to control pipeline behaviour.
|
A dictionary of argument names to parameter values, to control pipeline behaviour.
|
||||||
The only parameter available right now is `timeout`, which is the length of time, in seconds,
|
The only parameter available right now is `timeout`, which is the length of time, in seconds,
|
||||||
that the pipeline should wait before giving up on trying to download an image.
|
that the pipeline should wait before giving up on trying to download an image.
|
||||||
|
timeout (`float`, *optional*, defaults to None):
|
||||||
|
The maximum time in seconds to wait for fetching images from the web. If None, no timeout is set and
|
||||||
|
the call may block forever.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
A dictionary or a list of dictionaries containing result. If the input is a single image, will return a
|
A dictionary or a list of dictionaries containing result. If the input is a single image, will return a
|
||||||
@@ -93,9 +95,6 @@ class DepthEstimationPipeline(Pipeline):
|
|||||||
def _sanitize_parameters(self, timeout=None, parameters=None, **kwargs):
|
def _sanitize_parameters(self, timeout=None, parameters=None, **kwargs):
|
||||||
preprocess_params = {}
|
preprocess_params = {}
|
||||||
if timeout is not None:
|
if timeout is not None:
|
||||||
warnings.warn(
|
|
||||||
"The `timeout` argument is deprecated and will be removed in version 5 of Transformers", FutureWarning
|
|
||||||
)
|
|
||||||
preprocess_params["timeout"] = timeout
|
preprocess_params["timeout"] = timeout
|
||||||
if isinstance(parameters, dict) and "timeout" in parameters:
|
if isinstance(parameters, dict) and "timeout" in parameters:
|
||||||
preprocess_params["timeout"] = parameters["timeout"]
|
preprocess_params["timeout"] = parameters["timeout"]
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
import warnings
|
|
||||||
from typing import List, Union
|
from typing import List, Union
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@@ -113,9 +112,6 @@ class ImageClassificationPipeline(Pipeline):
|
|||||||
def _sanitize_parameters(self, top_k=None, function_to_apply=None, timeout=None):
|
def _sanitize_parameters(self, top_k=None, function_to_apply=None, timeout=None):
|
||||||
preprocess_params = {}
|
preprocess_params = {}
|
||||||
if timeout is not None:
|
if timeout is not None:
|
||||||
warnings.warn(
|
|
||||||
"The `timeout` argument is deprecated and will be removed in version 5 of Transformers", FutureWarning
|
|
||||||
)
|
|
||||||
preprocess_params["timeout"] = timeout
|
preprocess_params["timeout"] = timeout
|
||||||
postprocess_params = {}
|
postprocess_params = {}
|
||||||
if top_k is not None:
|
if top_k is not None:
|
||||||
@@ -159,6 +155,9 @@ class ImageClassificationPipeline(Pipeline):
|
|||||||
top_k (`int`, *optional*, defaults to 5):
|
top_k (`int`, *optional*, defaults to 5):
|
||||||
The number of top labels that will be returned by the pipeline. If the provided number is higher than
|
The number of top labels that will be returned by the pipeline. If the provided number is higher than
|
||||||
the number of labels available in the model configuration, it will default to the number of labels.
|
the number of labels available in the model configuration, it will default to the number of labels.
|
||||||
|
timeout (`float`, *optional*, defaults to None):
|
||||||
|
The maximum time in seconds to wait for fetching images from the web. If None, no timeout is set and
|
||||||
|
the call may block forever.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
A dictionary or a list of dictionaries containing result. If the input is a single image, will return a
|
A dictionary or a list of dictionaries containing result. If the input is a single image, will return a
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import warnings
|
|
||||||
from typing import Any, Dict, List, Union
|
from typing import Any, Dict, List, Union
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@@ -91,9 +90,6 @@ class ImageSegmentationPipeline(Pipeline):
|
|||||||
if "overlap_mask_area_threshold" in kwargs:
|
if "overlap_mask_area_threshold" in kwargs:
|
||||||
postprocess_kwargs["overlap_mask_area_threshold"] = kwargs["overlap_mask_area_threshold"]
|
postprocess_kwargs["overlap_mask_area_threshold"] = kwargs["overlap_mask_area_threshold"]
|
||||||
if "timeout" in kwargs:
|
if "timeout" in kwargs:
|
||||||
warnings.warn(
|
|
||||||
"The `timeout` argument is deprecated and will be removed in version 5 of Transformers", FutureWarning
|
|
||||||
)
|
|
||||||
preprocess_kwargs["timeout"] = kwargs["timeout"]
|
preprocess_kwargs["timeout"] = kwargs["timeout"]
|
||||||
|
|
||||||
return preprocess_kwargs, {}, postprocess_kwargs
|
return preprocess_kwargs, {}, postprocess_kwargs
|
||||||
@@ -122,6 +118,9 @@ class ImageSegmentationPipeline(Pipeline):
|
|||||||
Threshold to use when turning the predicted masks into binary values.
|
Threshold to use when turning the predicted masks into binary values.
|
||||||
overlap_mask_area_threshold (`float`, *optional*, defaults to 0.5):
|
overlap_mask_area_threshold (`float`, *optional*, defaults to 0.5):
|
||||||
Mask overlap threshold to eliminate small, disconnected segments.
|
Mask overlap threshold to eliminate small, disconnected segments.
|
||||||
|
timeout (`float`, *optional*, defaults to None):
|
||||||
|
The maximum time in seconds to wait for fetching images from the web. If None, no timeout is set and
|
||||||
|
the call may block forever.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
A dictionary or a list of dictionaries containing the result. If the input is a single image, will return a
|
A dictionary or a list of dictionaries containing the result. If the input is a single image, will return a
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import warnings
|
|
||||||
from typing import List, Union
|
from typing import List, Union
|
||||||
|
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
@@ -81,9 +80,6 @@ class ImageToTextPipeline(Pipeline):
|
|||||||
if prompt is not None:
|
if prompt is not None:
|
||||||
preprocess_params["prompt"] = prompt
|
preprocess_params["prompt"] = prompt
|
||||||
if timeout is not None:
|
if timeout is not None:
|
||||||
warnings.warn(
|
|
||||||
"The `timeout` argument is deprecated and will be removed in version 5 of Transformers", FutureWarning
|
|
||||||
)
|
|
||||||
preprocess_params["timeout"] = timeout
|
preprocess_params["timeout"] = timeout
|
||||||
|
|
||||||
if max_new_tokens is not None:
|
if max_new_tokens is not None:
|
||||||
@@ -118,6 +114,10 @@ class ImageToTextPipeline(Pipeline):
|
|||||||
generate_kwargs (`Dict`, *optional*):
|
generate_kwargs (`Dict`, *optional*):
|
||||||
Pass it to send all of these arguments directly to `generate` allowing full control of this function.
|
Pass it to send all of these arguments directly to `generate` allowing full control of this function.
|
||||||
|
|
||||||
|
timeout (`float`, *optional*, defaults to None):
|
||||||
|
The maximum time in seconds to wait for fetching images from the web. If None, no timeout is set and
|
||||||
|
the call may block forever.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
A list or a list of list of `dict`: Each result comes as a dictionary with the following key:
|
A list or a list of list of `dict`: Each result comes as a dictionary with the following key:
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import warnings
|
|
||||||
from typing import Any, Dict, List, Union
|
from typing import Any, Dict, List, Union
|
||||||
|
|
||||||
from ..utils import add_end_docstrings, is_torch_available, is_vision_available, logging, requires_backends
|
from ..utils import add_end_docstrings, is_torch_available, is_vision_available, logging, requires_backends
|
||||||
@@ -64,9 +63,6 @@ class ObjectDetectionPipeline(Pipeline):
|
|||||||
def _sanitize_parameters(self, **kwargs):
|
def _sanitize_parameters(self, **kwargs):
|
||||||
preprocess_params = {}
|
preprocess_params = {}
|
||||||
if "timeout" in kwargs:
|
if "timeout" in kwargs:
|
||||||
warnings.warn(
|
|
||||||
"The `timeout` argument is deprecated and will be removed in version 5 of Transformers", FutureWarning
|
|
||||||
)
|
|
||||||
preprocess_params["timeout"] = kwargs["timeout"]
|
preprocess_params["timeout"] = kwargs["timeout"]
|
||||||
postprocess_kwargs = {}
|
postprocess_kwargs = {}
|
||||||
if "threshold" in kwargs:
|
if "threshold" in kwargs:
|
||||||
@@ -89,6 +85,9 @@ class ObjectDetectionPipeline(Pipeline):
|
|||||||
same format: all as HTTP(S) links, all as local paths, or all as PIL images.
|
same format: all as HTTP(S) links, all as local paths, or all as PIL images.
|
||||||
threshold (`float`, *optional*, defaults to 0.5):
|
threshold (`float`, *optional*, defaults to 0.5):
|
||||||
The probability necessary to make a prediction.
|
The probability necessary to make a prediction.
|
||||||
|
timeout (`float`, *optional*, defaults to None):
|
||||||
|
The maximum time in seconds to wait for fetching images from the web. If None, no timeout is set and
|
||||||
|
the call may block forever.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
A list of dictionaries or a list of list of dictionaries containing the result. If the input is a single
|
A list of dictionaries or a list of list of dictionaries containing the result. If the input is a single
|
||||||
|
|||||||
@@ -94,6 +94,10 @@ class ZeroShotImageClassificationPipeline(Pipeline):
|
|||||||
replacing the placeholder with the candidate_labels. Pass "{}" if *candidate_labels* are
|
replacing the placeholder with the candidate_labels. Pass "{}" if *candidate_labels* are
|
||||||
already formatted.
|
already formatted.
|
||||||
|
|
||||||
|
timeout (`float`, *optional*, defaults to None):
|
||||||
|
The maximum time in seconds to wait for fetching images from the web. If None, no timeout is set and
|
||||||
|
the call may block forever.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
A list of dictionaries containing one entry per proposed label. Each dictionary contains the
|
A list of dictionaries containing one entry per proposed label. Each dictionary contains the
|
||||||
following keys:
|
following keys:
|
||||||
@@ -113,9 +117,6 @@ class ZeroShotImageClassificationPipeline(Pipeline):
|
|||||||
if "candidate_labels" in kwargs:
|
if "candidate_labels" in kwargs:
|
||||||
preprocess_params["candidate_labels"] = kwargs["candidate_labels"]
|
preprocess_params["candidate_labels"] = kwargs["candidate_labels"]
|
||||||
if "timeout" in kwargs:
|
if "timeout" in kwargs:
|
||||||
warnings.warn(
|
|
||||||
"The `timeout` argument is deprecated and will be removed in version 5 of Transformers", FutureWarning
|
|
||||||
)
|
|
||||||
preprocess_params["timeout"] = kwargs["timeout"]
|
preprocess_params["timeout"] = kwargs["timeout"]
|
||||||
if "hypothesis_template" in kwargs:
|
if "hypothesis_template" in kwargs:
|
||||||
preprocess_params["hypothesis_template"] = kwargs["hypothesis_template"]
|
preprocess_params["hypothesis_template"] = kwargs["hypothesis_template"]
|
||||||
|
|||||||
@@ -916,6 +916,8 @@ def parse_args_from_docstring_by_indentation(docstring):
|
|||||||
|
|
||||||
|
|
||||||
def compare_pipeline_args_to_hub_spec(pipeline_class, hub_spec):
|
def compare_pipeline_args_to_hub_spec(pipeline_class, hub_spec):
|
||||||
|
ALLOWED_TRANSFORMERS_ONLY_ARGS = ["timeout"]
|
||||||
|
|
||||||
docstring = inspect.getdoc(pipeline_class.__call__).strip()
|
docstring = inspect.getdoc(pipeline_class.__call__).strip()
|
||||||
docstring_args = set(parse_args_from_docstring_by_indentation(docstring))
|
docstring_args = set(parse_args_from_docstring_by_indentation(docstring))
|
||||||
hub_args = set(get_arg_names_from_hub_spec(hub_spec))
|
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):
|
|||||||
hub_args.remove(js_generate_args[0])
|
hub_args.remove(js_generate_args[0])
|
||||||
docstring_args.remove(docstring_generate_args[0])
|
docstring_args.remove(docstring_generate_args[0])
|
||||||
|
|
||||||
|
# Special casing 2: We permit some transformers-only arguments that don't affect pipeline output
|
||||||
|
for arg in ALLOWED_TRANSFORMERS_ONLY_ARGS:
|
||||||
|
if arg in docstring_args and arg not in hub_args:
|
||||||
|
docstring_args.remove(arg)
|
||||||
|
|
||||||
if hub_args != docstring_args:
|
if hub_args != docstring_args:
|
||||||
error = [f"{pipeline_class.__name__} differs from JS spec {hub_spec.__name__}"]
|
error = [f"{pipeline_class.__name__} differs from JS spec {hub_spec.__name__}"]
|
||||||
matching_args = hub_args & docstring_args
|
matching_args = hub_args & docstring_args
|
||||||
|
|||||||
Reference in New Issue
Block a user