Skip to content

Commit

Permalink
update installation protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
BBC-Esq authored Jul 31, 2024
1 parent 6a0271d commit 2a4af42
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 49 deletions.
4 changes: 2 additions & 2 deletions ct2_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ def set_cuda_paths():

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

env_vars = ['CUDA_PATH', 'CUDA_PATH_V12_2', 'PATH']
env_vars = ['CUDA_PATH', 'CUDA_PATH_V12_1', 'PATH']

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

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

set_cuda_paths()

Expand Down
11 changes: 8 additions & 3 deletions ct2_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
import platform

class CheckQuantizationSupport:

excluded_types = ['int16', 'int8', 'int8_float32', 'int8_float16', 'int8_bfloat16']

def has_cuda_device(self):
cuda_device_count = ctranslate2.get_cuda_device_count()
return cuda_device_count > 0

def get_supported_quantizations_cuda(self):
cuda_quantizations = ctranslate2.get_supported_compute_types("cuda")
return [q for q in cuda_quantizations if q != 'int16']
excluded_types = self.excluded_types
return [q for q in cuda_quantizations if q not in excluded_types]

def get_supported_quantizations_cpu(self):
cpu_quantizations = ctranslate2.get_supported_compute_types("cpu")
return [q for q in cpu_quantizations if q != 'int16']
excluded_types = self.excluded_types
return [q for q in cpu_quantizations if q not in excluded_types]

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

print(f"Updated {device} quantizations in config.yaml to: {quantizations}")
# print(f"Updated {device} quantizations in config.yaml to: {quantizations}")
132 changes: 88 additions & 44 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,104 @@
import subprocess
import sys
import os
import time
from pathlib import Path
import shutil

def run_command(command):
try:
subprocess.run(command, shell=True, check=True)
except subprocess.CalledProcessError as e:
print(f"Error running command: {command}")
print(f"Error message: {e}")
sys.exit(1)

def move_file(src, dst):
try:
if not src.exists():
print(f"Source file not found: {src}")
return False
shutil.move(str(src), str(dst))
print(f"Moved {src.name} to {dst}")
return True
except PermissionError:
print(f"Permission denied when trying to move {src}")
except Exception as e:
print(f"Error moving {src}: {e}")
return False

def main():
# Step 1: Upgrade pip, setuptools, and wheel
run_command("python -m pip install --upgrade pip setuptools wheel")
def install_libraries_with_retry(max_retries=3, delay=3):
libraries = [
"av==12.3.0",
"CFFI==1.16.0",
"certifi==2024.7.4",
"chardet==5.2.0",
"ctranslate2==4.3.1",
"faster-whisper==1.0.2",
"filelock==3.15.4",
"huggingface-hub==0.24.1",
"idna==3.7",
"nvidia-cublas-cu12==12.1.3.1",
"nvidia-cuda-nvrtc-cu12==12.1.105",
"nvidia-cuda-runtime-cu12==12.1.105",
"nvidia-cudnn-cu12==8.9.7.29",
"numpy==1.26.4",
"pycparser==2.22",
"PyYAML==6.0.1",
"requests==2.32.3",
"sounddevice==0.4.7",
"tokenizers==0.19.1",
"tqdm==4.66.4",
"urllib3==2.2.2"
]

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

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

files_to_move = [
(python_lib_path / 'nvidia' / 'cublas' / 'bin' / 'cublas64_12.dll', current_dir),
(python_lib_path / 'nvidia' / 'cublas' / 'bin' / 'cublasLt64_12.dll', current_dir),
(python_lib_path / 'nvidia' / 'cudnn' / 'bin' / 'cudnn_cnn_infer64_8.dll', current_dir)
]
print("\n--- Installation Summary ---")
if failed_installations:
print("\nThe following libraries failed to install:")
for lib in failed_installations:
print(f"- {lib}")

if multiple_attempts:
print("\nThe following libraries required multiple attempts to install:")
for lib, attempts in multiple_attempts:
print(f"- {lib} (took {attempts} attempts)")

if not failed_installations and not multiple_attempts:
print("\nAll libraries installed successfully on the first attempt.")
elif not failed_installations:
print("\nAll libraries were eventually installed successfully.")

all_files_moved = True
for src, dst in files_to_move:
if not move_file(src, dst):
all_files_moved = False
return failed_installations, multiple_attempts

# Step 4: Print result message
if all_files_moved:
def main():
start_time = time.time()

# install uv
print("\033[92mInstalling uv:\033[0m")
subprocess.run(["pip", "install", "uv"], check=True)

print("\033[92mInstalling PySide6:\033[0m")
subprocess.run(["uv", "pip", "install", "pyside6", "--no-cache-dir", "--link-mode=copy"], check=True)

# Upgrade pip, setuptools, and wheel using uv
print("\033[92mUpgrading pip, setuptools, and wheel:\033[0m")
subprocess.run(f"{sys.executable} -m uv pip install --upgrade pip setuptools wheel", shell=True, check=True)

# Step 2: Install libraries with retry using uv
print("\033[92mInstalling dependencies:\033[0m")
failed, multiple = install_libraries_with_retry()

if not failed:
print("\033[92mInstallation was successful! The program is ready to use.")
print(f"To run it, enter the command: python ct2_main.py\033[0m")
else:
print("\033[91mInstallation completed with errors. Some files could not be moved.")
print("Please check the error messages above and try to resolve the issues manually.\033[0m")
print("\033[91mInstallation encountered some issues. Please review the installation summary above.\033[0m")

end_time = time.time()
total_time = end_time - start_time
hours, rem = divmod(total_time, 3600)
minutes, seconds = divmod(rem, 60)

print(f"\033[92m\nTotal installation time: {int(hours):02d}:{int(minutes):02d}:{seconds:05.2f}\033[0m")

if __name__ == "__main__":
main()

0 comments on commit 2a4af42

Please sign in to comment.