$ErrorActionPreference='Continue' $B='C:\AGI\agi-research\build'; $log="$B\e21t_chain.log" function L($m){ "$(Get-Date -Format o) $m" | Out-File -FilePath $log -Append -Encoding utf8 } L "=== e21t start: capture real f16 KV cache (4B) via slot save for bit-level analysis ===" $out='C:\AGI\agi-research\e21_budget\e21t'; New-Item -ItemType Directory -Force $out | Out-Null $res="$out\results.jsonl" $bin='C:\AGI\llama.cpp\fork-29827\build-cuda\bin\llama-server.exe' $m4='C:\AGI\gguf\q35\Qwen3.5-4B-Q4_K_M.gguf' $wiki=[IO.File]::ReadAllText('C:\AGI\agi-research\bench\wiki_test.txt') $hay=[IO.File]::ReadAllText('C:\AGI\agi-research\e21_budget\e21p\hay_trial0.txt') $docs=@( @{tag='wikiA';txt=$wiki.Substring(0,120000)}, @{tag='wikiB';txt=$wiki.Substring(600000,120000)}, @{tag='mathA';txt=$hay.Substring(0,75000)} ) Get-Process llama-server -ErrorAction SilentlyContinue | Stop-Process -Force; Start-Sleep 6 foreach($kv in @('f16','q4_0')){ $lf="$out\srv_$kv.log" $a=@('-m',$m4,'-c','40960','-ngl','99','-fa','on','-np','1','--port','8098','-ctk',$kv,'-ctv',$kv,'-t','8','--slot-save-path',$out) $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 } foreach($d in $docs){ if($kv -eq 'q4_0' -and $d.tag -ne 'wikiA'){ continue } $r=[ordered]@{tag=$d.tag;kv=$kv;loaded=$ok} try{ $body=@{prompt=$d.txt;n_predict=1;temperature=0;cache_prompt=$true;id_slot=0}|ConvertTo-Json -Compress [IO.File]::WriteAllText("$out\b.json",$body) $c=Invoke-RestMethod -Uri 'http://127.0.0.1:8098/completion' -Method Post -ContentType 'application/json' -InFile "$out\b.json" -TimeoutSec 1200 $r.n_prompt=$c.timings.prompt_n; $r.prompt_tps=$c.timings.prompt_per_second $fn="kv_$($kv)_$($d.tag).bin" $sv=Invoke-RestMethod -Uri 'http://127.0.0.1:8098/slots/0?action=save' -Method Post -ContentType 'application/json' -Body (@{filename=$fn}|ConvertTo-Json -Compress) -TimeoutSec 600 $r.saved=$fn; $r.n_saved=$sv.n_saved; $r.n_written=$sv.n_written $null=Invoke-RestMethod -Uri 'http://127.0.0.1:8098/slots/0?action=erase' -Method Post -TimeoutSec 60 }catch{ $r.err="$_" } $r.t=(Get-Date -Format o) ($r|ConvertTo-Json -Compress)|Out-File $res -Append -Encoding utf8; L ("result "+($r|ConvertTo-Json -Compress)) } try{Stop-Process -Id $p.Id -Force}catch{}; Start-Sleep 5 } Get-Process llama-server -ErrorAction SilentlyContinue | Stop-Process -Force L "=== E21tDONE ==="