$ErrorActionPreference='Continue' $B='C:\rig\build'; $log="$B\e21d_chain.log" function L($m){ "$(Get-Date -Format o) $m" | Out-File -FilePath $log -Append -Encoding utf8 } L "=== e21d start: PR29827 build, push 512K/1M fully resident + needle ===" $out='C:\rig\e21_budget\e21d'; 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',$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){ $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 } $sb=New-Object System.Text.StringBuilder; $half=[int]($reps/2) 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;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);raw=($o.Substring(0,[math]::Min(400,$o.Length)));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') Needle @{n='256k_native_q4_0_ub64';c=262144;k='q4_0';ub=64} 10300 '256k_native' Needle @{n='512k_yarn2_q4_0_ub64';c=524288;k='q4_0';ub=64;x=$yarn} 21000 '512k_yarn2' Needle @{n='512k_yarn2_q4_0_ub64_q25';c=524288;k='q4_0';ub=64;x=$yarn} 5250 '512k_yarn2_at128k' Get-Process llama-server -ErrorAction SilentlyContinue | Stop-Process -Force L "=== E21dDONE ==="