# E21b: build upstream llama.cpp PR 29827 (CUDA: cap FA convert buffer for quantized KV) # and A/B its load-time GPU memory against a stock llama.cpp build. # Paths are generic; set $ROOT to your own working folder. $ErrorActionPreference='Continue' $ROOT='C:\rig' $B="$ROOT\build"; $log="$B\e21b_chain.log" function L($m){ "$(Get-Date -Format o) $m" | Out-File -FilePath $log -Append -Encoding utf8 } L "=== E21b chain start: no-admin CUDA 12.8 redist + build PR29827 fork + A/B buffer test ===" $CU="$ROOT\cuda-12.8"; $DL="$ROOT\cuda-dl"; New-Item -ItemType Directory -Force $CU,$DL | Out-Null $base='https://developer.download.nvidia.com/compute/cuda/redist/' $j=(Invoke-WebRequest -UseBasicParsing ($base+'redistrib_12.8.1.json')).Content | ConvertFrom-Json foreach($pk in 'cuda_nvcc','cuda_cudart','libcublas','cuda_cccl','cuda_nvrtc','cuda_nvml_dev','cuda_profiler_api','cuda_nvtx','cuda_crt','cuda_nvvm'){ $e=$j.$pk; if(-not $e){ L "pkg $pk not in manifest (ok)"; continue } $rp=$e.'windows-x86_64'.relative_path; if(-not $rp){ L "pkg $pk no windows build"; continue } $zip=Join-Path $DL (Split-Path $rp -Leaf) if(-not (Test-Path $zip)){ L "download $rp"; Invoke-WebRequest -UseBasicParsing ($base+$rp) -OutFile $zip } $x=Join-Path $DL ($pk+'_x'); if(Test-Path $x){Remove-Item $x -Recurse -Force} Expand-Archive $zip $x -Force $top=Get-ChildItem $x -Directory | select -First 1 Copy-Item "$($top.FullName)\*" $CU -Recurse -Force; L "installed $pk" } if(-not (Test-Path "$CU\bin\nvcc.exe")){ L "FAIL: nvcc missing"; L "=== E21bDONE (fail)"; exit 1 } & "$CU\bin\nvcc.exe" --version 2>&1 | Out-File $log -Append $vs=& "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -property installationPath # $src = checkout of the PR 29827 branch (feature/cuda-fattn-convert-buffer-cap) $src="$ROOT\llama.cpp\fork-29827"; $bd="$src\build-cuda" $cfg="call `"$vs\VC\Auxiliary\Build\vcvars64.bat`" && set CUDA_PATH=$CU&& set PATH=$CU\bin;C:\Program Files\CMake\bin;C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja;!PATH!&& cmake -S `"$src`" -B `"$bd`" -G Ninja -DCMAKE_BUILD_TYPE=Release -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=86 -DCUDAToolkit_ROOT=`"$CU`" -DCMAKE_CUDA_COMPILER=`"$CU/bin/nvcc.exe`" -DLLAMA_CURL=OFF -DLLAMA_BUILD_TESTS=OFF -DCMAKE_CUDA_FLAGS=-allow-unsupported-compiler && cmake --build `"$bd`" --target llama-server -j 12" L "configure+build start" cmd /v:on /c $cfg 2>&1 | Out-File "$B\e21b_build.log" -Encoding utf8 $srvP="$bd\bin\llama-server.exe" if(-not (Test-Path $srvP)){ L "FAIL: build produced no llama-server (see e21b_build.log)"; L "=== E21bDONE (fail)"; exit 1 } Copy-Item "$CU\bin\cudart64_12.dll","$CU\bin\cublas64_12.dll","$CU\bin\cublasLt64_12.dll" "$bd\bin\" -Force -ErrorAction SilentlyContinue L "build OK: $srvP" $out="$ROOT\results\e21b_pr29827"; New-Item -ItemType Directory -Force $out | Out-Null $res="$out\results.jsonl" $model="$ROOT\gguf\Qwen3.5-4B-Q4_K_M.gguf" $bins=@{stock="$ROOT\llama.cpp\llama-server.exe"; pr29827=$srvP} $cfgs=@( @{n='131k_q4_0_gpu_ub512';c=131072;k='q4_0';ub=512;host=$false}, @{n='131k_f16_gpu_ub512';c=131072;k='f16';ub=512;host=$false}, @{n='512k_q4_0_gpu_ub512';c=524288;k='q4_0';ub=512;host=$false}, @{n='512k_q4_0_gpu_ub128';c=524288;k='q4_0';ub=128;host=$false}, @{n='1m_q4_0_kvhost_ub512';c=1048576;k='q4_0';ub=512;host=$true} ) foreach($c in $cfgs){ foreach($bn in 'pr29827','stock'){ Get-Process llama-server -ErrorAction SilentlyContinue | Stop-Process -Force; Start-Sleep 5 $lf="$out\$($c.n)_$bn.log" $a=@('-m',$model,'-c',$c.c,'-ngl','99','-fa','on','-np','1','--port','8096','-ctk',$c.k,'-ctv',$c.k,'-ub',$c.ub,'-b','512','-t','8') if($c.host){$a+='--no-kv-offload'} $p=Start-Process -FilePath $bins[$bn] -ArgumentList $a -RedirectStandardError $lf -RedirectStandardOutput ($lf+'.out') -PassThru -NoNewWindow $t0=Get-Date; $ok=$false # NOTE: this check looks for 'server is listening' in stderr only, which did not match in our run, # so every row has loaded=false. The servers did load (in about 2 s); VRAM numbers are valid. while(((Get-Date)-$t0).TotalSeconds -lt 240 -and -not $p.HasExited){ if(Select-String -Path $lf -Pattern 'server is listening' -Quiet -ErrorAction SilentlyContinue){$ok=$true;break} if(Select-String -Path $lf -Pattern 'failed to allocate','out of memory' -Quiet -ErrorAction SilentlyContinue){break} Start-Sleep 3 } Start-Sleep 5 $used=(& nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits) -join '' $sh=$null; try{ $sh=[math]::Round(((Get-Counter "\GPU Process Memory(pid_$($p.Id)*)\Shared Usage" -ErrorAction Stop).CounterSamples | Measure-Object CookedValue -Sum).Sum/1MB) }catch{} try{Stop-Process -Id $p.Id -Force}catch{} $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}} $r=[ordered]@{cfg=$c.n;bin=$bn;ctx=$c.c;ub=$c.ub;ctk=$c.k;kv_host=$c.host;loaded=$ok; 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.]+)'); vram_used_mib=$used; shared_mib=$sh; t=(Get-Date -Format o)} ($r|ConvertTo-Json -Compress) | Out-File $res -Append -Encoding utf8; L ("result "+($r|ConvertTo-Json -Compress)) }} Get-Process llama-server -ErrorAction SilentlyContinue | Stop-Process -Force L "=== E21bDONE ==="