# E21v: KV cache type vs model quality (KL divergence vs f16 KV), Qwen3.5-4B, WikiText-2 test # Edit the paths below for your machine. $ErrorActionPreference='Continue' $log='e21v_chain.log' function L($m){ "$(Get-Date -Format o) $m" | Out-File -FilePath $log -Append -Encoding utf8 } L "=== e21v start ===" $out='e21v'; New-Item -ItemType Directory -Force $out | Out-Null $bin='llama.cpp\build-cuda\bin\llama-perplexity.exe' # llama.cpp with upstream PR 29827 $m4='Qwen3.5-4B-Q4_K_M.gguf'; $txt='wiki_test.txt' # WikiText-2 raw test split foreach($ctx in @(16384)){ $base="$out\kld_base_c$ctx.bin" & $bin -m $m4 -f $txt -c $ctx --chunks 8 -ngl 99 -fa on -ctk f16 -ctv f16 -b 2048 -ub 512 --kl-divergence-base $base *> "$out\f16_c$ctx.log" L "f16 base c$ctx exit $LASTEXITCODE" foreach($kv in @(@('q8_0','q8_0'),@('q5_0','q5_0'),@('q4_1','q4_1'),@('iq4_nl','iq4_nl'),@('q4_0','q4_0'),@('q8_0','q4_0'),@('q4_0','q8_0'),@('f16','f16'))){ $tag="$($kv[0])_$($kv[1])_c$ctx" & $bin -m $m4 -f $txt -c $ctx --chunks 8 -ngl 99 -fa on -ctk $kv[0] -ctv $kv[1] -b 2048 -ub 512 --kl-divergence-base $base --kl-divergence *> "$out\$tag.log" $sum=(Select-String -Path "$out\$tag.log" -Pattern 'Mean PPL|Mean KLD|Same top|RMS' | % { $_.Line.Trim() }) -join ' | ' L "result $tag exit $LASTEXITCODE :: $sum" } } L "=== E21vDONE ==="