Fix sacremoses sof dependency for Transformers XL (#18321)

* Fix sacremoses sof dependency for Transofmers XL

* Add function to the submodule init
This commit is contained in:
Sylvain Gugger 2022-07-27 09:37:02 -04:00 committed by GitHub
parent 5c5676cdf9
commit 0077360d67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 3 deletions

View File

@ -27,10 +27,19 @@ from typing import List, Optional, Tuple
import numpy as np
import sacremoses as sm
from ...tokenization_utils import PreTrainedTokenizer
from ...utils import cached_path, is_torch_available, logging, torch_only_method
from ...utils import (
cached_path,
is_sacremoses_available,
is_torch_available,
logging,
requires_backends,
torch_only_method,
)
if is_sacremoses_available():
import sacremoses as sm
if is_torch_available():
@ -187,6 +196,7 @@ class TransfoXLTokenizer(PreTrainedTokenizer):
language=language,
**kwargs,
)
requires_backends(self, "sacremoses")
if never_split is None:
never_split = self.all_special_tokens

View File

@ -109,6 +109,7 @@ from .import_utils import (
is_pytesseract_available,
is_pytorch_quantization_available,
is_rjieba_available,
is_sacremoses_available,
is_sagemaker_dp_enabled,
is_sagemaker_mp_enabled,
is_scatter_available,

View File

@ -444,6 +444,10 @@ def is_py3nvml_available():
return importlib.util.find_spec("py3nvml") is not None
def is_sacremoses_available():
return importlib.util.find_spec("sacremoses") is not None
def is_apex_available():
return importlib.util.find_spec("apex") is not None
@ -799,6 +803,13 @@ PHONEMIZER_IMPORT_ERROR = """
"""
# docstyle-ignore
SACREMOSES_IMPORT_ERROR = """
{0} requires the sacremoses library but it was not found in your environment. You can install it with pip:
`pip install sacremoses`
"""
# docstyle-ignore
SCIPY_IMPORT_ERROR = """
{0} requires the scipy library but it was not found in your environment. You can install it with pip:
@ -856,6 +867,7 @@ BACKENDS_MAPPING = OrderedDict(
("protobuf", (is_protobuf_available, PROTOBUF_IMPORT_ERROR)),
("pyctcdecode", (is_pyctcdecode_available, PYCTCDECODE_IMPORT_ERROR)),
("pytesseract", (is_pytesseract_available, PYTESSERACT_IMPORT_ERROR)),
("sacremoses", (is_sacremoses_available, SACREMOSES_IMPORT_ERROR)),
("scatter", (is_scatter_available, SCATTER_IMPORT_ERROR)),
("pytorch_quantization", (is_pytorch_quantization_available, PYTORCH_QUANTIZATION_IMPORT_ERROR)),
("sentencepiece", (is_sentencepiece_available, SENTENCEPIECE_IMPORT_ERROR)),