mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2025-12-19 23:25:02 +08:00
[Misc] Retry HF processing if "Already borrowed" error occurs (#25535)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
parent
190c45a6af
commit
fed8a9b107
@ -1,5 +1,6 @@
|
|||||||
# 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):
|
|||||||
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):
|
|||||||
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}")
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user