$ErrorActionPreference='Continue' $B='C:\rig\build'; $log="$B\e21f_chain.log" function L($m){ "$(Get-Date -Format o) $m" | Out-File -FilePath $log -Append -Encoding utf8 } L "=== e21f start: PR29827 build; 4B max fully-resident ctx (640K/704K/768K) + 9B @262K, needle with spill guard ===" $out='C:\rig\e21_budget\e21f'; New-Item -ItemType Directory -Force $out | Out-Null $res="$out\results.jsonl" $bin='C:\rig\llama.cpp\fork-29827\build-cuda\bin\llama-server.exe' $model='C:\rig\gguf\q35\Qwen3.5-4B-Q4_K_M.gguf' function Shared($id){ try{ [math]::Round(((Get-Counter "\GPU Process Memory(pid_$($id)*)\Shared Usage" -ErrorAction Stop).CounterSamples | Measure-Object CookedValue -Sum).Sum/1MB) }catch{ $null } } function Start-Srv($c,$lf){ Get-Process llama-server -ErrorAction SilentlyContinue | Stop-Process -Force; Start-Sleep 5 $a=@('-m',$(if($c.m){$c.m}else{$model}),'-c',$c.c,'-ngl','99','-fa','on','-np','1','--port','8097','-ctk',$c.k,'-ctv',$c.k,'-ub',$c.ub,'-b',[math]::Max($c.ub,512),'-t','8','-v') + $(if($c.x){$c.x}else{@()}) $p=Start-Process -FilePath $bin -ArgumentList $a -RedirectStandardError $lf -RedirectStandardOutput ($lf+'.out') -PassThru -NoNewWindow $t0=Get-Date; $ok=$false while(((Get-Date)-$t0).TotalSeconds -lt 300 -and -not $p.HasExited){ if(Select-String -Path $lf -Pattern 'listening on' -Quiet -ErrorAction SilentlyContinue){$ok=$true;break} Start-Sleep 3 } Start-Sleep 8 return @($p,$ok) } function Bufs($lf){ $t=Get-Content $lf -Raw -ErrorAction SilentlyContinue; $g={param($pat) $m=[regex]::Matches($t,$pat); if($m.Count){[double]$m[$m.Count-1].Groups[1].Value}else{$null}} @{cuda_compute_mib=(& $g 'CUDA0 compute buffer size =\s*([\d.]+)'); host_compute_mib=(& $g 'CUDA_Host compute buffer size =\s*([\d.]+)'); kv_mib=(& $g 'KV buffer size =\s*([\d.]+)')} } $fill='The grass is green. The sky is blue. The sun is yellow. Here we go. There and back again. ' $needle=' The secret passcode for the vault is 7319-4826. ' function Needle($c,$reps,$tag,$depth=0.5){ $lf="$out\needle_$tag.log"; $r0=Start-Srv $c $lf; $p=$r0[0] if(-not $r0[1]){ L "needle ${tag}: server did not load"; return } $s0=Shared $p.Id; $u0=[int]((& nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits) -join '') if($s0 -gt 300){ $r=[ordered]@{phase='needle';tag=$tag;cfg=$c.n;ctx=$c.c;status='SKIPPED-WONTFIT';idle_vram_mib=$u0;idle_shared_mib=$s0;bufs=(Bufs $lf);t=(Get-Date -Format o)}; ($r|ConvertTo-Json -Compress)|Out-File $res -Append -Encoding utf8; L ("wontfit "+($r|ConvertTo-Json -Compress)); try{Stop-Process -Id $p.Id -Force}catch{}; return } $sb=New-Object System.Text.StringBuilder; $half=[int]($reps*$depth) for($i=0;$i -lt $reps;$i++){ [void]$sb.Append($fill); if($i -eq $half){[void]$sb.Append($needle)} } $prompt=$sb.ToString()+"`n`nQuestion: What is the secret passcode for the vault? Answer with the passcode only.`nAnswer:" $body=@{prompt=$prompt;n_predict=24;temperature=0;cache_prompt=$false}|ConvertTo-Json -Compress [IO.File]::WriteAllText("$out\needle_$tag.body.json",$body) $job=Start-Job -ScriptBlock { param($f) try{ $r=Invoke-RestMethod -Uri 'http://127.0.0.1:8097/completion' -Method Post -ContentType 'application/json' -InFile $f -TimeoutSec 7200; $r|ConvertTo-Json -Compress -Depth 5 }catch{ "ERR "+$_.Exception.Message } } -ArgumentList "$out\needle_$tag.body.json" $t0=Get-Date; $maxU=0; $maxS=0 while($job.State -eq 'Running' -and ((Get-Date)-$t0).TotalMinutes -lt 125){ $u=[int]((& nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits) -join ''); if($u -gt $maxU){$maxU=$u} $s=Shared $p.Id; if($s -gt $maxS){$maxS=$s}; Start-Sleep 10 } $o=Receive-Job $job -Wait -ErrorAction SilentlyContinue | Out-String; Remove-Job $job -Force try{Stop-Process -Id $p.Id -Force}catch{} $content=$null;$np=$null;$pps=$null try{$j=$o|ConvertFrom-Json; $content=$j.content; $np=$j.timings.prompt_n; $pps=$j.timings.prompt_per_second}catch{} $r=[ordered]@{phase='needle';tag=$tag;model=$(if($c.m){Split-Path $c.m -Leaf}else{Split-Path $model -Leaf});depth=$depth;cfg=$c.n;ctx=$c.c;ub=$c.ub;reps=$reps;prompt_tokens=$np;prompt_tps=$pps;answer=$content;pass=($o -match '7319-4826');max_vram_used_mib=$maxU;max_shared_mib=$maxS;wall_min=[math]::Round(((Get-Date)-$t0).TotalMinutes,1);t=(Get-Date -Format o)} ($r|ConvertTo-Json -Compress)|Out-File $res -Append -Encoding utf8; L ("needle "+($r|ConvertTo-Json -Compress)) } $yarn=@('--override-kv','qwen35.context_length=int:524288','--rope-scaling','yarn','--rope-scale','2','--yarn-orig-ctx','262144') $yarn4=@('--override-kv','qwen35.context_length=int:1048576','--rope-scaling','yarn','--rope-scale','4','--yarn-orig-ctx','262144') $m9='C:\rig\gguf\q35\Qwen3.5-9B-Q4_K_M.gguf' function Y($ctx,$sc){ @('--override-kv',"qwen35.context_length=int:$ctx",'--rope-scaling','yarn','--rope-scale',"$sc",'--yarn-orig-ctx','262144') } Needle @{n='4b_640k_yarn2.5_q4_0_ub64';c=655360;k='q4_0';ub=64;x=(Y 655360 2.5)} 27000 '4b_640k_d50' 0.5 Needle @{n='4b_704k_yarn2.75_q4_0_ub64';c=720896;k='q4_0';ub=64;x=(Y 720896 2.75)} 29800 '4b_704k_d50' 0.5 Needle @{n='4b_768k_yarn3_q4_0_ub64';c=786432;k='q4_0';ub=64;x=(Y 786432 3)} 32500 '4b_768k_d50' 0.5 Needle @{n='9b_262k_q4_0_ub64';m=$m9;c=262144;k='q4_0';ub=64} 10700 '9b_262k_d50' 0.5 Needle @{n='9b_262k_q4_0_ub64';m=$m9;c=262144;k='q4_0';ub=64} 10700 '9b_262k_d10' 0.1 Needle @{n='9b_262k_q4_0_ub64';m=$m9;c=262144;k='q4_0';ub=64} 10700 '9b_262k_d90' 0.9 Get-Process llama-server -ErrorAction SilentlyContinue | Stop-Process -Force L "=== E21fDONE ==="