Skip to content

Commit 0abfbdd

Browse files
committed
Runpodskript überarbeitet - Ollama überarbeitet
1 parent 219f4a0 commit 0abfbdd

File tree

1 file changed

+117
-44
lines changed

1 file changed

+117
-44
lines changed

setup_runpod_direct.sh

Lines changed: 117 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/bash
22

33
# ============================================
4-
# OpenTuneWeaver RunPod Setup (CPU-Build Fix)
5-
# Version: 2.2
4+
# OpenTuneWeaver RunPod Setup (Ollama-Fix + Gemma3)
5+
# Version: 2.3
66
# ============================================
77

88
set -e # Exit on error
@@ -33,7 +33,7 @@ warning() {
3333
# ============================================
3434

3535
log "${BLUE}========================================${NC}"
36-
log "${BLUE}🚀 OpenTuneWeaver RunPod Installation v2.2${NC}"
36+
log "${BLUE}🚀 OpenTuneWeaver RunPod Installation v2.3${NC}"
3737
log "${BLUE}========================================${NC}"
3838

3939
# System Info
@@ -219,42 +219,61 @@ log "${BLUE}🦙 Installing Ollama...${NC}"
219219
# Install Ollama
220220
curl -fsSL https://ollama.com/install.sh | sh
221221

222-
# Start Ollama in background
222+
# Kill any existing Ollama processes
223+
pkill ollama 2>/dev/null || true
224+
sleep 2
225+
226+
# Start Ollama in background with robust startup
223227
log "Starting Ollama service..."
224-
nohup ollama serve > /workspace/ollama.log 2>&1 &
228+
ollama serve > /workspace/ollama.log 2>&1 &
225229
OLLAMA_PID=$!
226230
echo $OLLAMA_PID > /workspace/ollama.pid
227231

228-
# Wait for Ollama to start
229-
sleep 10
230-
231-
# Check if Ollama is running
232-
if curl -s http://localhost:11434/api/tags > /dev/null 2>&1; then
233-
log "✅ Ollama is running successfully"
234-
else
235-
warning "Ollama might not be running properly, check /workspace/ollama.log"
236-
fi
232+
# Wait for Ollama to start with proper verification
233+
log "Waiting for Ollama to become ready..."
234+
for i in {1..60}; do
235+
if curl -s http://localhost:11434/api/tags > /dev/null 2>&1; then
236+
log "✅ Ollama is running successfully on port 11434"
237+
break
238+
else
239+
if [ $i -eq 60 ]; then
240+
error "Ollama failed to start after 60 attempts"
241+
fi
242+
echo " Waiting for Ollama... ($i/60)"
243+
sleep 2
244+
fi
245+
done
237246

238247
# ============================================
239248
# SCHRITT 9: Download Ollama Models
240249
# ============================================
241250

242-
log "${BLUE}📥 Downloading Ollama models...${NC}"
251+
log "${BLUE}📥 Downloading Ollama models (this will take a while)...${NC}"
243252

244-
# Download a lightweight model for testing
245-
ollama pull llama3.2:3b || warning "Failed to pull model - will retry later"
253+
# Download the desired larger model
254+
log "Downloading gemma3:12b-it-qat (this may take 10-15 minutes)..."
255+
if ollama pull gemma3:12b-it-qat; then
256+
log "✅ gemma3:12b-it-qat downloaded successfully"
257+
export OLLAMA_MODEL="gemma3:12b-it-qat"
258+
else
259+
warning "Failed to download gemma3:12b-it-qat, falling back to llama3.2:3b"
260+
ollama pull llama3.2:3b
261+
export OLLAMA_MODEL="llama3.2:3b"
262+
fi
246263

247-
log "✅ Models downloaded"
264+
# Verify model is available
265+
log "Available models:"
266+
ollama list
248267

249268
# ============================================
250269
# SCHRITT 10: Create Pipeline Configuration
251270
# ============================================
252271

253272
log "${BLUE}📝 Creating pipeline configuration...${NC}"
254273

255-
cat > /workspace/OpenTuneWeaver/pipeline/pipeline_config.json << 'EOF'
274+
cat > /workspace/OpenTuneWeaver/pipeline/pipeline_config.json << EOF
256275
{
257-
"version": "2.2-runpod",
276+
"version": "2.3-runpod",
258277
"created": "$(date -Iseconds)",
259278
"tokens": {
260279
"hf_token": "",
@@ -265,28 +284,28 @@ cat > /workspace/OpenTuneWeaver/pipeline/pipeline_config.json << 'EOF'
265284
"use_openai_api": true,
266285
"openai_base_url": "http://localhost:11434/v1",
267286
"openai_api_key": "ollama",
268-
"openai_model_name": "llama3.2:3b",
287+
"openai_model_name": "${OLLAMA_MODEL:-gemma3:12b-it-qat}",
269288
"temperature": 0.1
270289
},
271290
"02_genwiki": {
272291
"use_openai_api": true,
273292
"openai_base_url": "http://localhost:11434/v1",
274293
"openai_api_key": "ollama",
275-
"openai_model_name": "llama3.2:3b",
294+
"openai_model_name": "${OLLAMA_MODEL:-gemma3:12b-it-qat}",
276295
"temperature": 0.3
277296
},
278297
"03_instructQA": {
279298
"use_openai_api": true,
280299
"openai_base_url": "http://localhost:11434/v1",
281300
"openai_api_key": "ollama",
282-
"openai_model_name": "llama3.2:3b",
301+
"openai_model_name": "${OLLAMA_MODEL:-gemma3:12b-it-qat}",
283302
"temperature": 0.7
284303
},
285304
"05_bmcreator": {
286305
"use_openai_api": true,
287306
"openai_base_url": "http://localhost:11434/v1",
288307
"openai_api_key": "ollama",
289-
"openai_model_name": "llama3.2:3b",
308+
"openai_model_name": "${OLLAMA_MODEL:-gemma3:12b-it-qat}",
290309
"temperature": 0.5
291310
}
292311
},
@@ -318,7 +337,7 @@ cat > /workspace/OpenTuneWeaver/pipeline/pipeline_config.json << 'EOF'
318337
"type": "api",
319338
"api_base_url": "http://localhost:11434/v1",
320339
"api_key": "ollama",
321-
"model": "llama3.2:3b"
340+
"model": "${OLLAMA_MODEL:-gemma3:12b-it-qat}"
322341
}
323342
},
324343
"pipeline": {
@@ -329,7 +348,7 @@ cat > /workspace/OpenTuneWeaver/pipeline/pipeline_config.json << 'EOF'
329348
}
330349
EOF
331350

332-
log "✅ Configuration created"
351+
log "✅ Configuration created with model: ${OLLAMA_MODEL:-gemma3:12b-it-qat}"
333352

334353
# ============================================
335354
# SCHRITT 11: Create Directory Structure
@@ -358,25 +377,53 @@ log "✅ Directory structure created"
358377

359378
log "${BLUE}📝 Creating startup scripts...${NC}"
360379

361-
# Main startup script
380+
# Improved startup script with robust Ollama handling
362381
cat > /workspace/start_otw.sh << 'EOF'
363382
#!/bin/bash
364383
365384
echo "🚀 Starting OpenTuneWeaver..."
366385
367-
# Start Ollama if not running
368-
if ! pgrep -x "ollama" > /dev/null; then
369-
echo "Starting Ollama..."
370-
nohup ollama serve > /workspace/ollama.log 2>&1 &
371-
sleep 10
372-
fi
386+
# Function to check if Ollama is responding
387+
check_ollama() {
388+
curl -s http://localhost:11434/api/tags > /dev/null 2>&1
389+
}
373390
374-
# Check Ollama status
375-
if curl -s http://localhost:11434/api/tags > /dev/null; then
376-
echo "✅ Ollama is running"
391+
# Kill existing Ollama processes
392+
pkill ollama 2>/dev/null || true
393+
sleep 3
394+
395+
# Start Ollama
396+
echo "Starting Ollama..."
397+
ollama serve > /workspace/ollama.log 2>&1 &
398+
OLLAMA_PID=$!
399+
echo $OLLAMA_PID > /workspace/ollama.pid
400+
401+
# Wait for Ollama to be ready
402+
echo "Waiting for Ollama to become ready..."
403+
for i in {1..30}; do
404+
if check_ollama; then
405+
echo "✅ Ollama is running and responding"
406+
break
407+
else
408+
if [ $i -eq 30 ]; then
409+
echo "❌ Ollama failed to start properly"
410+
echo "Check logs: tail -f /workspace/ollama.log"
411+
exit 1
412+
fi
413+
echo "Waiting... ($i/30)"
414+
sleep 2
415+
fi
416+
done
417+
418+
# Verify model is available
419+
echo "Verifying models..."
420+
if ollama list | grep -q "gemma3:12b-it-qat"; then
421+
echo "✅ gemma3:12b-it-qat is available"
422+
elif ollama list | grep -q "llama3.2:3b"; then
423+
echo "✅ llama3.2:3b is available"
377424
else
378-
echo "❌ Ollama is not responding"
379-
echo "Check logs: tail -f /workspace/ollama.log"
425+
echo "⚠️ No models found, downloading fallback model..."
426+
ollama pull llama3.2:3b
380427
fi
381428
382429
# Start OpenTuneWeaver UI
@@ -387,7 +434,7 @@ EOF
387434

388435
chmod +x /workspace/start_otw.sh
389436

390-
# Debug script
437+
# Enhanced debug script
391438
cat > /workspace/debug_otw.sh << 'EOF'
392439
#!/bin/bash
393440
@@ -401,16 +448,34 @@ echo -e "\nPython packages:"
401448
pip3 list | grep -E "(torch|transformers|gradio|unsloth)"
402449
403450
echo -e "\nOllama status:"
404-
curl -s http://localhost:11434/api/tags 2>/dev/null || echo "Ollama not responding"
451+
if curl -s http://localhost:11434/api/tags 2>/dev/null; then
452+
echo "✅ Ollama is responding"
453+
echo "Available models:"
454+
ollama list
455+
else
456+
echo "❌ Ollama not responding"
457+
fi
458+
459+
echo -e "\nOllama processes:"
460+
ps aux | grep ollama | grep -v grep
461+
462+
echo -e "\nOllama logs (last 20 lines):"
463+
tail -20 /workspace/ollama.log 2>/dev/null || echo "No Ollama logs found"
405464
406465
echo -e "\nGPU status:"
407466
nvidia-smi 2>/dev/null || echo "No GPU available"
408467
468+
echo -e "\nPort 11434 status:"
469+
ss -tlnp | grep 11434 || echo "Port 11434 not listening"
470+
409471
echo -e "\nProcess status:"
410472
ps aux | grep -E "(ollama|python)" | head -10
411473
412474
echo -e "\nllama.cpp build status:"
413475
ls -la /workspace/OpenTuneWeaver/pipeline/modules/06_finetuning/llama.cpp/build/bin/ 2>/dev/null || echo "llama.cpp not built"
476+
477+
echo -e "\nConfiguration model:"
478+
grep "openai_model_name" /workspace/OpenTuneWeaver/pipeline/pipeline_config.json 2>/dev/null || echo "No config found"
414479
EOF
415480

416481
chmod +x /workspace/debug_otw.sh
@@ -449,6 +514,8 @@ except ImportError as e:
449514
# Test Ollama connection
450515
if curl -s http://localhost:11434/api/tags > /dev/null; then
451516
log "✅ Ollama connection test passed"
517+
echo "Available models:"
518+
ollama list
452519
else
453520
warning "Ollama connection test failed"
454521
fi
@@ -483,10 +550,16 @@ echo " Configuration: /workspace/OpenTuneWeaver/pipeline/pipeline_config
483550
echo " Logs: /workspace/ollama.log"
484551
echo " llama.cpp binary: /workspace/OpenTuneWeaver/pipeline/modules/06_finetuning/llama.cpp/build/bin/"
485552
echo ""
486-
echo "ℹ️ Build Info:"
487-
echo " llama.cpp: CPU-only build (stable and reliable)"
488-
echo " PyTorch: GPU-accelerated (if CUDA available)"
489-
echo " Ollama: GPU-accelerated (if CUDA available)"
553+
echo "🤖 Model Information:"
554+
echo " Primary model: ${OLLAMA_MODEL:-gemma3:12b-it-qat}"
555+
echo " llama.cpp build: CPU-only (stable and reliable)"
556+
echo " PyTorch: GPU-accelerated (if CUDA available)"
557+
echo " Ollama: GPU-accelerated (if CUDA available)"
558+
echo ""
559+
echo "💡 Notes:"
560+
echo " - gemma3:12b-it-qat is a larger, more capable model (~24GB download)"
561+
echo " - If download fails, system falls back to llama3.2:3b"
562+
echo " - Ollama startup is now more robust with proper waiting"
490563
echo ""
491564

492565
# Optional: Auto-start

0 commit comments

Comments
 (0)