100enigma commited on
Commit
a5ecaa8
·
1 Parent(s): a3ebd21

add: droplet setup script

Browse files
Files changed (1) hide show
  1. setup.sh +182 -0
setup.sh ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # setup.sh — SimQuantum MI300X one-time setup
3
+ # Run this ONCE on a fresh droplet.
4
+ # After this, use start.sh every time.
5
+ set -e
6
+
7
+ CONDA_ENV="qdots"
8
+ MODEL="Qwen/Qwen2.5-1.5B-Instruct"
9
+ REPO_URL="https://huggingface.co/spaces/lablab-ai-amd-developer-hackathon/simquantum-tuning-lab"
10
+ REPO_DIR="/root/simquantum-tuning-lab"
11
+
12
+ echo ""
13
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
14
+ echo " SimQuantum — One-Time Droplet Setup"
15
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
16
+ echo ""
17
+
18
+ # ── 1. Clone repo ─────────────────────────────────────────────────────────────
19
+ if [ -d "$REPO_DIR/.git" ]; then
20
+ echo "► Repo already exists — pulling latest..."
21
+ cd "$REPO_DIR"
22
+ git pull origin main
23
+ else
24
+ echo "► Cloning SimQuantum from HuggingFace..."
25
+ git clone "$REPO_URL" "$REPO_DIR"
26
+ cd "$REPO_DIR"
27
+ fi
28
+ echo " ✓ Repo ready at $REPO_DIR"
29
+
30
+ # ── 2. Conda init ─────────────────────────────────────────────────────────────
31
+ echo "► Initializing conda..."
32
+ source /root/miniconda3/etc/profile.d/conda.sh
33
+
34
+ # ── 3. Create env if it doesn't exist ────────────────────────────────────────
35
+ if conda env list | grep -q "^${CONDA_ENV} "; then
36
+ echo " ✓ Conda env '$CONDA_ENV' already exists"
37
+ else
38
+ echo "► Creating conda env '$CONDA_ENV' (Python 3.11)..."
39
+ conda create -y -n "$CONDA_ENV" python=3.11
40
+ echo " ✓ Created"
41
+ fi
42
+ conda activate "$CONDA_ENV"
43
+ echo " ✓ Python: $(python --version)"
44
+
45
+ # ── 4. ROCm PyTorch ───────────────────────────────────────────────────────────
46
+ if python -c "import torch; assert torch.cuda.is_available()" 2>/dev/null; then
47
+ echo " ✓ ROCm PyTorch already installed"
48
+ else
49
+ echo "► Installing ROCm PyTorch (this takes a few minutes)..."
50
+ pip install torch torchvision \
51
+ --index-url https://download.pytorch.org/whl/rocm6.2 \
52
+ --quiet
53
+ echo " ✓ Done"
54
+ fi
55
+
56
+ # ── 5. vLLM ───────────────────────────────────────────────────────────────────
57
+ if python -c "import vllm" 2>/dev/null; then
58
+ echo " ✓ vLLM already installed"
59
+ else
60
+ echo "► Installing vLLM..."
61
+ pip install vllm --quiet
62
+ echo " ✓ Done"
63
+ fi
64
+
65
+ # ── 6. App dependencies ───────────────────────────────────────────────────────
66
+ echo "► Installing app dependencies..."
67
+ pip install streamlit==1.57.0 plotly openai numpy scipy scikit-learn tqdm --quiet
68
+ pip install -e . --quiet
69
+ echo " ✓ Done"
70
+
71
+ # ── 7. Pre-download the model weights ────────────────────────────────────────
72
+ # Do this now so start.sh doesn't spend credits downloading later
73
+ echo "► Pre-downloading $MODEL weights (one-time, ~3GB)..."
74
+ python -c "
75
+ from huggingface_hub import snapshot_download
76
+ snapshot_download('$MODEL')
77
+ print(' ✓ Model weights cached')
78
+ "
79
+
80
+ # ── 8. Write start.sh into the repo dir so it's always there ─────────────────
81
+ cat > "$REPO_DIR/start.sh" << 'STARTSCRIPT'
82
+ #!/bin/bash
83
+ # start.sh — run this every time you boot the droplet
84
+ CONDA_ENV="qdots"
85
+ MODEL="Qwen/Qwen2.5-1.5B-Instruct"
86
+ VLLM_PORT=8000
87
+ STREAMLIT_PORT=8501
88
+ REPO_DIR="/root/simquantum-tuning-lab"
89
+
90
+ echo ""
91
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
92
+ echo " SimQuantum — Starting Up"
93
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
94
+
95
+ cd "$REPO_DIR"
96
+
97
+ # Pull latest code (cheap, always do it)
98
+ git pull origin main --quiet && echo "► Code up to date ✓" || echo "► (git pull skipped)"
99
+
100
+ # Init conda
101
+ source /root/miniconda3/etc/profile.d/conda.sh
102
+ conda activate "$CONDA_ENV"
103
+
104
+ PYTHON="$(which python)"
105
+ VLLM_BIN="$(which vllm)"
106
+
107
+ # ── Start vLLM if not running ─────────────────────────────────────────────────
108
+ if curl -s http://localhost:$VLLM_PORT/v1/models > /dev/null 2>&1; then
109
+ echo "► vLLM already running ✓"
110
+ else
111
+ echo "► Starting vLLM (Qwen2.5-1.5B on MI300X)..."
112
+ export HIP_VISIBLE_DEVICES=0
113
+ export ROCR_VISIBLE_DEVICES=0
114
+ export VLLM_TARGET_DEVICE=rocm
115
+ export HSA_OVERRIDE_GFX_VERSION=9.4.2
116
+
117
+ nohup "$VLLM_BIN" serve "$MODEL" \
118
+ --host 0.0.0.0 \
119
+ --port $VLLM_PORT \
120
+ --gpu-memory-utilization 0.45 \
121
+ --max-model-len 4096 \
122
+ > /tmp/vllm.log 2>&1 &
123
+ VLLM_PID=$!
124
+
125
+ echo -n " Waiting for vLLM"
126
+ for i in $(seq 1 120); do
127
+ curl -s http://localhost:$VLLM_PORT/v1/models > /dev/null 2>&1 && echo " ✓" && break
128
+ if ! kill -0 $VLLM_PID 2>/dev/null; then
129
+ echo ""
130
+ echo " ✗ vLLM crashed. Last 20 lines:"
131
+ tail -20 /tmp/vllm.log
132
+ exit 1
133
+ fi
134
+ printf "."; sleep 1
135
+ done
136
+ fi
137
+
138
+ # ── Kill old Streamlit only ───────────────────────────────────────────────────
139
+ pkill -f "streamlit run" 2>/dev/null || true
140
+ sleep 1
141
+
142
+ # ── Start Streamlit ───────────────────────────────────────────────────────────
143
+ echo "► Starting Streamlit..."
144
+ export QDOT_LLM_BASE_URL="http://localhost:${VLLM_PORT}/v1"
145
+ export QDOT_LLM_MODEL="$MODEL"
146
+
147
+ nohup "$PYTHON" -m streamlit run app.py \
148
+ --server.port "$STREAMLIT_PORT" \
149
+ --server.address 0.0.0.0 \
150
+ --server.headless true \
151
+ > /tmp/streamlit.log 2>&1 &
152
+
153
+ echo -n " Waiting for Streamlit"
154
+ for i in $(seq 1 30); do
155
+ curl -s http://localhost:$STREAMLIT_PORT > /dev/null 2>&1 && echo " ✓" && break
156
+ printf "."; sleep 1
157
+ done
158
+
159
+ PUBLIC_IP=$(curl -s ifconfig.me 2>/dev/null || echo "YOUR_IP")
160
+ echo ""
161
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
162
+ echo " ✓ SimQuantum is live!"
163
+ echo ""
164
+ echo " Open this in your browser:"
165
+ echo " http://${PUBLIC_IP}:${STREAMLIT_PORT}"
166
+ echo ""
167
+ echo " If something looks wrong:"
168
+ echo " tail -f /tmp/vllm.log"
169
+ echo " tail -f /tmp/streamlit.log"
170
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
171
+ STARTSCRIPT
172
+
173
+ chmod +x "$REPO_DIR/start.sh"
174
+
175
+ echo ""
176
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
177
+ echo " ✓ Setup complete!"
178
+ echo ""
179
+ echo " From now on, just run:"
180
+ echo " cd /root/simquantum-tuning-lab"
181
+ echo " bash start.sh"
182
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"