Skip to content

Commit 27f09fd

Browse files
committed
Add initial version
1 parent cd8acbb commit 27f09fd

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

download_model_sources.ps1

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
$stopwatch = [System.Diagnostics.Stopwatch]::startNew()
2+
3+
$sourceDirectory = "R:\AI\LLM\source"
4+
5+
$naturalSort = { [regex]::Replace($_, '\d+', { $args[0].Value.PadLeft(20) }) }
6+
7+
$repositoryDirectories = Get-ChildItem -Directory $sourceDirectory | Sort-Object $naturalSort
8+
9+
Write-Host "Downloading $($repositoryDirectories.Length) repositories..." -ForegroundColor "Yellow"
10+
11+
ForEach ($repositoryDirectory in $repositoryDirectories) {
12+
13+
$repositoryDirectoryPath = Join-Path -Path $sourceDirectory -ChildPath $repositoryDirectory
14+
15+
$repositoryOriginURI = git -C "${repositoryDirectoryPath}" config --get remote.origin.url
16+
17+
Write-Host "Downloading ${repositoryOriginURI}..." -ForegroundColor "DarkYellow"
18+
19+
Write-Host "Pruning incomplete large files..." -ForegroundColor "Yellow"
20+
Remove-Item "${repositoryDirectoryPath}\.git\lfs\incomplete\*" -Recurse -Force
21+
22+
Write-Host "Resetting working directory..." -ForegroundColor "Yellow"
23+
git -C "${repositoryDirectoryPath}" reset --hard HEAD
24+
25+
Write-Host "Pulling regular files..." -ForegroundColor "Yellow"
26+
27+
# We do not want the regular git pull command to also fetch
28+
# large lfs files, because it has no progress indicator.
29+
$env:GIT_LFS_SKIP_SMUDGE="1"
30+
31+
git -C "${repositoryDirectoryPath}" pull
32+
33+
Write-Host "Pulling large files..." -ForegroundColor "Yellow"
34+
git -C "${repositoryDirectoryPath}" -c lfs.concurrenttransfers=1 lfs pull
35+
}
36+
37+
$stopwatch.Stop()
38+
$durationInSeconds = [Math]::Floor([Decimal]($stopwatch.Elapsed.TotalSeconds))
39+
40+
Write-Host "Successfully finished the download in ${durationInSeconds} seconds." -ForegroundColor "Green"

quantize_weights_for_llama.cpp.ps1

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
$stopwatch = [System.Diagnostics.Stopwatch]::startNew()
2+
3+
$llamaCppDirectory = "D:\Privat\GitHub\windows_llama.cpp\vendor\llama.cpp"
4+
$sourceDirectory = "R:\AI\LLM\source"
5+
$targetDirectory = "R:\AI\LLM\gguf"
6+
$cacheDirectory = "E:\cache"
7+
8+
$exclude = @()
9+
10+
$types = @(
11+
# "q2_K"
12+
# "q3_K"
13+
# "q3_K_L"
14+
# "q3_K_M"
15+
# "q3_K_S"
16+
# "q4_0"
17+
# "q4_1"
18+
# "q4_K"
19+
"q4_K_M"
20+
# "q4_K_S"
21+
# "q5_0"
22+
# "q5_1"
23+
# "q5_K"
24+
# "q5_K_M"
25+
# "q5_K_S"
26+
# "q6_K"
27+
# "q8_0"
28+
)
29+
30+
$naturalSort = { [regex]::Replace($_, '\d+', { $args[0].Value.PadLeft(20) }) }
31+
32+
$repositoryDirectories = Get-ChildItem -Directory $sourceDirectory -Exclude $exclude -Name | Sort-Object $naturalSort
33+
34+
Write-Host "Quantizing $($repositoryDirectories.Length) large language models." -ForegroundColor "Yellow"
35+
36+
conda activate llama.cpp
37+
38+
ForEach ($repositoryName in $repositoryDirectories) {
39+
40+
$sourceDirectoryPath = Join-Path -Path $sourceDirectory -ChildPath $repositoryName
41+
$targetDirectoryPath = Join-Path -Path $targetDirectory -ChildPath $repositoryName
42+
43+
if (!(Test-Path -Path $targetDirectoryPath)) {
44+
New-Item -Path $targetDirectory -Name $repositoryName -ItemType "directory"
45+
}
46+
47+
Write-Host "Working on ${repositoryName}..." -ForegroundColor "DarkYellow"
48+
49+
# We are creating the intermediate unquantized model in a dedicated cache directory
50+
# so that it can be locatend on another drive to improve the quantization speed.
51+
$unquantizedModelPath = Join-Path -Path $cacheDirectory -ChildPath "${repositoryName}.model-unquantized.gguf"
52+
53+
ForEach ($type in $types) {
54+
55+
$quantizedModelPath = Join-Path -Path $targetDirectoryPath -ChildPath "model-quantized-${type}.gguf"
56+
57+
if (!(Test-Path -Path $quantizedModelPath) -and !(Test-Path -Path $unquantizedModelPath)) {
58+
59+
Write-Host "Converting ${sourceDirectoryPath} to ${unquantizedModelPath}..." -ForegroundColor "DarkYellow"
60+
61+
$convertCommand = "${llamaCppDirectory}\convert.py --outfile $unquantizedModelPath $sourceDirectoryPath"
62+
63+
Invoke-Expression "python $convertCommand"
64+
}
65+
66+
if (!(Test-Path -Path $quantizedModelPath)) {
67+
68+
$quantizeCommand = "${llamaCppDirectory}\build\bin\Release\quantize.exe"
69+
70+
Write-Host "Quantizing ${unquantizedModelPath} to ${quantizedModelPath}..." -ForegroundColor "DarkYellow"
71+
72+
Invoke-Expression "$quantizeCommand $unquantizedModelPath $quantizedModelPath $type"
73+
}
74+
}
75+
76+
if ((Test-Path -Path $unquantizedModelPath)) {
77+
78+
Write-Host "Removing intermediate unquantized model ${unquantizedModelPath}..." -ForegroundColor "DarkYellow"
79+
Remove-Item "${unquantizedModelPath}" -Recurse -Force
80+
}
81+
}
82+
83+
$stopwatch.Stop()
84+
$durationInSeconds = [Math]::Floor([Decimal]($stopwatch.Elapsed.TotalSeconds))
85+
86+
Write-Host "Successfully finished the quantization in ${durationInSeconds} seconds." -ForegroundColor "Yellow"

0 commit comments

Comments
 (0)