Skip to content

Commit 2a4af42

Browse files
authored
update installation protocol
1 parent 6a0271d commit 2a4af42

File tree

3 files changed

+98
-49
lines changed

3 files changed

+98
-49
lines changed

ct2_main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ def set_cuda_paths():
1111

1212
paths_to_add = [str(cuda_path), str(cublas_path), str(cudnn_path)]
1313

14-
env_vars = ['CUDA_PATH', 'CUDA_PATH_V12_2', 'PATH']
14+
env_vars = ['CUDA_PATH', 'CUDA_PATH_V12_1', 'PATH']
1515

1616
for env_var in env_vars:
1717
current_value = os.environ.get(env_var, '')
1818
new_value = os.pathsep.join(paths_to_add + [current_value] if current_value else paths_to_add)
1919
os.environ[env_var] = new_value
2020

21-
print("CUDA paths have been set or updated in the environment variables.")
21+
# print("CUDA paths have been set or updated in the environment variables.")
2222

2323
set_cuda_paths()
2424

ct2_utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33
import platform
44

55
class CheckQuantizationSupport:
6+
7+
excluded_types = ['int16', 'int8', 'int8_float32', 'int8_float16', 'int8_bfloat16']
8+
69
def has_cuda_device(self):
710
cuda_device_count = ctranslate2.get_cuda_device_count()
811
return cuda_device_count > 0
912

1013
def get_supported_quantizations_cuda(self):
1114
cuda_quantizations = ctranslate2.get_supported_compute_types("cuda")
12-
return [q for q in cuda_quantizations if q != 'int16']
15+
excluded_types = self.excluded_types
16+
return [q for q in cuda_quantizations if q not in excluded_types]
1317

1418
def get_supported_quantizations_cpu(self):
1519
cpu_quantizations = ctranslate2.get_supported_compute_types("cpu")
16-
return [q for q in cpu_quantizations if q != 'int16']
20+
excluded_types = self.excluded_types
21+
return [q for q in cpu_quantizations if q not in excluded_types]
1722

1823
def update_supported_quantizations(self):
1924
cpu_quantizations = self.get_supported_quantizations_cpu()
@@ -38,4 +43,4 @@ def _update_supported_quantizations_in_config(self, device, quantizations):
3843
with open("config.yaml", "w") as f:
3944
yaml.safe_dump(config, f, default_style="'")
4045

41-
print(f"Updated {device} quantizations in config.yaml to: {quantizations}")
46+
# print(f"Updated {device} quantizations in config.yaml to: {quantizations}")

setup.py

Lines changed: 88 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,104 @@
11
import subprocess
22
import sys
33
import os
4+
import time
45
from pathlib import Path
5-
import shutil
6-
7-
def run_command(command):
8-
try:
9-
subprocess.run(command, shell=True, check=True)
10-
except subprocess.CalledProcessError as e:
11-
print(f"Error running command: {command}")
12-
print(f"Error message: {e}")
13-
sys.exit(1)
14-
15-
def move_file(src, dst):
16-
try:
17-
if not src.exists():
18-
print(f"Source file not found: {src}")
19-
return False
20-
shutil.move(str(src), str(dst))
21-
print(f"Moved {src.name} to {dst}")
22-
return True
23-
except PermissionError:
24-
print(f"Permission denied when trying to move {src}")
25-
except Exception as e:
26-
print(f"Error moving {src}: {e}")
27-
return False
286

29-
def main():
30-
# Step 1: Upgrade pip, setuptools, and wheel
31-
run_command("python -m pip install --upgrade pip setuptools wheel")
7+
def install_libraries_with_retry(max_retries=3, delay=3):
8+
libraries = [
9+
"av==12.3.0",
10+
"CFFI==1.16.0",
11+
"certifi==2024.7.4",
12+
"chardet==5.2.0",
13+
"ctranslate2==4.3.1",
14+
"faster-whisper==1.0.2",
15+
"filelock==3.15.4",
16+
"huggingface-hub==0.24.1",
17+
"idna==3.7",
18+
"nvidia-cublas-cu12==12.1.3.1",
19+
"nvidia-cuda-nvrtc-cu12==12.1.105",
20+
"nvidia-cuda-runtime-cu12==12.1.105",
21+
"nvidia-cudnn-cu12==8.9.7.29",
22+
"numpy==1.26.4",
23+
"pycparser==2.22",
24+
"PyYAML==6.0.1",
25+
"requests==2.32.3",
26+
"sounddevice==0.4.7",
27+
"tokenizers==0.19.1",
28+
"tqdm==4.66.4",
29+
"urllib3==2.2.2"
30+
]
3231

33-
# Step 2: Install requirements
34-
run_command("pip install -r requirements.txt")
32+
failed_installations = []
33+
multiple_attempts = []
3534

36-
# Step 3: Move files
37-
current_dir = Path(__file__).parent.resolve()
38-
python_lib_path = current_dir / 'Lib' / 'site-packages'
35+
for library in libraries:
36+
for attempt in range(max_retries):
37+
try:
38+
print(f"\nAttempt {attempt + 1} of {max_retries}: Installing {library}")
39+
command = [sys.executable, "-m", "uv", "pip", "install", library, "--no-deps", "--no-cache-dir"]
40+
subprocess.run(command, check=True, capture_output=True, text=True)
41+
print(f"Successfully installed {library}")
42+
if attempt > 0:
43+
multiple_attempts.append((library, attempt + 1))
44+
break
45+
except subprocess.CalledProcessError as e:
46+
print(f"Attempt {attempt + 1} failed. Error: {e.stderr.strip()}")
47+
if attempt < max_retries - 1:
48+
print(f"Retrying in {delay} seconds...")
49+
time.sleep(delay)
50+
else:
51+
print(f"Failed to install {library} after {max_retries} attempts.")
52+
failed_installations.append(library)
3953

40-
files_to_move = [
41-
(python_lib_path / 'nvidia' / 'cublas' / 'bin' / 'cublas64_12.dll', current_dir),
42-
(python_lib_path / 'nvidia' / 'cublas' / 'bin' / 'cublasLt64_12.dll', current_dir),
43-
(python_lib_path / 'nvidia' / 'cudnn' / 'bin' / 'cudnn_cnn_infer64_8.dll', current_dir)
44-
]
54+
print("\n--- Installation Summary ---")
55+
if failed_installations:
56+
print("\nThe following libraries failed to install:")
57+
for lib in failed_installations:
58+
print(f"- {lib}")
59+
60+
if multiple_attempts:
61+
print("\nThe following libraries required multiple attempts to install:")
62+
for lib, attempts in multiple_attempts:
63+
print(f"- {lib} (took {attempts} attempts)")
64+
65+
if not failed_installations and not multiple_attempts:
66+
print("\nAll libraries installed successfully on the first attempt.")
67+
elif not failed_installations:
68+
print("\nAll libraries were eventually installed successfully.")
4569

46-
all_files_moved = True
47-
for src, dst in files_to_move:
48-
if not move_file(src, dst):
49-
all_files_moved = False
70+
return failed_installations, multiple_attempts
5071

51-
# Step 4: Print result message
52-
if all_files_moved:
72+
def main():
73+
start_time = time.time()
74+
75+
# install uv
76+
print("\033[92mInstalling uv:\033[0m")
77+
subprocess.run(["pip", "install", "uv"], check=True)
78+
79+
print("\033[92mInstalling PySide6:\033[0m")
80+
subprocess.run(["uv", "pip", "install", "pyside6", "--no-cache-dir", "--link-mode=copy"], check=True)
81+
82+
# Upgrade pip, setuptools, and wheel using uv
83+
print("\033[92mUpgrading pip, setuptools, and wheel:\033[0m")
84+
subprocess.run(f"{sys.executable} -m uv pip install --upgrade pip setuptools wheel", shell=True, check=True)
85+
86+
# Step 2: Install libraries with retry using uv
87+
print("\033[92mInstalling dependencies:\033[0m")
88+
failed, multiple = install_libraries_with_retry()
89+
90+
if not failed:
5391
print("\033[92mInstallation was successful! The program is ready to use.")
5492
print(f"To run it, enter the command: python ct2_main.py\033[0m")
5593
else:
56-
print("\033[91mInstallation completed with errors. Some files could not be moved.")
57-
print("Please check the error messages above and try to resolve the issues manually.\033[0m")
94+
print("\033[91mInstallation encountered some issues. Please review the installation summary above.\033[0m")
95+
96+
end_time = time.time()
97+
total_time = end_time - start_time
98+
hours, rem = divmod(total_time, 3600)
99+
minutes, seconds = divmod(rem, 60)
100+
101+
print(f"\033[92m\nTotal installation time: {int(hours):02d}:{int(minutes):02d}:{seconds:05.2f}\033[0m")
58102

59103
if __name__ == "__main__":
60104
main()

0 commit comments

Comments
 (0)