|
#!/bin/bash |
|
|
|
|
|
|
|
|
|
|
|
|
|
set -e |
|
|
|
|
|
VENV_DIR="$HOME/ghostai_music_generator/musicgen_env" |
|
LOG_FILE="$HOME/ghostai_music_generator/setup_musicgen_env_$(date +%Y%m%d_%H%M%S).log" |
|
PYTHON_VERSION="python3.10" |
|
PIP="$VENV_DIR/bin/pip" |
|
PYTHON="$VENV_DIR/bin/python" |
|
|
|
|
|
mkdir -p "$(dirname "$LOG_FILE")" |
|
|
|
|
|
log() { |
|
echo "[$(date +%Y-%m-%d\ %H:%M:%S)] $1" | tee -a "$LOG_FILE" |
|
} |
|
|
|
|
|
check_status() { |
|
if [ $? -ne 0 ]; then |
|
log "ERROR: $1 failed" |
|
exit 1 |
|
fi |
|
} |
|
|
|
|
|
check_package() { |
|
dpkg -l "$1" &>/dev/null |
|
return $? |
|
} |
|
|
|
|
|
log "Starting MusicGen environment setup" |
|
|
|
|
|
log "Installing system dependencies..." |
|
sudo apt-get update >> "$LOG_FILE" 2>&1 |
|
check_status "apt-get update" |
|
|
|
for pkg in build-essential cmake python3.10 python3.10-venv python3.10-dev; do |
|
if ! check_package "$pkg"; then |
|
log "Installing $pkg..." |
|
sudo apt-get install -y "$pkg" >> "$LOG_FILE" 2>&1 |
|
check_status "install $pkg" |
|
else |
|
log "$pkg already installed" |
|
fi |
|
done |
|
|
|
|
|
if [ -d "$VENV_DIR" ]; then |
|
log "Removing existing virtual environment at $VENV_DIR" |
|
rm -rf "$VENV_DIR" |
|
check_status "remove virtual environment" |
|
fi |
|
|
|
|
|
log "Creating virtual environment at $VENV_DIR" |
|
$PYTHON_VERSION -m venv "$VENV_DIR" |
|
check_status "create virtual environment" |
|
source "$VENV_DIR/bin/activate" |
|
check_status "activate virtual environment" |
|
|
|
|
|
log "Upgrading pip..." |
|
$PIP install --upgrade pip >> "$LOG_FILE" 2>&1 |
|
check_status "upgrade pip" |
|
|
|
|
|
log "Uninstalling conflicting packages..." |
|
$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 |
|
check_status "uninstall conflicting packages" |
|
|
|
|
|
log "Installing dependencies..." |
|
$PIP install torch==2.1.0+cu121 torchaudio==2.1.0+cu121 --index-url https://download.pytorch.org/whl/cu121 >> "$LOG_FILE" 2>&1 |
|
check_status "install torch and torchaudio" |
|
$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 |
|
check_status "install remaining dependencies" |
|
|
|
|
|
log "Verifying installed packages..." |
|
$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" |
|
check_status "list installed packages" |
|
|
|
|
|
log "Verifying CUDA and torch..." |
|
$PYTHON -c "import torch; print(torch.__version__, torch.cuda.is_available(), torch.version.cuda)" >> "$LOG_FILE" 2>&1 |
|
check_status "verify CUDA and torch" |
|
|
|
|
|
log "Testing imports..." |
|
$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 |
|
check_status "test imports" |
|
|
|
|
|
log "Checking for dependency conflicts with pipdeptree..." |
|
$PIP install pipdeptree >> "$LOG_FILE" 2>&1 |
|
check_status "install pipdeptree" |
|
$PYTHON -m pipdeptree > "$HOME/ghostai_music_generator/pipdeptree_output.txt" 2>> "$LOG_FILE" |
|
check_status "run pipdeptree" |
|
|
|
|
|
log "Cleaning up unnecessary packages..." |
|
$PIP uninstall -y stable-audio-tools laion-clap x-transformers accelerate dctorch torchdata torchtext torchvision >> "$LOG_FILE" 2>&1 || true |
|
|
|
|
|
log "Final verification of installed packages..." |
|
EXPECTED_PACKAGES=( |
|
"audiocraft==1.3.0" |
|
"gradio==3.50.2" |
|
"networkx==2.8.8" |
|
"numpy==1.26.4" |
|
"pydantic==1.10.13" |
|
"pydub==0.25.1" |
|
"requests==2.31.0" |
|
"spacy==3.7.2" |
|
"torch==2.1.0+cu121" |
|
"torchaudio==2.1.0+cu121" |
|
"transformers==4.40.2" |
|
"typer==0.7.0" |
|
) |
|
for pkg in "${EXPECTED_PACKAGES[@]}"; do |
|
if $PIP list | grep -q "$pkg"; then |
|
log "$pkg verified" |
|
else |
|
log "ERROR: $pkg not found" |
|
exit 1 |
|
fi |
|
done |
|
|
|
log "MusicGen environment setup completed successfully" |
|
log "Virtual environment: $VENV_DIR" |
|
log "Log file: $LOG_FILE" |
|
log "Verified packages: $HOME/ghostai_music_generator/verified_packages.txt" |
|
log "Dependency tree: $HOME/ghostai_music_generator/pipdeptree_output.txt" |
|
log "To activate: source $VENV_DIR/bin/activate" |
|
log "To run script: python musicgen_optimized.py" |
|
|
|
exit 0 |