2024-06-30 22:06:23 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Function to check if PyTorch is installed
|
|
|
|
check_pytorch_installed() {
|
|
|
|
python -c "import torch" >/dev/null 2>&1
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function to create virtual environment
|
|
|
|
create_venv() {
|
|
|
|
if [ -d "venv" ]; then
|
|
|
|
echo "Virtual environment already exists. Skipping creation."
|
|
|
|
source venv/bin/activate
|
|
|
|
else
|
|
|
|
echo "Creating virtual environment..."
|
|
|
|
python3.10 -m venv --system-site-packages venv
|
|
|
|
source venv/bin/activate
|
|
|
|
python3.10 -m pip install --upgrade pip
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
use_venv() {
|
|
|
|
echo "Connecting to virtual environment..."
|
|
|
|
source venv/bin/activate
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function to install build-essential or equivalent
|
|
|
|
install_build_essentials() {
|
|
|
|
echo "Checking for build essentials..."
|
2024-08-10 21:27:45 +02:00
|
|
|
|
2024-06-30 22:06:23 +02:00
|
|
|
if [ -f /etc/debian_version ]; then
|
|
|
|
sudo apt-get update
|
|
|
|
sudo apt-get install -y build-essential python3.10-dev
|
2024-08-10 21:27:45 +02:00
|
|
|
|
2024-06-30 22:06:23 +02:00
|
|
|
elif [ -f /etc/fedora-release ]; then
|
2024-08-10 21:27:45 +02:00
|
|
|
if rpm -q gcc &>/dev/null && rpm -q python3.10-devel &>/dev/null; then
|
|
|
|
echo "Development Tools and Python 3.10 development files are already installed."
|
2024-06-30 22:06:23 +02:00
|
|
|
else
|
2024-08-10 21:27:45 +02:00
|
|
|
echo "Installing Development Tools and Python 3.10 development files..."
|
2024-06-30 22:06:23 +02:00
|
|
|
sudo dnf groupinstall -y "Development Tools"
|
2024-08-10 21:27:45 +02:00
|
|
|
sudo dnf install -y python3.10-devel
|
2024-06-30 22:06:23 +02:00
|
|
|
fi
|
2024-08-10 21:27:45 +02:00
|
|
|
|
2024-06-30 22:06:23 +02:00
|
|
|
else
|
|
|
|
echo "Unsupported operating system. Please install build-essential or equivalent manually."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function to install PyTorch in the virtual environment
|
|
|
|
install_pytorch() {
|
|
|
|
# Check if PyTorch is installed
|
|
|
|
if check_pytorch_installed; then
|
|
|
|
echo "PyTorch is already installed."
|
|
|
|
else
|
|
|
|
echo "Installing PyTorch..."
|
|
|
|
python3.10 -m pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm6.1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
prepare_env(){
|
|
|
|
# Create virtual environment
|
|
|
|
create_venv
|
|
|
|
|
|
|
|
# Install build essentials
|
|
|
|
install_build_essentials
|
|
|
|
|
|
|
|
# Install PyTorch in the virtual environment
|
|
|
|
install_pytorch
|
|
|
|
}
|
|
|
|
|
|
|
|
clean() {
|
|
|
|
python3.10 -m pip cache purge
|
2024-08-10 21:27:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
yes_or_no() {
|
|
|
|
while true; do
|
|
|
|
read -p "$* [y/n]: " yn
|
|
|
|
case $yn in
|
|
|
|
[Yy]*) return 0 ;;
|
|
|
|
[Nn]*) echo "Aborted" ; return 1 ;;
|
|
|
|
esac
|
|
|
|
done
|
2024-06-30 22:06:23 +02:00
|
|
|
}
|