Files
leleka/benchmarks/tools/Smoke-GptOssStack.ps1
T

85 lines
5.8 KiB
PowerShell

<#
.SYNOPSIS
End-to-end smoke test of the gpt-oss stack: the control plane serving /v1/responses with the CPU worker.
.DESCRIPTION
Starts leleka-api with leleka-cpu-worker (or, with -Worker leleka-igpu-worker, the GPU-prefill worker) for the given GGUF, waits for readiness, sends four requests
(a plain question, a function call, a tool-result round trip that must reuse the cached prefix, and a
streaming request), checks the answers' shape, and stops everything it started. Build first:
cargo build --release -p leleka-control-plane -p leleka-cpu-worker -p leleka-igpu-worker
It is a functional check, not a benchmark. Run it on an otherwise idle machine.
#>
param(
[Parameter(Mandatory)] [string] $Model,
[string] $RepoRoot,
[int] $Port = 8081,
[int] $Context = 8192,
[int] $Threads = 10,
[ValidateSet('leleka-cpu-worker', 'leleka-igpu-worker', 'leleka-npu-worker')] [string] $Worker = 'leleka-cpu-worker',
[string] $OpenVinoRoot = '',
[int] $GpuMinTokens = 256
)
$ErrorActionPreference = 'Stop'
if (-not $RepoRoot) { $RepoRoot = (Resolve-Path (Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Path) '..\..')).Path }
$bin = Join-Path $RepoRoot 'target\release'
$work = Join-Path ([IO.Path]::GetTempPath()) ("leleka-smoke-" + [Guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory $work | Out-Null
$config = @{
bind = "127.0.0.1:$Port"; model = 'gpt-oss-20b'
engine = @{
executable = (Join-Path $bin "$Worker.exe")
args = @('--model', $Model, '--ctx', "$Context", '--threads', "$Threads") + $(if ($Worker -eq 'leleka-igpu-worker') { @('--gpu-min-tokens', "$GpuMinTokens") } elseif ($Worker -eq 'leleka-npu-worker') { @('--npu-min-tokens', "$GpuMinTokens", '--openvino-root', $OpenVinoRoot) } else { @() })
gptoss_gguf = $Model; startup_timeout_s = 300; generation_timeout_s = 600
}
} | ConvertTo-Json -Depth 5
[IO.File]::WriteAllText((Join-Path $work 'config.json'), $config, (New-Object Text.UTF8Encoding($false)))
function Check($ok, $what) { if (-not $ok) { throw "FAILED: $what" } else { "ok $what" } }
$server = Start-Process (Join-Path $bin 'leleka-api.exe') -ArgumentList @('serve', '--config', (Join-Path $work 'config.json')) `
-PassThru -WindowStyle Hidden -RedirectStandardOutput (Join-Path $work 'out.txt') -RedirectStandardError (Join-Path $work 'err.txt')
try {
$ready = $false
foreach ($i in 1..100) {
Start-Sleep 3
if ($server.HasExited) { throw 'the control plane exited; see ' + (Join-Path $work 'err.txt') }
try { if ((Invoke-WebRequest "http://127.0.0.1:$Port/ready" -UseBasicParsing -TimeoutSec 3).StatusCode -eq 200) { $ready = $true; break } } catch {}
}
Check $ready 'control plane and worker ready'
$uri = "http://127.0.0.1:$Port/v1/responses"
$post = { param($b) Invoke-RestMethod $uri -Method Post -Body ($b | ConvertTo-Json -Depth 8 -Compress) -ContentType 'application/json' -TimeoutSec 300 }
$tool = @{ type = 'function'; name = 'get_weather'; description = 'Get the current weather for a city.'
parameters = @{ type = 'object'; properties = @{ city = @{ type = 'string' } }; required = @('city') } }
$r = & $post @{ model = 'gpt-oss-20b'; input = 'What is the capital of France? Answer in one short sentence.'; max_output_tokens = 300; reasoning = @{ effort = 'low' } }
$text = ($r.output | Where-Object type -eq 'message' | ForEach-Object { $_.content[0].text }) -join ''
Check ($r.status -eq 'completed' -and $text -match 'Paris') "plain question answered: $text"
$r = & $post @{ model = 'gpt-oss-20b'; input = "What's the weather in Paris right now? Use the tool."; tools = @($tool); max_output_tokens = 400; reasoning = @{ effort = 'low' } }
$call = $r.output | Where-Object type -eq 'function_call' | Select-Object -First 1
Check ($call -and $call.name -eq 'get_weather' -and ($call.arguments | ConvertFrom-Json).city -eq 'Paris') "function call: $($call.arguments)"
$items = @(
@{ role = 'user'; content = "What's the weather in Paris right now? Use the tool." },
@{ type = 'function_call'; call_id = 'call_1'; name = 'get_weather'; arguments = '{"city":"Paris"}' },
@{ type = 'function_call_output'; call_id = 'call_1'; output = '{"temp_c": 18, "sky": "light rain"}' })
$r = & $post @{ model = 'gpt-oss-20b'; input = $items; tools = @($tool); max_output_tokens = 400; reasoning = @{ effort = 'low' } }
$text = ($r.output | Where-Object type -eq 'message' | ForEach-Object { $_.content[0].text }) -join ''
Check ($text -match '18') "tool result used: $text"
Check ($r.usage.input_tokens_details.cached_tokens -gt 0) "prefix reused ($($r.usage.input_tokens_details.cached_tokens) of $($r.usage.input_tokens) prompt tokens cached)"
$req = [Net.HttpWebRequest]::Create($uri); $req.Method = 'POST'; $req.ContentType = 'application/json'; $req.Timeout = 300000
$bytes = [Text.Encoding]::UTF8.GetBytes((@{ model = 'gpt-oss-20b'; input = 'Count from 1 to 5.'; stream = $true; max_output_tokens = 200; reasoning = @{ effort = 'low' } } | ConvertTo-Json -Compress))
$s = $req.GetRequestStream(); $s.Write($bytes, 0, $bytes.Length); $s.Close()
$reader = New-Object IO.StreamReader($req.GetResponse().GetResponseStream()); $events = @()
while (($line = $reader.ReadLine()) -ne $null) { if ($line.StartsWith('event: ')) { $events += $line.Substring(7) } }
Check (($events -contains 'response.created') -and ($events -contains 'response.output_text.delta') -and ($events[-1] -eq 'response.completed')) "stream of $($events.Count) events ends with response.completed"
'ALL PASSED'
}
finally {
# the worker is a child of the control plane: stop only processes this script started
Get-CimInstance Win32_Process -Filter "ParentProcessId=$($server.Id)" -ErrorAction SilentlyContinue |
ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }
if (-not $server.HasExited) { Stop-Process $server -Force }
Remove-Item $work -Recurse -Force -ErrorAction SilentlyContinue
}