<# .SYNOPSIS Launch two llama-server processes (base vs tuned) for runtime A/B eval. .EXAMPLE .\pipeline\start_servers.ps1 -BaseGguf .\output\base-Q8_0.gguf -TunedGguf .\output\tuned-Q8_0.gguf .\pipeline\start_servers.ps1 -BaseGguf .\a.gguf -TunedGguf .\b.gguf -PortA 8080 -PortB 8081 #> param( [string]$BaseGguf, [string]$TunedGguf, [int]$PortA = 8080, [int]$PortB = 8081 ) $ErrorActionPreference = 'Stop' function Usage { Write-Host "Usage: .\pipeline\start_servers.ps1 -BaseGguf -TunedGguf [-PortA 8080] [-PortB 8081]" Write-Host "Launches two llama-server processes with --jinja -c 2048 -ngl 0 (CPU-safe)," Write-Host "waits for /health on each, writes PIDs, and prints the two base URLs." } if ([string]::IsNullOrWhiteSpace($BaseGguf) -or [string]::IsNullOrWhiteSpace($TunedGguf)) { Write-Host "ERROR: -BaseGguf and -TunedGguf are both required." -ForegroundColor Red Usage exit 1 } if ($PortA -eq $PortB) { Write-Host "ERROR: -PortA and -PortB must differ." -ForegroundColor Red exit 1 } foreach ($f in @($BaseGguf, $TunedGguf)) { if (-not (Test-Path $f)) { Write-Host "ERROR: GGUF file not found: $f" -ForegroundColor Red Write-Host "Check the path and re-run. (This check runs at launch time only;" Write-Host " the script parses fine without the files existing.)" exit 1 } } $RepoRoot = Split-Path (Split-Path $MyInvocation.MyCommand.Path -Parent) -Parent $Server = Join-Path $RepoRoot 'llama-bin\llama-server.exe' if (-not (Test-Path $Server)) { # fall back to PATH $cmd = Get-Command llama-server -ErrorAction SilentlyContinue if ($cmd) { $Server = $cmd.Source } else { Write-Host "ERROR: llama-server not found at $Server and not on PATH." -ForegroundColor Red exit 1 } } function Start-Side { param([string]$Gguf, [int]$Port, [string]$Tag) $log = Join-Path $RepoRoot "llama-server-$Tag-$Port.log" $pidFile = Join-Path $RepoRoot "llama-server-$Tag-$Port.pid" Write-Host "Starting [$Tag] $Server -m $Gguf --port $Port ..." $proc = Start-Process -FilePath $Server ` -ArgumentList @('-m', $Gguf, '--port', "$Port", '--jinja', '-c', '2048', '-ngl', '0') ` -RedirectStandardOutput $log -RedirectStandardError ("$log.err") ` -PassThru $proc.Id | Out-File -FilePath $pidFile -Encoding ascii Write-Host " PID $($proc.Id) (pid file: $pidFile, log: $log)" # Wait for /health (llama-server serves GET /health -> {"status":"ok"}). $deadline = (Get-Date).AddSeconds(300) while ((Get-Date) -lt $deadline) { if ($proc.HasExited) { Write-Host "ERROR: [$Tag] server (PID $($proc.Id)) exited early. See $log and $log.err" -ForegroundColor Red exit 1 } try { $r = Invoke-WebRequest -Uri "http://127.0.0.1:$Port/health" -TimeoutSec 5 -UseBasicParsing if ($r.StatusCode -eq 200) { Write-Host " [$Tag] healthy on port $Port"; return $proc.Id } } catch { Start-Sleep -Seconds 2 } } Write-Host "ERROR: [$Tag] server did not become healthy within 300s. See $log" -ForegroundColor Red exit 1 } $pidA = Start-Side -Gguf $BaseGguf -Port $PortA -Tag 'base' $pidB = Start-Side -Gguf $TunedGguf -Port $PortB -Tag 'tuned' $urlA = "http://127.0.0.1:$PortA/v1" $urlB = "http://127.0.0.1:$PortB/v1" Write-Host "" Write-Host "Both servers up:" Write-Host " A (base): $urlA (PID $pidA)" Write-Host " B (tuned): $urlB (PID $pidB)" Write-Host "" Write-Host "Next:" Write-Host " python pipeline/runtime_ab.py --base-url-a $urlA --label-a `"base Q8_0`" --base-url-b $urlB --label-b `"tuned Q8_0`" --data data_native/test.jsonl --limit 100 --out reports/runtime_ab" Write-Host "Stop with: Stop-Process -Id $pidA,$pidB"