File size: 3,675 Bytes
17b0632 | 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 | <#
.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 <base.gguf> -TunedGguf <tuned.gguf> [-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"
|