Unverified Commit 0077360d authored by Sylvain Gugger's avatar Sylvain Gugger Committed by GitHub
Browse files

Fix sacremoses sof dependency for Transformers XL (#18321)

* Fix sacremoses sof dependency for Transofmers XL

* Add function to the submodule init
parent 5c5676cd
...@@ -27,10 +27,19 @@ from typing import List, Optional, Tuple ...@@ -27,10 +27,19 @@ from typing import List, Optional, Tuple
import numpy as np import numpy as np
import sacremoses as sm
from ...tokenization_utils import PreTrainedTokenizer 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(): if is_torch_available():
...@@ -187,6 +196,7 @@ class TransfoXLTokenizer(PreTrainedTokenizer): ...@@ -187,6 +196,7 @@ class TransfoXLTokenizer(PreTrainedTokenizer):
language=language, language=language,
**kwargs, **kwargs,
) )
requires_backends(self, "sacremoses")
if never_split is None: if never_split is None:
never_split = self.all_special_tokens never_split = self.all_special_tokens
......
...@@ -109,6 +109,7 @@ from .import_utils import ( ...@@ -109,6 +109,7 @@ from .import_utils import (
is_pytesseract_available, is_pytesseract_available,
is_pytorch_quantization_available, is_pytorch_quantization_available,
is_rjieba_available, is_rjieba_available,
is_sacremoses_available,
is_sagemaker_dp_enabled, is_sagemaker_dp_enabled,
is_sagemaker_mp_enabled, is_sagemaker_mp_enabled,
is_scatter_available, is_scatter_available,
......
...@@ -444,6 +444,10 @@ def is_py3nvml_available(): ...@@ -444,6 +444,10 @@ def is_py3nvml_available():
return importlib.util.find_spec("py3nvml") is not None 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(): def is_apex_available():
return importlib.util.find_spec("apex") is not None return importlib.util.find_spec("apex") is not None
...@@ -799,6 +803,13 @@ PHONEMIZER_IMPORT_ERROR = """ ...@@ -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 # docstyle-ignore
SCIPY_IMPORT_ERROR = """ SCIPY_IMPORT_ERROR = """
{0} requires the scipy library but it was not found in your environment. You can install it with pip: {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( ...@@ -856,6 +867,7 @@ BACKENDS_MAPPING = OrderedDict(
("protobuf", (is_protobuf_available, PROTOBUF_IMPORT_ERROR)), ("protobuf", (is_protobuf_available, PROTOBUF_IMPORT_ERROR)),
("pyctcdecode", (is_pyctcdecode_available, PYCTCDECODE_IMPORT_ERROR)), ("pyctcdecode", (is_pyctcdecode_available, PYCTCDECODE_IMPORT_ERROR)),
("pytesseract", (is_pytesseract_available, PYTESSERACT_IMPORT_ERROR)), ("pytesseract", (is_pytesseract_available, PYTESSERACT_IMPORT_ERROR)),
("sacremoses", (is_sacremoses_available, SACREMOSES_IMPORT_ERROR)),
("scatter", (is_scatter_available, SCATTER_IMPORT_ERROR)), ("scatter", (is_scatter_available, SCATTER_IMPORT_ERROR)),
("pytorch_quantization", (is_pytorch_quantization_available, PYTORCH_QUANTIZATION_IMPORT_ERROR)), ("pytorch_quantization", (is_pytorch_quantization_available, PYTORCH_QUANTIZATION_IMPORT_ERROR)),
("sentencepiece", (is_sentencepiece_available, SENTENCEPIECE_IMPORT_ERROR)), ("sentencepiece", (is_sentencepiece_available, SENTENCEPIECE_IMPORT_ERROR)),
......
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