# E22d: which cache half causes the 64K quantized-KV perplexity drop? Needs llama-perplexity with two small env-var patches: # LLAMA_PPL_TOKEN_OFFSET = number of leading tokens of the text file to skip # LLAMA_PPL_SCORE_LAST = score only the last N tokens of the (single) chunk # Without those env vars the tool behaves as upstream. $ErrorActionPreference='Continue' $B='C:\AGI\agi-research\build'; $log="$B\e22d_chain.log" function L($m){ "$(Get-Date -Format o) $m" | Out-File -FilePath $log -Append -Encoding utf8 } L "=== e22d start ===" $out='C:\AGI\agi-research\e21_budget\e22d'; New-Item -ItemType Directory -Force $out | Out-Null $bin='C:\AGI\llama.cpp\fork-29827\build-cuda\bin\llama-perplexity.exe' $m4='C:\AGI\gguf\q35\Qwen3.5-4B-Q4_K_M.gguf' $txt='C:\AGI\agi-research\bench\wiki_test.txt' Get-Process llama-server -ErrorAction SilentlyContinue | Stop-Process -Force $env:LLAMA_PPL_SCORE_LAST='4096' $arms=@(@('q8_0','f16','k8vf'),@('f16','q8_0','kfv8'),@('q4_0','f16','k4vf'),@('f16','q4_0','kfv4'),@('q8_0','q8_0','q8rep')) foreach($E in @(72000,108000,144000,180000,216000,252000)){ foreach($Lc in @(65536)){ $ctx=$Lc+4097; $off=$E-$ctx; $env:LLAMA_PPL_TOKEN_OFFSET="$off"; $nm="E${E}_L$Lc"; $base="$out\kld_base_$nm.bin" & $bin -m $m4 -f $txt -c $ctx --chunks 1 -ngl 99 -fa on -ctk f16 -ctv f16 -b 2048 -ub 512 --kl-divergence-base $base *> "$out\${nm}_f16_base.log" $p=(Select-String -Path "$out\${nm}_f16_base.log" -Pattern 'Final estimate|token offset|you need|failed' | % { $_.Line.Trim() }) -join ' ' L "$nm f16 base :: $p" if(-not (Test-Path $base)){ L "$nm no base, skipping"; continue } foreach($r in $arms){ $tag="${nm}_$($r[2])"; $lf="$out\$tag.log" $a=@('-m',$m4,'-f',$txt,'-c',$ctx,'--chunks',1,'-ngl',99,'-fa','on','-ctk',$r[0],'-ctv',$r[1],'-b',2048,'-ub',512,'--kl-divergence-base',$base,'--kl-divergence') $t0=Get-Date $pr=Start-Process -FilePath $bin -ArgumentList $a -RedirectStandardOutput "$lf.out" -RedirectStandardError $lf -NoNewWindow -PassThru if(-not $pr.WaitForExit(8*60*1000)){ $pr.Kill(); L "result $tag TIMEOUT"; continue } $sum=(Select-String -Path $lf,"$lf.out" -Pattern 'Mean PPL\(Q\) |Mean PPL\(base\)|Mean KLD|Same top' | % { $_.Line.Trim() }) -join ' | ' L "result $tag wall $([int]((Get-Date)-$t0).TotalSeconds)s :: $sum" } Remove-Item $base -Force -ErrorAction SilentlyContinue } } L "=== e22dDONE ==="