-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRun-VLLMFP8Query8K.ps1
More file actions
131 lines (117 loc) · 4.53 KB
/
Copy pathRun-VLLMFP8Query8K.ps1
File metadata and controls
131 lines (117 loc) · 4.53 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
param(
[int]$Port = 8800,
[int]$ContainerPort = 8000,
[int]$Context = 8192,
[string]$Image = "vllm/vllm-openai:gemma4-cu130",
[string]$ContainerName = "tq-vllm-fp8-8k"
)
$ErrorActionPreference = "Stop"
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
$bench = Join-Path $root "bench_embeddings_turbo"
$python = Join-Path $root "envs\tq-bench\python.exe"
$runLogs = Join-Path $bench "run_logs"
$hfCache = Join-Path $root "hf_cache"
$fp8Index = "I:\dev\Legal\case_kb\bench_embeddings\indexes\qwen3-embedding-8b-fp8-vllm.lance"
$modelId = "qwen3-embedding-8b-fp8-vllm-docker-8k"
$indexModelId = "qwen3-embedding-8b-fp8-vllm"
$hfRepo = "maywell/Qwen3-Embedding-8B-FP8-Dynamic"
if (!(Test-Path $python)) { throw "Python env not found at $python" }
if (!(Test-Path $fp8Index)) { throw "FP8 vLLM index not found at $fp8Index" }
New-Item -ItemType Directory -Force -Path $runLogs | Out-Null
New-Item -ItemType Directory -Force -Path $hfCache | Out-Null
function Stop-PortProcess {
param([int]$LocalPort)
$connections = Get-NetTCPConnection -LocalPort $LocalPort -ErrorAction SilentlyContinue
foreach ($conn in $connections) {
if ($conn.OwningProcess -and $conn.OwningProcess -ne 0) {
Stop-Process -Id $conn.OwningProcess -Force -ErrorAction SilentlyContinue
}
}
}
function Stop-Container {
param([string]$Name)
$existing = docker ps -a -q -f "name=^$Name$"
if ($existing) {
docker rm -f $Name | Out-Null
}
}
function Wait-VLLMReady {
param([int]$LocalPort, [int]$TimeoutSeconds = 900)
$deadline = (Get-Date).AddSeconds($TimeoutSeconds)
do {
try {
Invoke-RestMethod -Uri "http://127.0.0.1:$LocalPort/v1/models" -TimeoutSec 5 | Out-Null
return
} catch {
Start-Sleep -Seconds 5
}
} while ((Get-Date) -lt $deadline)
throw "vLLM did not become ready on port $LocalPort within $TimeoutSeconds seconds"
}
function Start-VramMonitor {
param([string]$Path)
$cmd = "while (`$true) { nvidia-smi --query-gpu=timestamp,memory.used,utilization.gpu --format=csv,noheader,nounits; Start-Sleep -Seconds 1 }"
return Start-Process -FilePath "powershell" -ArgumentList @("-NoProfile", "-Command", $cmd) -RedirectStandardOutput $Path -WindowStyle Hidden -PassThru
}
function Save-DockerLogs {
param([string]$Name, [string]$Path)
$existing = docker ps -a -q -f "name=^$Name$"
if ($existing) {
cmd /c "docker logs $Name > `"$Path`" 2>&1"
}
}
$serverLog = Join-Path $runLogs "$modelId.server.docker.log"
$evalOut = Join-Path $runLogs "$modelId.on-fp8-vllm-8k.eval.out.log"
$evalErr = Join-Path $runLogs "$modelId.on-fp8-vllm-8k.eval.err.log"
$vramCsv = Join-Path $runLogs "$modelId.on-fp8-vllm-8k.eval.vram.csv"
Write-Host "=== 8K FP8-index cross-eval: query=$modelId index=$indexModelId ==="
Stop-Container -Name $ContainerName
Stop-PortProcess -LocalPort $Port
$mountCache = "${hfCache}:/root/.cache/huggingface"
$dockerArgs = @(
"run", "-d",
"--name", $ContainerName,
"--gpus", "all",
"--ipc", "host",
"-p", "${Port}:${ContainerPort}",
"-v", $mountCache,
"-e", "HF_HUB_ENABLE_HF_TRANSFER=0",
"-e", "VLLM_USAGE_SOURCE=production-docker-image",
$Image,
$hfRepo,
"--runner", "pooling",
"--convert", "embed",
"--max-model-len", "$Context",
"--served-model-name", $hfRepo,
"--host", "0.0.0.0",
"--port", "$ContainerPort",
"--trust-remote-code",
"--gpu-memory-utilization", "0.90"
)
docker @dockerArgs | Out-File -FilePath $serverLog -Encoding utf8
$monitor = $null
try {
Write-Host "Waiting for vLLM server on http://127.0.0.1:$Port ..."
Wait-VLLMReady -LocalPort $Port
Save-DockerLogs -Name $ContainerName -Path $serverLog
$monitor = Start-VramMonitor -Path $vramCsv
$pyArgs = @(
"-m", "runners.eval_quality",
"--model", $modelId,
"--index-model", $indexModelId,
"--index-path", $fp8Index
)
$p = Start-Process -FilePath $python -ArgumentList $pyArgs -WorkingDirectory $bench -RedirectStandardOutput $evalOut -RedirectStandardError $evalErr -Wait -PassThru -WindowStyle Hidden
if (($p.ExitCode -ne 0) -and ($null -ne $p.ExitCode)) {
throw "vLLM cross-eval failed, see $evalErr"
}
} finally {
if ($monitor -and !$monitor.HasExited) {
Stop-Process -Id $monitor.Id -Force -ErrorAction SilentlyContinue
}
Save-DockerLogs -Name $ContainerName -Path $serverLog
Stop-Container -Name $ContainerName
}
Push-Location $bench
& $python -m runners.build_fp8_cross_query_report
Pop-Location