-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.sh
executable file
·157 lines (137 loc) · 5.4 KB
/
setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash
# This script sets up the project by installing dependencies, checking for a poetry environment,
# and installing pre-commit hooks.
# Add color and formatting variables at the top
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
BOLD='\033[1m'
# Initialize error tracking
ERRORS_FOUND=0
# Function for section headers
print_section() {
echo -e "\n${BOLD}${BLUE}=== $1 ===${NC}\n"
}
# Function for success messages
print_success() {
echo -e "${GREEN}✓ $1${NC}"
}
# Function for warnings
print_warning() {
echo -e "${YELLOW}⚠ $1${NC}"
}
# --- GIT LFS SETUP --- #
print_section "Git LFS Setup"
if ! command -v git-lfs &> /dev/null; then
print_warning "git-lfs is not installed. Some model checkpointing functionality may not work correctly."
ERRORS_FOUND=$((ERRORS_FOUND + 1))
# Check the operating system
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
echo -e "${YELLOW} You can install it using Homebrew:${NC}"
echo " brew install git-lfs"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Linux
echo -e "${YELLOW} You can install it using your package manager:${NC}"
if command -v apt-get &> /dev/null; then
# Ubuntu/Debian
echo " curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash"
echo " sudo apt-get install git-lfs"
elif command -v yum &> /dev/null; then
# CentOS/RHEL
echo " curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | sudo bash"
echo " sudo yum install git-lfs"
else
print_warning "Could not detect package manager. Please install git-lfs manually."
fi
else
print_warning "Unsupported operating system. Please install git-lfs manually."
fi
else
git-lfs install
print_success "git-lfs installed and initialized"
fi
# --- CUDA VERSION CHECK --- #
print_section "CUDA Version Check"
if command -v nvidia-smi &> /dev/null; then
CUDA_VERSION=$(nvidia-smi | sed -n 's/.*CUDA Version: \([0-9.]*\).*/\1/p')
if [[ -z "$CUDA_VERSION" ]]; then
ERRORS_FOUND=$((ERRORS_FOUND + 1))
print_warning "nvidia-smi failed to communicate with the NVIDIA driver."
echo -e "${YELLOW} Ensure that the latest NVIDIA driver is installed and running.${NC}"
else
MAJOR_VERSION=${CUDA_VERSION%.*}
MINOR_VERSION=${CUDA_VERSION#*.}
if [ "$MAJOR_VERSION" -lt 12 ] || ([ "$MAJOR_VERSION" -eq 12 ] && [ "$MINOR_VERSION" -lt 1 ]); then
ERRORS_FOUND=$((ERRORS_FOUND + 1))
print_warning "CUDA version ${MAJOR_VERSION}.${MINOR_VERSION} detected."
echo -e "${YELLOW} Some multi-node communication GPU features may not work properly.${NC}"
echo -e "${YELLOW} CUDA version 12.1 or newer is recommended.${NC}"
else
print_success "CUDA version ${MAJOR_VERSION}.${MINOR_VERSION} detected"
fi
fi
else
ERRORS_FOUND=$((ERRORS_FOUND + 1))
print_warning "nvidia-smi not found. Unable to check CUDA version."
echo -e "${YELLOW} Ensure that NVIDIA drivers and CUDA version at 12.1 or newer are installed for GPU support.${NC}"
fi
# ---- ENVIRONMENT VARIABLES ---- #
print_section "Environment Variables"
if [ -f .env ]; then
print_success "Loading environment variables from .env..."
source .env
if [[ -n "$HF_TOKEN" && -n "$WANDB_API_KEY" ]]; then
print_success "Both HF_TOKEN and WANDB_API_KEY are set and loaded!"
else
print_warning "One or both of HF_TOKEN and WANDB_API_KEY are not set."
fi
else
print_warning "No .env file found."
echo -e "${YELLOW} You might need to create one with HF_TOKEN and WANDB_API_KEY${NC}"
echo -e "${YELLOW} Example .env contents:${NC}"
echo " export HF_TOKEN=your_huggingface_token"
echo " export WANDB_API_KEY=your_wandb_key"
ERRORS_FOUND=$((ERRORS_FOUND + 1))
fi
# ---- POETRY SETUP ---- #
print_section "Poetry Setup"
# First check if Poetry is installed
if ! command -v poetry &> /dev/null; then
echo "Poetry not found. Installing..."
curl -sSL https://install.python-poetry.org | python3 -
print_success "Poetry installed successfully"
else
print_success "Poetry already installed"
fi
# Then check for virtual environment
if [ ! -d ".venv" ]; then
echo "No virtual environment found. Creating one..."
poetry config virtualenvs.in-project true
poetry install --with dev
print_success "Poetry environment created successfully"
else
print_success "Poetry environment already exists"
fi
# ---- PRE-COMMIT SETUP ---- #
print_section "Pre-commit Setup"
# Install pre-commit hooks
echo "Installing pre-commit hooks..."
poetry run pre-commit install
print_success "Pre-commit hooks installed"
# Run pre-commit hooks on all files
echo "Running pre-commit hooks on all files..."
poetry run pre-commit run --all-files
print_success "Pre-commit initial run complete"
# --- Final Status Message --- #
# Final status message
print_section "Setup Status"
if [ $ERRORS_FOUND -eq 0 ]; then
print_success "Setup Complete! 🎉"
print_success "To activate the virtual environment, run: poetry shell"
else
print_warning "Setup completed with warnings! Please check the messages above."
echo -e "${YELLOW} Some features might not work as expected.${NC}"
fi