Unverified Commit fed8a9b1 authored by Cyrus Leung's avatar Cyrus Leung Committed by GitHub
Browse files

[Misc] Retry HF processing if "Already borrowed" error occurs (#25535)


Signed-off-by: default avatarDarkLight1337 <tlleungac@connect.ust.hk>
parent 190c45a6
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import time
from collections.abc import Mapping from collections.abc import Mapping
from dataclasses import dataclass from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Union from typing import TYPE_CHECKING, Any, Union
...@@ -139,6 +140,9 @@ class InputProcessingContext(InputContext): ...@@ -139,6 +140,9 @@ class InputProcessingContext(InputContext):
hf_processor: ProcessorMixin, hf_processor: ProcessorMixin,
data: Mapping[str, object], data: Mapping[str, object],
kwargs: Mapping[str, object] = {}, kwargs: Mapping[str, object] = {},
*,
num_tries: int = 1,
max_tries: int = 5,
) -> Union[BatchFeature, JSONTree]: ) -> Union[BatchFeature, JSONTree]:
""" """
Call `hf_processor` on the prompt `data` Call `hf_processor` on the prompt `data`
...@@ -180,6 +184,22 @@ class InputProcessingContext(InputContext): ...@@ -180,6 +184,22 @@ class InputProcessingContext(InputContext):
return cast_output return cast_output
except Exception as exc: except Exception as exc:
# See https://github.com/huggingface/tokenizers/issues/537
if (isinstance(exc, RuntimeError) and exc
and exc.args[0] == "Already borrowed"
and num_tries < max_tries):
logger.warning(
"Failed to acquire tokenizer in current thread. "
"Retrying (%d/%d)...", num_tries, max_tries)
time.sleep(0.5)
return self.call_hf_processor(
hf_processor,
data,
kwargs,
num_tries=num_tries + 1,
max_tries=max_tries,
)
msg = (f"Failed to apply {type(hf_processor).__name__} " msg = (f"Failed to apply {type(hf_processor).__name__} "
f"on data={data} with kwargs={allowed_kwargs}") f"on data={data} with kwargs={allowed_kwargs}")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment