-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix issues with optional dependencies (#204)
* fix issues with optional dependencies * format document * Tree: Format and comment
- Loading branch information
1 parent
75af974
commit 3aeddc5
Showing
9 changed files
with
104 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import platform | ||
from packaging import version | ||
from importlib.metadata import version as package_version | ||
from loguru import logger | ||
from common.optional_dependencies import dependencies | ||
|
||
|
||
def check_exllama_version(): | ||
"""Verifies the exllama version""" | ||
|
||
install_message = ( | ||
"Please update your environment by running an update script " | ||
"(update_scripts/" | ||
f"update_deps.{'bat' if platform.system() == 'Windows' else 'sh'})\n\n" | ||
"Or you can manually run a requirements update " | ||
"using the following command:\n\n" | ||
"For CUDA 12.1:\n" | ||
"pip install --upgrade .[cu121]\n\n" | ||
"For CUDA 11.8:\n" | ||
"pip install --upgrade .[cu118]\n\n" | ||
"For ROCm:\n" | ||
"pip install --upgrade .[amd]\n\n" | ||
) | ||
|
||
if not dependencies.exl2: | ||
raise SystemExit(("Exllamav2 is not installed.\n" + install_message)) | ||
|
||
required_version = version.parse("0.2.2") | ||
current_version = version.parse(package_version("exllamav2").split("+")[0]) | ||
|
||
unsupported_message = ( | ||
f"ERROR: TabbyAPI requires ExLlamaV2 {required_version} " | ||
f"or greater. Your current version is {current_version}.\n" + install_message | ||
) | ||
|
||
if current_version < required_version: | ||
raise SystemExit(unsupported_message) | ||
else: | ||
logger.info(f"ExllamaV2 version: {current_version}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""Construct a model of all optional dependencies""" | ||
|
||
import importlib.util | ||
from pydantic import BaseModel, computed_field | ||
|
||
|
||
# Declare the exported parts of this module | ||
__all__ = ["dependencies"] | ||
|
||
|
||
class DependenciesModel(BaseModel): | ||
"""Model of which optional dependencies are installed.""" | ||
|
||
torch: bool | ||
exllamav2: bool | ||
flash_attn: bool | ||
outlines: bool | ||
infinity_emb: bool | ||
sentence_transformers: bool | ||
|
||
@computed_field | ||
@property | ||
def extras(self) -> bool: | ||
return self.outlines and self.infinity_emb and self.sentence_transformers | ||
|
||
@computed_field | ||
@property | ||
def exl2(self) -> bool: | ||
return self.torch and self.exllamav2 and self.flash_attn | ||
|
||
|
||
def is_installed(package_name: str) -> bool: | ||
"""Utility function to check if a package is installed.""" | ||
|
||
spec = importlib.util.find_spec(package_name) | ||
return spec is not None | ||
|
||
|
||
def get_installed_deps() -> DependenciesModel: | ||
"""Check if optional dependencies are installed by looping over the fields.""" | ||
|
||
fields = DependenciesModel.model_fields | ||
|
||
installed_deps = {} | ||
|
||
for field_name in fields.keys(): | ||
installed_deps[field_name] = is_installed(field_name) | ||
|
||
return DependenciesModel(**installed_deps) | ||
|
||
|
||
dependencies = get_installed_deps() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters