-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-dev.sh
More file actions
executable file
·131 lines (109 loc) · 4.75 KB
/
start-dev.sh
File metadata and controls
executable file
·131 lines (109 loc) · 4.75 KB
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
#!/bin/bash
# Note: This script is designed for Linux/WSL2 environments. Its purpose is to pre-load 2 local models so they are 'warm' and ready to use without the user having to wait for models to load every time a model runs.
# Windows users should use WSL2 or adapt for PowerShell
# Make start-dev.sh executable (one-time)
# chmod +x start-dev.sh
# to run in terminal: ./start-dev.sh
# Step 1: Start Ollama and DB
docker compose up -d ollama db
# Step 2: Wait for Ollama
until docker compose exec ollama ollama list &>/dev/null; do
echo "Waiting for Ollama..."
sleep 5
done
echo "Ollama ready!"
# Step 3: Check for models (informational only - no auto-pulling)
echo "Checking available models from your Ollama installation:"
docker compose exec ollama ollama list
# Optional: Uncomment any of these sections if you need to pull models
# # Arctic Text2SQL model (uncomment if needed)
# if ! docker compose exec ollama ollama list | grep -q "arctic-text2sql:latest"; then
# echo "Pulling Arctic model..."
# docker compose exec ollama ollama pull hf.co/mradermacher/Arctic-Text2SQL-R1-7B-GGUF:Q4_K_M
# docker compose exec ollama ollama cp hf.co/mradermacher/Arctic-Text2SQL-R1-7B-GGUF:Q4_K_M arctic-text2sql:latest
# echo "Arctic model pulled"
# fi
# # Distil-Qwen3 Text2SQL model (uncomment if needed)
# if ! docker compose exec ollama ollama list | grep -q "distil-qwen3-4b:latest"; then
# echo "Pulling Distil-Qwen3 model..."
# docker compose exec ollama ollama pull hf.co/distil-labs/distil-qwen3-4b-text2sql-gguf-4bit
# docker compose exec ollama ollama cp hf.co/distil-labs/distil-qwen3-4b-text2sql-gguf-4bit distil-qwen3-4b:latest
# echo "Distil-Qwen3 model pulled"
# fi
# # Qwen2.5-Coder-7B SQL generator model (uncomment if needed)
# if ! docker compose exec ollama ollama list | grep -q "qwen2.5-coder-7b:latest"; then
# echo "Pulling Qwen2.5-Coder-7B model from Hugging Face..."
# docker compose exec ollama ollama pull hf.co/bartowski/Qwen2.5-Coder-7B-Instruct-GGUF:Q4_K_M
# # Optional: create a shorter name for convenience
# docker compose exec ollama ollama cp hf.co/bartowski/Qwen2.5-Coder-7B-Instruct-GGUF:Q4_K_M qwen2.5-coder-7b:latest
# echo "Qwen2.5-Coder-7B model pulled and available as 'qwen2.5-coder-7b:latest'"
# fi
# # Qwen2.5-Coder-14B judge model (uncomment if needed)
# if ! docker compose exec ollama ollama list | grep -q "qwen2.5-coder:14b"; then
# echo "Pulling Qwen2.5-Coder-14B model..."
# docker compose exec ollama ollama pull qwen2.5-coder:14b
# echo "Qwen2.5-Coder-14B model pulled"
# fi
# Step 4: Pre-load models into VRAM via API
echo "Pre-loading models into VRAM via API..."
# Function to trigger model load
load_model() {
local model_name=$1
echo "Loading ${model_name}..."
curl -s -X POST http://localhost:11434/api/generate \
-H "Content-Type: application/json" \
-d "{
\"model\": \"${model_name}\",
\"prompt\": \"\",
\"stream\": false,
\"options\": {\"num_predict\": 1}
}" > /dev/null
if [ $? -eq 0 ]; then
echo "${model_name} load triggered."
else
echo "Failed to trigger load for ${model_name}. It will load on first use."
fi
}
# Function to warm up model with a real request
warmup_model() {
local model_name=$1
echo "Warming up ${model_name} with test request..."
curl -s -X POST http://localhost:11434/v1/chat/completions \
-H "Content-Type: application/json" \
-d "{
\"model\": \"${model_name}\",
\"messages\": [{\"role\": \"user\", \"content\": \"Say hello\"}],
\"max_tokens\": 10,
\"temperature\": 0.1
}" > /dev/null
if [ $? -eq 0 ]; then
echo "${model_name} warm-up complete."
else
echo "Warning: ${model_name} warm-up failed, but model may still work."
fi
}
# Read models from .env (ignoring commented lines)
TEXT2SQL_MODEL=$(grep -v '^#' .env | grep TEXT2SQL_MODEL | cut -d '=' -f2)
JUDGE_MODEL=$(grep -v '^#' .env | grep JUDGE_MODEL | cut -d '=' -f2)
if [ -z "$TEXT2SQL_MODEL" ] || [ -z "$JUDGE_MODEL" ]; then
echo "Error: TEXT2SQL_MODEL or JUDGE_MODEL not found in .env file"
exit 1
fi
# Load ONLY 2 models total (one SQL generator + one AI response generator / judge model).
echo "Loading SQL generator model..."
load_model "$TEXT2SQL_MODEL"
echo "Loading AI response/judge model..."
load_model "$JUDGE_MODEL"
echo "Waiting for models to fully initialize in VRAM..."
sleep 10
# Step 5: Warm up models with actual requests
echo "Warming up models to prevent first-request truncation..."
warmup_model "$TEXT2SQL_MODEL"
warmup_model "$JUDGE_MODEL"
# Step 6: Verify VRAM usage
echo "Current VRAM usage:"
docker compose exec ollama nvidia-smi | grep "MiB /" | head -1
# Step 7: Start the backend (without --watch flag)
echo "Starting backend services..."
docker compose up -d
echo "Setup complete! Models are loaded and warmed up."