$ErrorActionPreference='Continue' $B='C:\rig\build'; $log="$B\e21e_chain.log" function L($m){ "$(Get-Date -Format o) $m" | Out-File -FilePath $log -Append -Encoding utf8 } L "=== e21e start: PR29827 build; 2B @1M fully resident needle + 4B @512K depth/replication ===" $out='C:\rig\e21_budget\e21e'; 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) } $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 } $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') $m2='C:\rig\gguf\q35\Qwen3.5-2B-Q4_K_M.gguf' Needle @{n='2b_1m_yarn4_q4_0_ub64';m=$m2;c=1048576;k='q4_0';ub=64;x=$yarn4} 41500 '2b_1m_d50' 0.5 Needle @{n='2b_1m_yarn4_q4_0_ub64';m=$m2;c=1048576;k='q4_0';ub=64;x=$yarn4} 41500 '2b_1m_d10' 0.1 Needle @{n='2b_1m_yarn4_q4_0_ub64';m=$m2;c=1048576;k='q4_0';ub=64;x=$yarn4} 41500 '2b_1m_d90' 0.9 Needle @{n='512k_yarn2_q4_0_ub64';c=524288;k='q4_0';ub=64;x=$yarn} 21000 '4b_512k_d10' 0.1 Needle @{n='512k_yarn2_q4_0_ub64';c=524288;k='q4_0';ub=64;x=$yarn} 21000 '4b_512k_d90' 0.9 Needle @{n='512k_yarn2_q4_0_ub64';c=524288;k='q4_0';ub=64;x=$yarn} 21000 '4b_512k_d50_rep2' 0.5 Get-Process llama-server -ErrorAction SilentlyContinue | Stop-Process -Force L "=== E21eDONE ==="