Skip to content

Commit 2e7b6b0

Browse files
authored
Create alternative requirements.txt with AMD and Metal wheels (#4052)
1 parent 9de2dfa commit 2e7b6b0

13 files changed

+336
-66
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ pip install -r requirements.txt
108108
1) Replace the last command above with
109109

110110
```
111-
pip install -r requirements_nocuda.txt
111+
pip install -r requirements_nowheels.txt
112112
```
113113

114114
2) Manually install llama-cpp-python using the appropriate command for your hardware: [Installation from PyPI](https://github.com/abetlen/llama-cpp-python#installation-from-pypi).
115-
115+
116116
3) Do the same for CTransformers: [Installation](https://github.com/marella/ctransformers#installation).
117117

118118
4) AMD: Manually install AutoGPTQ: [Installation](https://github.com/PanQiWei/AutoGPTQ#installation).

modules/llamacpp_hf.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
from modules import RoPE, shared
1111
from modules.logging_colors import logger
1212

13-
import llama_cpp
14-
15-
if torch.cuda.is_available() and not torch.version.hip:
16-
try:
17-
import llama_cpp_cuda
18-
except:
19-
llama_cpp_cuda = None
20-
else:
13+
try:
14+
import llama_cpp
15+
except:
16+
llama_cpp = None
17+
18+
try:
19+
import llama_cpp_cuda
20+
except:
2121
llama_cpp_cuda = None
2222

2323

2424
def llama_cpp_lib():
25-
if shared.args.cpu or llama_cpp_cuda is None:
25+
if (shared.args.cpu and llama_cpp is not None) or llama_cpp_cuda is None:
2626
return llama_cpp
2727
else:
2828
return llama_cpp_cuda

modules/llamacpp_model.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
from modules.logging_colors import logger
1010
from modules.text_generation import get_max_prompt_length
1111

12-
import llama_cpp
13-
14-
if torch.cuda.is_available() and not torch.version.hip:
15-
try:
16-
import llama_cpp_cuda
17-
except:
18-
llama_cpp_cuda = None
19-
else:
12+
try:
13+
import llama_cpp
14+
except:
15+
llama_cpp = None
16+
17+
try:
18+
import llama_cpp_cuda
19+
except:
2020
llama_cpp_cuda = None
2121

2222

2323
def llama_cpp_lib():
24-
if shared.args.cpu or llama_cpp_cuda is None:
24+
if (shared.args.cpu and llama_cpp is not None) or llama_cpp_cuda is None:
2525
return llama_cpp
2626
else:
2727
return llama_cpp_cuda

one_click.py

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import argparse
22
import glob
33
import os
4+
import platform
45
import site
56
import subprocess
67
import sys
@@ -34,6 +35,25 @@ def is_macos():
3435
return sys.platform.startswith("darwin")
3536

3637

38+
def is_x86_64():
39+
return platform.machine() == "x86_64"
40+
41+
42+
def cpu_has_avx2():
43+
import cpuinfo
44+
45+
info = cpuinfo.get_cpu_info()
46+
if 'avx2' in info['flags']:
47+
return True
48+
49+
return False
50+
51+
52+
def torch_version():
53+
from torch import __version__ as torver
54+
return torver
55+
56+
3757
def is_installed():
3858
for sitedir in site.getsitepackages():
3959
if "site-packages" in sitedir and conda_env_path in sitedir:
@@ -137,7 +157,7 @@ def install_webui():
137157
install_pytorch = "python -m pip install torch==2.0.1a0 torchvision==0.15.2a0 intel_extension_for_pytorch==2.0.110+xpu -f https://developer.intel.com/ipex-whl-stable-xpu"
138158

139159
# Install Git and then Pytorch
140-
run_cmd(f"{install_git} && {install_pytorch}", assert_success=True, environment=True)
160+
run_cmd(f"{install_git} && {install_pytorch} && python -m pip install py-cpuinfo", assert_success=True, environment=True)
141161

142162
# Install the webui requirements
143163
update_requirements(initial_installation=True)
@@ -162,7 +182,37 @@ def update_requirements(initial_installation=False):
162182
if os.path.exists(extension_req_path):
163183
run_cmd("python -m pip install -r " + extension_req_path + " --upgrade", assert_success=True, environment=True)
164184

165-
textgen_requirements = open("requirements.txt").read().splitlines()
185+
# Detect the PyTorch version
186+
torver = torch_version()
187+
is_cuda = '+cu' in torver # 2.0.1+cu117
188+
is_rocm = '+rocm' in torver # 2.0.1+rocm5.4.2
189+
is_intel = '+cxx11' in torver # 2.0.1a0+cxx11.abi
190+
is_cpu = '+cpu' in torver # 2.0.1+cpu
191+
192+
if is_rocm:
193+
if cpu_has_avx2():
194+
requirements_file = "requirements_amd.txt"
195+
else:
196+
requirements_file = "requirements_amd_noavx2.txt"
197+
elif is_cpu:
198+
if cpu_has_avx2():
199+
requirements_file = "requirements_cpu_only.txt"
200+
else:
201+
requirements_file = "requirements_cpu_only_noavx2.txt"
202+
elif is_macos():
203+
if is_x86_64():
204+
requirements_file = "requirements_apple_intel.txt"
205+
else:
206+
requirements_file = "requirements_apple_silicon.txt"
207+
else:
208+
if cpu_has_avx2():
209+
requirements_file = "requirements.txt"
210+
else:
211+
requirements_file = "requirements_noavx2.txt"
212+
213+
print(f"Using the following requirements file: {requirements_file}")
214+
215+
textgen_requirements = open(requirements_file).read().splitlines()
166216

167217
# Workaround for git+ packages not updating properly. Also store requirements.txt for later use
168218
git_requirements = [req for req in textgen_requirements if req.startswith("git+")]
@@ -178,14 +228,7 @@ def update_requirements(initial_installation=False):
178228
print(f"Uninstalled {package_name}")
179229

180230
# Install/update the project requirements
181-
run_cmd("python -m pip install -r requirements.txt --upgrade", assert_success=True, environment=True)
182-
183-
# The following requirements are for CUDA, not CPU
184-
# Parse output of 'pip show torch' to determine torch version
185-
torver_cmd = run_cmd("python -m pip show torch", assert_success=True, environment=True, capture_output=True)
186-
torver = [v.split()[1] for v in torver_cmd.stdout.decode('utf-8').splitlines() if 'Version:' in v][0]
187-
is_cuda = '+cu' in torver
188-
is_rocm = '+rocm' in torver
231+
run_cmd(f"python -m pip install -r {requirements_file} --upgrade", assert_success=True, environment=True)
189232

190233
# Check for '+cu' or '+rocm' in version string to determine if torch uses CUDA or ROCm. Check for pytorch-cuda as well for backwards compatibility
191234
if not any((is_cuda, is_rocm)) and run_cmd("conda list -f pytorch-cuda | grep pytorch-cuda", environment=True, capture_output=True).returncode == 1:
@@ -216,29 +259,6 @@ def update_requirements(initial_installation=False):
216259
# Install the correct version of g++
217260
run_cmd("conda install -y -k conda-forge::gxx_linux-64=11.2.0", environment=True)
218261

219-
if is_rocm:
220-
# Pre-installed ExLlama module does not support AMD GPU
221-
run_cmd("python -m pip uninstall -y exllama", environment=True)
222-
# Get download URL for latest ExLlama ROCm wheel
223-
exllama_rocm = run_cmd('curl -s https://api.github.com/repos/jllllll/exllama/releases/latest | grep browser_download_url | grep rocm5.4.2-cp310-cp310-linux_x86_64.whl | cut -d : -f 2,3 | tr -d \'"\'', environment=True, capture_output=True).stdout.decode('utf-8')
224-
if 'rocm5.4.2-cp310-cp310-linux_x86_64.whl' in exllama_rocm:
225-
run_cmd("python -m pip install " + exllama_rocm, environment=True)
226-
227-
# Install/Update ROCm AutoGPTQ for AMD GPUs
228-
auto_gptq_version = [req for req in textgen_requirements if req.startswith('https://github.com/PanQiWei/AutoGPTQ/releases/download/')][0].split('/')[7]
229-
auto_gptq_wheel = run_cmd(f'curl -s https://api.github.com/repos/PanQiWei/AutoGPTQ/releases/tags/{auto_gptq_version} | grep browser_download_url | grep rocm5.4.2-cp310-cp310-linux_x86_64.whl | cut -d : -f 2,3 | tr -d \'"\'', environment=True, capture_output=True).stdout.decode('utf-8')
230-
if not auto_gptq_wheel and run_cmd(f"python -m pip install {auto_gptq_wheel} --force-reinstall --no-deps", environment=True).returncode != 0:
231-
print_big_message("ERROR: AutoGPTQ wheel installation failed!\n You will not be able to use GPTQ-based models with AutoGPTQ.")
232-
233-
# Install GPTQ-for-LLaMa for ROCm
234-
gptq_wheel = run_cmd('curl -s https://api.github.com/repos/jllllll/GPTQ-for-LLaMa-CUDA/releases/latest | grep browser_download_url | grep rocm5.4.2-cp310-cp310-linux_x86_64.whl | cut -d : -f 2,3 | tr -d \'"\'', environment=True, capture_output=True).stdout.decode('utf-8')
235-
install_gptq = run_cmd("python -m pip install " + gptq_wheel, environment=True).returncode == 0
236-
if install_gptq:
237-
print("Wheel installation success!")
238-
else:
239-
print("ERROR: GPTQ wheel installation failed.")
240-
print("You will not be able to use GPTQ-based models with GPTQ-for-LLaMa.")
241-
242262
clear_cache()
243263

244264

requirements.txt

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,17 @@ wandb
2929
bitsandbytes==0.41.1; platform_system != "Windows"
3030
https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.1-py3-none-win_amd64.whl; platform_system == "Windows"
3131

32-
# AutoGPTQ
32+
# llama-cpp-python (CPU only, AVX2)
33+
https://github.com/abetlen/llama-cpp-python/releases/download/v0.2.6/llama_cpp_python-0.2.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; platform_system == "Linux" and platform_machine == "x86_64"
34+
https://github.com/abetlen/llama-cpp-python/releases/download/v0.2.6/llama_cpp_python-0.2.6-cp310-cp310-win_amd64.whl; platform_system == "Windows"
35+
36+
# CUDA wheels
3337
https://github.com/PanQiWei/AutoGPTQ/releases/download/v0.4.2/auto_gptq-0.4.2+cu117-cp310-cp310-win_amd64.whl; platform_system == "Windows"
3438
https://github.com/PanQiWei/AutoGPTQ/releases/download/v0.4.2/auto_gptq-0.4.2+cu117-cp310-cp310-linux_x86_64.whl; platform_system == "Linux" and platform_machine == "x86_64"
35-
36-
# ExLlama
3739
https://github.com/jllllll/exllama/releases/download/0.0.17/exllama-0.0.17+cu117-cp310-cp310-win_amd64.whl; platform_system == "Windows"
3840
https://github.com/jllllll/exllama/releases/download/0.0.17/exllama-0.0.17+cu117-cp310-cp310-linux_x86_64.whl; platform_system == "Linux" and platform_machine == "x86_64"
39-
40-
# llama-cpp-python without GPU support
41-
llama-cpp-python==0.2.6; platform_system != "Windows"
42-
https://github.com/abetlen/llama-cpp-python/releases/download/v0.2.6/llama_cpp_python-0.2.6-cp310-cp310-win_amd64.whl; platform_system == "Windows"
43-
44-
# llama-cpp-python with CUDA support
4541
https://github.com/jllllll/llama-cpp-python-cuBLAS-wheels/releases/download/textgen-webui/llama_cpp_python_cuda-0.2.6+cu117-cp310-cp310-win_amd64.whl; platform_system == "Windows"
4642
https://github.com/jllllll/llama-cpp-python-cuBLAS-wheels/releases/download/textgen-webui/llama_cpp_python_cuda-0.2.6+cu117-cp310-cp310-manylinux_2_31_x86_64.whl; platform_system == "Linux" and platform_machine == "x86_64"
47-
48-
# GPTQ-for-LLaMa
4943
https://github.com/jllllll/GPTQ-for-LLaMa-CUDA/releases/download/0.1.0/gptq_for_llama-0.1.0+cu117-cp310-cp310-win_amd64.whl; platform_system == "Windows"
5044
https://github.com/jllllll/GPTQ-for-LLaMa-CUDA/releases/download/0.1.0/gptq_for_llama-0.1.0+cu117-cp310-cp310-linux_x86_64.whl; platform_system == "Linux" and platform_machine == "x86_64"
51-
52-
# ctransformers
5345
https://github.com/jllllll/ctransformers-cuBLAS-wheels/releases/download/AVX2/ctransformers-0.2.27+cu117-py3-none-any.whl

requirements_amd.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
aiofiles==23.1.0
2+
fastapi==0.95.2
3+
gradio_client==0.2.5
4+
gradio==3.33.1
5+
pydantic==1.10.12
6+
7+
accelerate==0.23.*
8+
colorama
9+
datasets
10+
einops
11+
exllamav2==0.0.3
12+
markdown
13+
numpy==1.24
14+
optimum==1.13.1
15+
pandas
16+
peft==0.5.*
17+
Pillow>=9.5.0
18+
pyyaml
19+
requests
20+
safetensors==0.3.2
21+
transformers==4.33.*
22+
scipy
23+
sentencepiece
24+
tensorboard
25+
tqdm
26+
wandb
27+
28+
# bitsandbytes
29+
bitsandbytes==0.41.1; platform_system != "Windows"
30+
https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.1-py3-none-win_amd64.whl; platform_system == "Windows"
31+
32+
# llama-cpp-python (CPU only, AVX2)
33+
https://github.com/abetlen/llama-cpp-python/releases/download/v0.2.6/llama_cpp_python-0.2.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; platform_system == "Linux" and platform_machine == "x86_64"
34+
https://github.com/abetlen/llama-cpp-python/releases/download/v0.2.6/llama_cpp_python-0.2.6-cp310-cp310-win_amd64.whl; platform_system == "Windows"
35+
36+
# AMD wheels
37+
https://github.com/PanQiWei/AutoGPTQ/releases/download/v0.4.2/auto_gptq-0.4.2+rocm5.4.2-cp310-cp310-linux_x86_64.whl; platform_system == "Linux" and platform_machine == "x86_64"
38+
https://github.com/jllllll/exllama/releases/download/0.0.17/exllama-0.0.17+rocm5.4.2-cp310-cp310-linux_x86_64.whl; platform_system == "Linux" and platform_machine == "x86_64"
39+
https://github.com/jllllll/llama-cpp-python-cuBLAS-wheels/releases/download/rocm/llama_cpp_python_cuda-0.2.6+rocm5.4.2-cp310-cp310-manylinux_2_31_x86_64.whl; platform_system == "Linux" and platform_machine == "x86_64"
40+
https://github.com/jllllll/GPTQ-for-LLaMa-CUDA/releases/download/0.1.0/gptq_for_llama-0.1.0+rocm5.4.2-cp310-cp310-linux_x86_64.whl; platform_system == "Linux" and platform_machine == "x86_64"

requirements_amd_noavx2.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
aiofiles==23.1.0
2+
fastapi==0.95.2
3+
gradio_client==0.2.5
4+
gradio==3.33.1
5+
pydantic==1.10.12
6+
7+
accelerate==0.23.*
8+
colorama
9+
datasets
10+
einops
11+
exllamav2==0.0.3
12+
markdown
13+
numpy==1.24
14+
optimum==1.13.1
15+
pandas
16+
peft==0.5.*
17+
Pillow>=9.5.0
18+
pyyaml
19+
requests
20+
safetensors==0.3.2
21+
transformers==4.33.*
22+
scipy
23+
sentencepiece
24+
tensorboard
25+
tqdm
26+
wandb
27+
28+
# bitsandbytes
29+
bitsandbytes==0.41.1; platform_system != "Windows"
30+
https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.1-py3-none-win_amd64.whl; platform_system == "Windows"
31+
32+
# llama-cpp-python (CPU only)
33+
https://github.com/jllllll/llama-cpp-python-cuBLAS-wheels/releases/download/basic/llama_cpp_python-0.2.6+cu117-cp310-cp310-manylinux_2_31_x86_64.whl; platform_system == "Linux" and platform_machine == "x86_64"
34+
https://github.com/jllllll/llama-cpp-python-cuBLAS-wheels/releases/download/basic/llama_cpp_python-0.2.6+cu117-cp310-cp310-win_amd64.whl; platform_system == "Windows"
35+
36+
# AMD wheels
37+
https://github.com/PanQiWei/AutoGPTQ/releases/download/v0.4.2/auto_gptq-0.4.2+rocm5.4.2-cp310-cp310-linux_x86_64.whl; platform_system == "Linux" and platform_machine == "x86_64"
38+
https://github.com/jllllll/exllama/releases/download/0.0.17/exllama-0.0.17+rocm5.4.2-cp310-cp310-linux_x86_64.whl; platform_system == "Linux" and platform_machine == "x86_64"
39+
https://github.com/jllllll/GPTQ-for-LLaMa-CUDA/releases/download/0.1.0/gptq_for_llama-0.1.0+rocm5.4.2-cp310-cp310-linux_x86_64.whl; platform_system == "Linux" and platform_machine == "x86_64"

requirements_apple_intel.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
aiofiles==23.1.0
2+
fastapi==0.95.2
3+
gradio_client==0.2.5
4+
gradio==3.33.1
5+
pydantic==1.10.12
6+
7+
accelerate==0.23.*
8+
colorama
9+
datasets
10+
einops
11+
exllamav2==0.0.3
12+
markdown
13+
numpy==1.24
14+
optimum==1.13.1
15+
pandas
16+
peft==0.5.*
17+
Pillow>=9.5.0
18+
pyyaml
19+
requests
20+
safetensors==0.3.2
21+
transformers==4.33.*
22+
scipy
23+
sentencepiece
24+
tensorboard
25+
tqdm
26+
wandb
27+
28+
# bitsandbytes
29+
bitsandbytes==0.41.1; platform_system != "Windows"
30+
https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.1-py3-none-win_amd64.whl; platform_system == "Windows"
31+
32+
# Mac wheels
33+
https://github.com/jllllll/llama-cpp-python-cuBLAS-wheels/releases/download/metal/llama_cpp_python-0.2.6-cp310-cp310-macosx_11_0_x86_64.whl

requirements_apple_silicon.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
aiofiles==23.1.0
2+
fastapi==0.95.2
3+
gradio_client==0.2.5
4+
gradio==3.33.1
5+
pydantic==1.10.12
6+
7+
accelerate==0.23.*
8+
colorama
9+
datasets
10+
einops
11+
exllamav2==0.0.3
12+
markdown
13+
numpy==1.24
14+
optimum==1.13.1
15+
pandas
16+
peft==0.5.*
17+
Pillow>=9.5.0
18+
pyyaml
19+
requests
20+
safetensors==0.3.2
21+
transformers==4.33.*
22+
scipy
23+
sentencepiece
24+
tensorboard
25+
tqdm
26+
wandb
27+
28+
# bitsandbytes
29+
bitsandbytes==0.41.1; platform_system != "Windows"
30+
https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.1-py3-none-win_amd64.whl; platform_system == "Windows"
31+
32+
# Mac wheels
33+
https://github.com/jllllll/llama-cpp-python-cuBLAS-wheels/releases/download/metal/llama_cpp_python-0.2.6-cp310-cp310-macosx_11_0_arm64.whl

0 commit comments

Comments
 (0)