ghostai1 commited on
Commit
880bece
·
verified ·
1 Parent(s): 9c876fa

Create cuda12install.sh

Browse files
Files changed (1) hide show
  1. cuda12install.sh +147 -0
cuda12install.sh ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # setup_musicgen_env.sh
4
+ # Automates the setup of a clean virtual environment for MusicGen script
5
+ # Handles dependency conflicts, installs compatible versions, and verifies setup
6
+ # Designed for Ubuntu homelab (T-1000) with RTX 3060 Ti, CUDA 12, Python 3.10
7
+
8
+ set -e # Exit on any error
9
+
10
+ # Define variables
11
+ VENV_DIR="$HOME/ghostai_music_generator/musicgen_env"
12
+ LOG_FILE="$HOME/ghostai_music_generator/setup_musicgen_env_$(date +%Y%m%d_%H%M%S).log"
13
+ PYTHON_VERSION="python3.10"
14
+ PIP="$VENV_DIR/bin/pip"
15
+ PYTHON="$VENV_DIR/bin/python"
16
+
17
+ # Create log directory
18
+ mkdir -p "$(dirname "$LOG_FILE")"
19
+
20
+ # Function to log messages
21
+ log() {
22
+ echo "[$(date +%Y-%m-%d\ %H:%M:%S)] $1" | tee -a "$LOG_FILE"
23
+ }
24
+
25
+ # Function to check command status
26
+ check_status() {
27
+ if [ $? -ne 0 ]; then
28
+ log "ERROR: $1 failed"
29
+ exit 1
30
+ fi
31
+ }
32
+
33
+ # Function to check if a package is installed
34
+ check_package() {
35
+ dpkg -l "$1" &>/dev/null
36
+ return $?
37
+ }
38
+
39
+ # Start logging
40
+ log "Starting MusicGen environment setup"
41
+
42
+ # Install system dependencies
43
+ log "Installing system dependencies..."
44
+ sudo apt-get update >> "$LOG_FILE" 2>&1
45
+ check_status "apt-get update"
46
+
47
+ for pkg in build-essential cmake python3.10 python3.10-venv python3.10-dev; do
48
+ if ! check_package "$pkg"; then
49
+ log "Installing $pkg..."
50
+ sudo apt-get install -y "$pkg" >> "$LOG_FILE" 2>&1
51
+ check_status "install $pkg"
52
+ else
53
+ log "$pkg already installed"
54
+ fi
55
+ done
56
+
57
+ # Remove existing virtual environment if it exists
58
+ if [ -d "$VENV_DIR" ]; then
59
+ log "Removing existing virtual environment at $VENV_DIR"
60
+ rm -rf "$VENV_DIR"
61
+ check_status "remove virtual environment"
62
+ fi
63
+
64
+ # Create and activate virtual environment
65
+ log "Creating virtual environment at $VENV_DIR"
66
+ $PYTHON_VERSION -m venv "$VENV_DIR"
67
+ check_status "create virtual environment"
68
+ source "$VENV_DIR/bin/activate"
69
+ check_status "activate virtual environment"
70
+
71
+ # Upgrade pip
72
+ log "Upgrading pip..."
73
+ $PIP install --upgrade pip >> "$LOG_FILE" 2>&1
74
+ check_status "upgrade pip"
75
+
76
+ # Uninstall conflicting packages
77
+ log "Uninstalling conflicting packages..."
78
+ $PIP uninstall -y torch torchaudio numpy transformers requests spacy networkx audiocraft pydub gradio typer pydantic laion-clap pydantic-core xformers torchdata torchtext torchvision stable-audio-tools accelerate dctorch >> "$LOG_FILE" 2>&1
79
+ check_status "uninstall conflicting packages"
80
+
81
+ # Install dependencies
82
+ log "Installing dependencies..."
83
+ $PIP install torch==2.1.0+cu121 torchaudio==2.1.0+cu121 --index-url https://download.pytorch.org/whl/cu121 >> "$LOG_FILE" 2>&1
84
+ check_status "install torch and torchaudio"
85
+ $PIP install git+https://github.com/facebookresearch/audiocraft.git@refs/tags/v1.3.0 numpy==1.26.4 transformers==4.40.2 requests==2.31.0 spacy==3.7.2 networkx==2.8.8 pydub==0.25.1 gradio==3.50.2 pydantic==1.10.13 >> "$LOG_FILE" 2>&1
86
+ check_status "install remaining dependencies"
87
+
88
+ # Verify installation
89
+ log "Verifying installed packages..."
90
+ $PIP list | grep -E "torch|torchaudio|numpy|transformers|requests|spacy|networkx|audiocraft|pydub|gradio|typer|pydantic|laion-clap" > "$HOME/ghostai_music_generator/verified_packages.txt"
91
+ check_status "list installed packages"
92
+
93
+ # Check CUDA and torch
94
+ log "Verifying CUDA and torch..."
95
+ $PYTHON -c "import torch; print(torch.__version__, torch.cuda.is_available(), torch.version.cuda)" >> "$LOG_FILE" 2>&1
96
+ check_status "verify CUDA and torch"
97
+
98
+ # Test imports
99
+ log "Testing imports..."
100
+ $PYTHON -c "import torch; import torchaudio; import audiocraft; import numpy; import transformers; import requests; import spacy; import networkx; import pydub; import gradio; import pydantic; print('All imports successful')" >> "$LOG_FILE" 2>&1
101
+ check_status "test imports"
102
+
103
+ # Check for dependency conflicts
104
+ log "Checking for dependency conflicts with pipdeptree..."
105
+ $PIP install pipdeptree >> "$LOG_FILE" 2>&1
106
+ check_status "install pipdeptree"
107
+ $PYTHON -m pipdeptree > "$HOME/ghostai_music_generator/pipdeptree_output.txt" 2>> "$LOG_FILE"
108
+ check_status "run pipdeptree"
109
+
110
+ # Clean up unnecessary packages
111
+ log "Cleaning up unnecessary packages..."
112
+ $PIP uninstall -y stable-audio-tools laion-clap x-transformers accelerate dctorch torchdata torchtext torchvision >> "$LOG_FILE" 2>&1 || true # Ignore errors if not installed
113
+
114
+ # Final verification
115
+ log "Final verification of installed packages..."
116
+ EXPECTED_PACKAGES=(
117
+ "audiocraft==1.3.0"
118
+ "gradio==3.50.2"
119
+ "networkx==2.8.8"
120
+ "numpy==1.26.4"
121
+ "pydantic==1.10.13"
122
+ "pydub==0.25.1"
123
+ "requests==2.31.0"
124
+ "spacy==3.7.2"
125
+ "torch==2.1.0+cu121"
126
+ "torchaudio==2.1.0+cu121"
127
+ "transformers==4.40.2"
128
+ "typer==0.7.0"
129
+ )
130
+ for pkg in "${EXPECTED_PACKAGES[@]}"; do
131
+ if $PIP list | grep -q "$pkg"; then
132
+ log "$pkg verified"
133
+ else
134
+ log "ERROR: $pkg not found"
135
+ exit 1
136
+ fi
137
+ done
138
+
139
+ log "MusicGen environment setup completed successfully"
140
+ log "Virtual environment: $VENV_DIR"
141
+ log "Log file: $LOG_FILE"
142
+ log "Verified packages: $HOME/ghostai_music_generator/verified_packages.txt"
143
+ log "Dependency tree: $HOME/ghostai_music_generator/pipdeptree_output.txt"
144
+ log "To activate: source $VENV_DIR/bin/activate"
145
+ log "To run script: python musicgen_optimized.py"
146
+
147
+ exit 0