Skip to content

Commit 17f3dca

Browse files
committed
Packaging: Add agnostic method to check version of packages
Some packages such as ExllamaV2 and V3 require specific versions for the latest features. Rather than creating repetitive functions, create an agnostic function to check the installed package and then report to the user to upgrade. This is also sent to requests for loading and unloading, so keep the error short. Signed-off-by: kingbri <8082010+kingbri1@users.noreply.github.com>
1 parent 084916c commit 17f3dca

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

backends/exllamav2/model.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from common.hardware import hardware_supports_flash_attn
4545
from common.health import HealthManager
4646
from common.multimodal import MultimodalEmbeddingWrapper
47+
from common.optional_dependencies import check_package_version
4748
from common.sampling import BaseSamplerRequest
4849
from common.templating import PromptTemplate, find_prompt_template
4950
from common.transformers_utils import HFModel
@@ -111,6 +112,9 @@ async def create(cls, model_directory: pathlib.Path, hf_model: HFModel, **kwargs
111112
# Create a new instance as a "fake self"
112113
self = cls()
113114

115+
# Make sure ExllamaV2 is up to date
116+
check_package_version("exllamav2", "0.3.0")
117+
114118
# Initialize config
115119
self.config = ExLlamaV2Config()
116120
self.model_dir = model_directory

backends/exllamav3/model.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from common.hardware import hardware_supports_flash_attn
3333
from common.health import HealthManager
3434
from common.multimodal import MultimodalEmbeddingWrapper
35+
from common.optional_dependencies import check_package_version
3536
from common.sampling import BaseSamplerRequest
3637
from common.templating import PromptTemplate, find_prompt_template
3738
from common.transformers_utils import HFModel
@@ -96,6 +97,9 @@ async def create(cls, model_directory: pathlib.Path, hf_model: HFModel, **kwargs
9697

9798
self = cls()
9899

100+
# Make sure ExllamaV3 is up to date
101+
check_package_version("exllamav3", "0.0.2")
102+
99103
logger.warning(
100104
"ExllamaV3 is currently in an alpha state. "
101105
"Please note that all config options may not work."

common/optional_dependencies.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"""Construct a model of all optional dependencies"""
22

33
import importlib.util
4+
from importlib.metadata import version as package_version
5+
from loguru import logger
6+
from packaging import version
47
from pydantic import BaseModel, computed_field
58

69

@@ -49,4 +52,26 @@ def get_installed_deps() -> DependenciesModel:
4952
return DependenciesModel(**installed_deps)
5053

5154

55+
def check_package_version(package_name: str, required_version_str: str):
56+
"""
57+
Fetches and verifies a given package version.
58+
59+
This assumes that the required package is installed.
60+
"""
61+
62+
required_version = version.parse(required_version_str)
63+
current_version = version.parse(package_version(package_name).split("+")[0])
64+
65+
unsupported_message = (
66+
f"ERROR: TabbyAPI requires ExLlamaV2 {required_version} "
67+
f"or greater. Your current version is {current_version}. "
68+
"Please update your dependencies."
69+
)
70+
71+
if current_version < required_version:
72+
raise RuntimeError(unsupported_message)
73+
else:
74+
logger.info(f"{package_name} version: {current_version}")
75+
76+
5277
dependencies = get_installed_deps()

0 commit comments

Comments
 (0)