Skip to content

Instantly share code, notes, and snippets.

@MasterGroosha
Last active June 10, 2026 13:45
Show Gist options
  • Select an option

  • Save MasterGroosha/b8e0f976dcc197fb2d30f79a504e5cf4 to your computer and use it in GitHub Desktop.

Select an option

Save MasterGroosha/b8e0f976dcc197fb2d30f79a504e5cf4 to your computer and use it in GitHub Desktop.
llama.cpp updater on Windows

This is my approach to self-updating llama.cpp.

Initial setup

  1. Create all the files listed in the folder_structure.txt file from this gist.
  2. Open the latest llama.cpp release on GitHub, for example: https://github.com/ggml-org/llama.cpp/releases/tag/b9587
  3. Download the required archives. In my case, these were:
    • llama-b9587-bin-win-cuda-13.3-x64.zip
    • cudart-llama-bin-win-cuda-13.3-x64.zip
  4. Extract both archives into the files folder.
  5. Copy the SHA of cudart-llama-bin-win-cuda-13.3-x64.zip to cuda-dll.sha256. In my case, it was: sha256:1462a050eb4c684921ba51dcc4cc488a036674c3e73e9945ee705b854808d03e
  6. In version.txt, place the name of the most recent release. In my case, this was: b9587

Updating

To update, simply run the update.bat script. It automatically checks for a new version and skips downloading cudart-llama-bin-win-cuda-13.3-x64.zip if the SHA has not changed. This saves roughly 370 MB of unnecessary downloads.

sha256:1462a050eb4c684921ba51dcc4cc488a036674c3e73e9945ee705b854808d03e
files (dir)
cuda-dll.sha256
update.bat
version.txt
@echo off
setlocal
powershell -NoProfile -ExecutionPolicy Bypass -Command "$p='%~f0'; $c=Get-Content -Raw -LiteralPath $p; $m='### POWERSHELL ###'; $i=$c.LastIndexOf($m); if ($i -lt 0) { throw 'PowerShell payload marker was not found.' }; Invoke-Expression $c.Substring($i + $m.Length)"
if errorlevel 1 (
echo Update failed.
exit /b 1
)
exit /b 0
### POWERSHELL ###
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
$root = (Get-Location).Path
$filesDir = Join-Path $root 'files'
$versionFile = Join-Path $root 'version.txt'
$cudaShaFile = Join-Path $root 'cuda-dll.sha256'
$repo = 'ggml-org/llama.cpp'
$headers = @{ 'User-Agent' = 'llama-cpp-windows-cuda-updater' }
function Get-AssetDigest {
param([object] $Asset)
if ($Asset.PSObject.Properties.Name -contains 'digest' -and $Asset.digest) {
return [string] $Asset.digest
}
return ''
}
function Find-OneAsset {
param(
[object[]] $Assets,
[string] $Kind,
[string] $Pattern
)
$matches = @(
$Assets |
Where-Object { $_.name -like $Pattern } |
Sort-Object name -Descending
)
if ($matches.Count -eq 0) {
throw ('Could not find {0} asset matching {1}' -f $Kind, $Pattern)
}
if ($matches.Count -gt 1) {
Write-Host ('Found several {0} assets; using {1}' -f $Kind, $matches[0].name)
}
return $matches[0]
}
if (-not (Test-Path -LiteralPath $filesDir)) {
New-Item -ItemType Directory -Path $filesDir | Out-Null
}
$currentVersion = ''
if (Test-Path -LiteralPath $versionFile) {
$currentVersion = (Get-Content -Raw -LiteralPath $versionFile).Trim()
}
$currentCudaDigest = ''
if (Test-Path -LiteralPath $cudaShaFile) {
$currentCudaDigest = (Get-Content -Raw -LiteralPath $cudaShaFile).Trim()
}
Write-Host ('Checking latest release for {0}...' -f $repo)
$release = Invoke-RestMethod `
-Headers $headers `
-Uri ('https://api.github.com/repos/{0}/releases/latest' -f $repo)
$latestVersion = [string] $release.tag_name
if ([string]::IsNullOrWhiteSpace($latestVersion)) {
throw 'GitHub response did not contain tag_name'
}
$assets = @($release.assets)
$llamaAsset = Find-OneAsset `
-Assets $assets `
-Kind 'llama.cpp CUDA 13 Windows x64' `
-Pattern ('llama-{0}-bin-win-cuda-13.*-x64.zip' -f $latestVersion)
$cudaAsset = Find-OneAsset `
-Assets $assets `
-Kind 'CUDA 13 DLL' `
-Pattern 'cudart-llama-bin-win-cuda-13.*-x64.zip'
$cudaDigest = Get-AssetDigest $cudaAsset
$versionChanged = ($latestVersion -ne $currentVersion)
$cudaChanged = $true
if ($cudaDigest -and $currentCudaDigest -and ($cudaDigest -eq $currentCudaDigest)) {
$cudaChanged = $false
}
if (-not $versionChanged -and -not $cudaChanged) {
Write-Host ('Already up to date: {0}' -f $latestVersion)
exit 0
}
if (-not $versionChanged -and $cudaDigest -and -not $currentCudaDigest) {
Set-Content -Encoding ASCII -NoNewline -Path $cudaShaFile -Value $cudaDigest
Write-Host ('Version is current ({0}); recorded CUDA DLL digest.' -f $latestVersion)
exit 0
}
$tmp = Join-Path $env:TEMP ('llama-cpp-update-' + [guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Path $tmp | Out-Null
try {
if ($versionChanged) {
$llamaZip = Join-Path $tmp $llamaAsset.name
Write-Host ('Downloading {0}...' -f $llamaAsset.name)
Invoke-WebRequest `
-Headers $headers `
-Uri $llamaAsset.browser_download_url `
-OutFile $llamaZip
Write-Host 'Extracting llama.cpp binaries...'
Expand-Archive -Force -Path $llamaZip -DestinationPath $tmp
Copy-Item `
-Force `
-Recurse `
-Path (Join-Path $tmp '*') `
-Destination $filesDir `
-Exclude '*.zip'
}
if ($cudaChanged) {
if (-not $cudaDigest) {
Write-Host 'GitHub did not provide a digest for the CUDA DLL asset; downloading DLL archive.'
}
$cudaZip = Join-Path $tmp $cudaAsset.name
Write-Host ('Downloading {0}...' -f $cudaAsset.name)
Invoke-WebRequest `
-Headers $headers `
-Uri $cudaAsset.browser_download_url `
-OutFile $cudaZip
Write-Host 'Extracting CUDA DLLs...'
Expand-Archive -Force -Path $cudaZip -DestinationPath $tmp
Copy-Item `
-Force `
-Recurse `
-Path (Join-Path $tmp '*') `
-Destination $filesDir `
-Exclude '*.zip'
}
Set-Content -Encoding ASCII -NoNewline -Path $versionFile -Value $latestVersion
if ($cudaDigest) {
Set-Content -Encoding ASCII -NoNewline -Path $cudaShaFile -Value $cudaDigest
}
Write-Host ('Updated to {0}' -f $latestVersion)
}
finally {
if (Test-Path -LiteralPath $tmp) {
Remove-Item -Recurse -Force -LiteralPath $tmp
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment