<# .SYNOPSIS Starts the Leleka gpt-oss runtime on Windows: the control plane (/v1/responses) with a CPU, iGPU or NPU worker. .DESCRIPTION Writes a configuration for strata-next, starts it, waits until it is ready and keeps it running in the foreground (Ctrl+C stops the control plane and its workers). Nothing is installed or downloaded. Modes (-Mode): igpu (default) leleka-igpu-worker: long prompts are prefilled on the integrated GPU, decoding on the CPU; with no usable GPU it serves from the CPU on its own. cpu leleka-cpu-worker: everything on the CPU (AVX2 / AVX-VNNI). npu leleka-npu-worker: long prompts are prefilled by the Intel NPU through leleka-npu-service (experimental; needs -OpenVinoRoot, an unpacked OpenVINO runtime, and an Intel NPU driver). Defaults that matter, with the reason (docs/windows-runtime.md has the measurements): -Speculate on exact prompt-lookup speculative decoding; the output equals plain decoding, copy-heavy output (rewrites, patches) decodes up to 1.5x faster, other output is within noise. -CacheSlots 4 one worker keeps the KV caches of four conversations, so several agents sharing the runtime do not recompute each other's prefix. -Threads logical processors minus two (the two low-power cores add nothing to a memory-bound decode). .PARAMETER Model Path of gpt-oss-20b-MXFP4.gguf (SHA-256 65d06d31...cde53ab is the file this runtime was measured with). .PARAMETER BinDir Folder with strata-next.exe and the workers. Default: bin next to this script, else target\release of the repository. #> [CmdletBinding()] param( [Parameter(Mandatory)] [string] $Model, [ValidateSet('igpu', 'cpu', 'npu')] [string] $Mode = 'igpu', [string] $OpenVinoRoot = $env:LELEKA_OPENVINO_ROOT, [string] $BinDir, [int] $Port = 8081, [string] $Bind = '127.0.0.1', [int] $Context = 16384, [int] $Threads = 0, [int] $CacheSlots = 4, [switch] $NoSpeculate, [int] $StartupTimeoutSeconds = 300 ) $ErrorActionPreference = 'Stop' if (-not (Test-Path -LiteralPath $Model -PathType Leaf)) { throw "model file not found: $Model" } if (-not $BinDir) { $candidates = @((Join-Path $PSScriptRoot 'bin'), (Join-Path $PSScriptRoot '..\..\target\release'), (Join-Path $PSScriptRoot '..\..\dist\windows')) $BinDir = $candidates | Where-Object { Test-Path (Join-Path $_ 'strata-next.exe') } | Select-Object -First 1 } if (-not $BinDir -or -not (Test-Path (Join-Path $BinDir 'strata-next.exe'))) { throw 'strata-next.exe not found; pass -BinDir' } $BinDir = (Resolve-Path $BinDir).Path $worker = @{ igpu = 'leleka-igpu-worker'; cpu = 'leleka-cpu-worker'; npu = 'leleka-npu-worker' }[$Mode] if (-not (Test-Path (Join-Path $BinDir "$worker.exe"))) { throw "$worker.exe not found in $BinDir" } if ($Mode -eq 'npu') { if (-not $OpenVinoRoot -or -not (Test-Path $OpenVinoRoot)) { throw 'npu mode needs -OpenVinoRoot (or LELEKA_OPENVINO_ROOT): an unpacked OpenVINO runtime' } if (-not (Test-Path (Join-Path $BinDir 'leleka-npu-service.exe'))) { throw "leleka-npu-service.exe not found in $BinDir" } } if ($Threads -le 0) { $Threads = [Math]::Max(1, [Environment]::ProcessorCount - 2) } # the model is memory-mapped (12 GB) next to the KV caches and scratch: warn rather than start into paging $os = Get-CimInstance Win32_OperatingSystem $freeGb = [Math]::Round($os.FreePhysicalMemory / 1MB, 1) $needGb = [Math]::Round(12.1 + 0.05 * $Context / 1000 * $CacheSlots + 1.5, 1) if ($freeGb + 12 -lt $needGb) { Write-Warning "about $needGb GB needed (model 12.1 GB when mapped, $CacheSlots KV caches of $Context tokens, scratch) and only $freeGb GB are free: close other programs or lower -Context / -CacheSlots" } $args = @('--model', $Model, '--ctx', "$Context", '--threads', "$Threads", '--cache-slots', "$CacheSlots") if (-not $NoSpeculate) { $args += '--speculate' } if ($Mode -eq 'npu') { $args += @('--openvino-root', $OpenVinoRoot) } $work = Join-Path ([IO.Path]::GetTempPath()) 'leleka-runtime' New-Item -ItemType Directory -Force $work | Out-Null $configPath = Join-Path $work 'config.json' @{ bind = "${Bind}:$Port"; model = 'gpt-oss-20b' engine = @{ executable = (Join-Path $BinDir "$worker.exe"); args = $args; gptoss_gguf = (Resolve-Path $Model).Path startup_timeout_s = $StartupTimeoutSeconds; generation_timeout_s = 1800 } } | ConvertTo-Json -Depth 5 | ForEach-Object { [IO.File]::WriteAllText($configPath, $_, (New-Object Text.UTF8Encoding($false))) } Write-Host "Leleka: $Mode worker, $Threads threads, context $Context, $CacheSlots cache slots, speculation $(if ($NoSpeculate) {'off'} else {'on'})" $server = Start-Process (Join-Path $BinDir 'strata-next.exe') -ArgumentList @('serve', '--config', $configPath) -PassThru -NoNewWindow try { $deadline = (Get-Date).AddSeconds($StartupTimeoutSeconds + 30) $ready = $false while ((Get-Date) -lt $deadline -and -not $server.HasExited) { try { if ((Invoke-RestMethod "http://${Bind}:$Port/ready" -TimeoutSec 2) ) { $ready = $true; break } } catch { } Start-Sleep 2 } if (-not $ready) { throw 'the runtime did not become ready (see the messages above)' } Write-Host "Ready: http://${Bind}:$Port/v1/responses (health: /health, readiness: /ready). Ctrl+C stops it." $server.WaitForExit() } finally { if (-not $server.HasExited) { Stop-Process -Id $server.Id -Force } }