-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathinstall.py
110 lines (92 loc) · 3.09 KB
/
install.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import sys
import pkg_resources
import launch
from tipo_installer import logger, KGEN_VERSION
def get_installed_version(package: str):
try:
return pkg_resources.get_distribution(package).version
except Exception:
return None
llama_cpp_python_wheel = (
"llama-cpp-python --prefer-binary "
"--extra-index-url=https://jllllll.github.io/llama-cpp-python-cuBLAS-wheels/{}/{}"
)
llama_cpp_python_wheel_official = (
"https://github.com/abetlen/llama-cpp-python/releases/download/"
"v{version_arch}/llama_cpp_python-{version}-{python}-{python}-{platform}.whl"
)
version_arch = {
"0.3.4": [
("cp39", "cp310", "cp311", "cp312"),
("cu121", "cu122", "cu123", "cu124", "metal"),
("linux_x86_64", "win_amd64", "maxosx_11_0_arm64"),
],
"0.3.2": [
("cp38", "cp39", "cp310", "cp311", "cp312"),
("cpu", "metal"),
("linux_x86_64", "win_amd64", "maxosx_11_0_arm64"),
],
}
def install_llama_cpp_legacy(cuda_version, has_cuda):
if cuda_version >= "122":
cuda_version = "122"
package = llama_cpp_python_wheel.format(
"AVX2", f"cu{cuda_version}" if has_cuda else "cpu"
)
launch.run_pip(
f"install {package}",
"LLaMA-CPP-Python for TIPO",
)
def install_llama_cpp():
if get_installed_version("llama_cpp_python") is not None:
return
logger.info("Attempting to install LLaMA-CPP-Python")
import torch
has_cuda = torch.cuda.is_available()
cuda_version = torch.version.cuda.replace(".", "")
arch = "cu" + cuda_version if has_cuda else "cpu"
if has_cuda and arch >= "cu124":
arch = "cu124"
platform = sys.platform
py_ver = f"cp{sys.version_info.major}{sys.version_info.minor}"
if platform == "darwin":
platform = "maxosx_11_0_arm64"
elif platform == "win32":
platform = "win_amd64"
elif platform == "linux":
platform = "linux_x86_64"
for version, (py_vers, archs, platforms) in version_arch.items():
if py_ver in py_vers and arch in archs and platform in platforms:
break
else:
logger.warning("Official wheel not found, using legacy builds")
install_llama_cpp_legacy(cuda_version, has_cuda)
return
wheel = llama_cpp_python_wheel_official.format(
version=version,
python=py_ver,
platform=platform,
version_arch=f"{version}-{arch}",
)
try:
launch.run_pip(
f"install {wheel}",
"LLaMA-CPP-Python for TIPO",
)
logger.info("Installation of llama-cpp-python succeeded")
except Exception:
logger.warning(
"Installation of llama-cpp-python failed, "
"Please try to install it manually or use non-gguf models"
)
def install_tipo_kgen():
version = get_installed_version("tipo-kgen")
if version is not None and version >= KGEN_VERSION:
return
logger.info("Attempting to install tipo_kgen")
launch.run_pip(
f'install -U "tipo-kgen>={KGEN_VERSION}"',
"tipo-kgen for TIPO",
)
install_llama_cpp()
install_tipo_kgen()