pfox1995 commited on
Commit
c88952c
Β·
verified Β·
1 Parent(s): efb4788

Add restart_server.sh (server.py + restart_server.sh + Korean README expansion)

Browse files
Files changed (1) hide show
  1. restart_server.sh +90 -0
restart_server.sh ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # One-shot rehydrate + relaunch for the Korean pest-detector server.
3
+ # Idempotent: skips installs if the packages are already importable.
4
+ # Run this after any pod restart (which wipes the container disk).
5
+ #
6
+ # Usage: bash /workspace/restart_server.sh
7
+ set -uo pipefail
8
+
9
+ PORT="${PORT:-8080}"
10
+ ADAPTER="${ADAPTER:-pfox1995/pest-detector-deploy}"
11
+ LOAD_IN_4BIT="${LOAD_IN_4BIT:-true}"
12
+ # RunPod auto-sets RUNPOD_POD_ID β€” derive proxy URL from it. Override with PUBLIC_URL=...
13
+ PUBLIC_URL="${PUBLIC_URL:-https://${RUNPOD_POD_ID:-YOUR_POD_ID}-${PORT}.proxy.runpod.net}"
14
+
15
+ cd /workspace
16
+ mkdir -p /workspace/.tmp /workspace/.pip-cache
17
+ export TMPDIR=/workspace/.tmp
18
+
19
+ step() { echo; echo "=== $* ==="; }
20
+
21
+ # ───────── Stage 1: stack ─────────
22
+ step "1/3 Python stack"
23
+ need_stack=0
24
+ python3 -c "import unsloth, peft, fastapi, uvicorn, bitsandbytes, fla" 2>/dev/null || need_stack=1
25
+
26
+ if [ $need_stack -eq 1 ]; then
27
+ echo " installing unsloth + transformers + peft + fastapi + bnb + fla"
28
+ pip install --break-system-packages --cache-dir=/workspace/.pip-cache \
29
+ 'unsloth[cu128-torch280]' 'transformers>=5.2,<6.0' 'peft==0.19.1' \
30
+ fastapi uvicorn python-multipart bitsandbytes flash-linear-attention \
31
+ 2>&1 | tail -3
32
+ else
33
+ echo " βœ“ already installed"
34
+ fi
35
+
36
+ # ───────── Stage 2: causal_conv1d (prebuilt wheel β€” skip the 9-arch CUDA build) ─────────
37
+ step "2/3 causal_conv1d fast-path lib"
38
+ if python3 -c "import causal_conv1d" 2>/dev/null; then
39
+ echo " βœ“ already installed: $(python3 -c 'import causal_conv1d; print(causal_conv1d.__version__)')"
40
+ else
41
+ echo " installing prebuilt wheel for torch 2.8 + cu12 + py312"
42
+ pip install --break-system-packages \
43
+ 'https://github.com/Dao-AILab/causal-conv1d/releases/download/v1.6.1.post4/causal_conv1d-1.6.1%2Bcu12torch2.8cxx11abiTRUE-cp312-cp312-linux_x86_64.whl' \
44
+ 2>&1 | tail -3
45
+ python3 -c "import causal_conv1d; print(' βœ“ ccc', causal_conv1d.__version__)"
46
+ fi
47
+
48
+ # ───────── Stage 3: launch server in tmux ─────────
49
+ step "3/3 launch server in tmux 'pest' on :$PORT"
50
+ tmux kill-session -t pest 2>/dev/null || true
51
+ sleep 1
52
+
53
+ tmux new-session -d -s pest "
54
+ export HF_TOKEN=\$(cat /workspace/.cache/huggingface/token)
55
+ export HF_HOME=/workspace/.cache/huggingface
56
+ export ADAPTER='$ADAPTER'
57
+ export LOAD_IN_4BIT='$LOAD_IN_4BIT'
58
+ export PORT='$PORT'
59
+ python3 -u /workspace/deploy/server.py 2>&1 | tee /workspace/pest_server.log
60
+ exec bash
61
+ "
62
+
63
+ echo
64
+ echo " waiting for /health (Unsloth load + LoRA attach takes ~90s)..."
65
+ ready_after=""
66
+ for i in $(seq 1 90); do
67
+ if curl -sf -m 2 "http://localhost:$PORT/health" >/dev/null 2>&1; then
68
+ ready_after="$((i*2))"
69
+ break
70
+ fi
71
+ sleep 2
72
+ done
73
+
74
+ if [ -z "$ready_after" ]; then
75
+ echo " βœ— server did not come up within 180s. Check:"
76
+ echo " tmux capture-pane -t pest -p | tail -30"
77
+ echo " tail -40 /workspace/pest_server.log"
78
+ exit 1
79
+ fi
80
+
81
+ echo " βœ“ ready after ${ready_after}s"
82
+ echo
83
+ echo "════════════════════════════════════════════════════════════"
84
+ echo " βœ“ pest detector server is live"
85
+ echo " Local: http://localhost:$PORT"
86
+ echo " Public: $PUBLIC_URL"
87
+ echo " VRAM: $(nvidia-smi --query-gpu=memory.used,memory.total --format=csv,noheader,nounits | awk -F',' '{printf "%.1f / %.1f GB\n", $1/1024, $2/1024}')"
88
+ echo " Logs: tail -f /workspace/pest_server.log"
89
+ echo " Stop: tmux kill-session -t pest"
90
+ echo "════════════════════════════════════════════════════════════"