Skip to content

Commit

Permalink
Fix is_ninja_available() (#23752)
Browse files Browse the repository at this point in the history
* Fix is_ninja_available()

search ninja using subprocess instead of importlib.

* Fix style

* Fix doc

* Fix style
  • Loading branch information
niltok authored May 25, 2023
1 parent 3416bba commit f04f549
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/transformers/utils/import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import json
import os
import shutil
import subprocess
import sys
import warnings
from collections import OrderedDict
Expand Down Expand Up @@ -94,7 +95,6 @@ def _is_package_available(pkg_name: str, return_version: bool = False) -> Union[
_keras_nlp_available = _is_package_available("keras_nlp")
_librosa_available = _is_package_available("librosa")
_natten_available = _is_package_available("natten")
_ninja_available = _is_package_available("ninja")
_onnx_available = _is_package_available("onnx")
_openai_available = _is_package_available("openai")
_optimum_available = _is_package_available("optimum")
Expand Down Expand Up @@ -449,7 +449,16 @@ def is_apex_available():


def is_ninja_available():
return _ninja_available
r"""
Code comes from *torch.utils.cpp_extension.is_ninja_available()*. Returns `True` if the
[ninja](https://ninja-build.org/) build system is available on the system, `False` otherwise.
"""
try:
subprocess.check_output("ninja --version".split())
except Exception:
return False
else:
return True


def is_ipex_available():
Expand Down

0 comments on commit f04f549

Please sign in to comment.