add option to disable version check

Former-commit-id: fd769cb2de696aee3c5e882237e16eace6a9d675
This commit is contained in:
hiyouga
2024-02-10 22:31:23 +08:00
parent ea2eef508a
commit a52372df01
4 changed files with 47 additions and 26 deletions

View File

@@ -2,11 +2,11 @@ import importlib.metadata
import importlib.util
def is_package_available(name: str) -> bool:
def _is_package_available(name: str) -> bool:
return importlib.util.find_spec(name) is not None
def get_package_version(name: str) -> str:
def _get_package_version(name: str) -> str:
try:
return importlib.metadata.version(name)
except Exception:
@@ -14,36 +14,40 @@ def get_package_version(name: str) -> str:
def is_fastapi_availble():
return is_package_available("fastapi")
return _is_package_available("fastapi")
def is_flash_attn2_available():
return is_package_available("flash_attn") and get_package_version("flash_attn").startswith("2")
return _is_package_available("flash_attn") and _get_package_version("flash_attn").startswith("2")
def is_jieba_available():
return is_package_available("jieba")
return _is_package_available("jieba")
def is_matplotlib_available():
return is_package_available("matplotlib")
return _is_package_available("matplotlib")
def is_nltk_available():
return is_package_available("nltk")
return _is_package_available("nltk")
def is_requests_available():
return is_package_available("requests")
return _is_package_available("requests")
def is_rouge_available():
return is_package_available("rouge_chinese")
return _is_package_available("rouge_chinese")
def is_starlette_available():
return is_package_available("sse_starlette")
return _is_package_available("sse_starlette")
def is_unsloth_available():
return _is_package_available("unsloth")
def is_uvicorn_available():
return is_package_available("uvicorn")
return _is_package_available("uvicorn")