@@ -15,6 +15,8 @@ $llamaCppDirectory = Resolve-Path -Path $env:LLAMA_CPP_DIRECTORY
1515$sourceDirectory = Resolve-Path - Path $env: SOURCE_DIRECTORY
1616$targetDirectory = Resolve-Path - Path $env: TARGET_DIRECTORY
1717$cacheDirectory = Resolve-Path - Path $env: CACHE_DIRECTORY
18+ $trainingDataPath = Resolve-Path - Path $env: TRAINING_DATA
19+ $cleanCache = [System.Convert ]::ToBoolean($env: CLEAN_CACHE )
1820$quantizationTypes = $env: QUANTIZATION_TYPES -split ' ,'
1921
2022$naturalSort = { [regex ]::Replace($_ , ' \d+' , { $args [0 ].Value.PadLeft(20 ) }) }
@@ -39,6 +41,7 @@ ForEach ($repositoryName in $repositoryDirectories) {
3941 Write-Host " Working on ${repositoryName} ..." - ForegroundColor " DarkYellow"
4042
4143 $unquantizedModelPath = Join-Path - Path $cacheDirectory - ChildPath " ${repositoryName} .model-unquantized.gguf"
44+ $importanceMatrixPath = Join-Path - Path $cacheDirectory - ChildPath " ${repositoryName} .importance-matrix.dat"
4245
4346 ForEach ($type in $quantizationTypes ) {
4447
@@ -53,6 +56,15 @@ ForEach ($repositoryName in $repositoryDirectories) {
5356 Invoke-Expression " $convertCommand --outfile `" ${unquantizedModelPath} `" `" ${sourceDirectoryPath} `" "
5457 }
5558
59+ if ((" IQ2_XXS IQ2_XS IQ3_XXS" .Contains($type )) -and ! (Test-Path - Path $importanceMatrixPath )) {
60+
61+ Write-Host " Computing importance matrix for ${unquantizedModelPath} at ${importanceMatrixPath} ..." - ForegroundColor " DarkYellow"
62+
63+ $imatrixCommand = " ${llamaCppDirectory} \build\bin\Release\imatrix.exe"
64+
65+ Invoke-Expression " $imatrixCommand -m `" ${unquantizedModelPath} `" -f `" ${trainingDataPath} `" -o `" ${importanceMatrixPath} `" "
66+ }
67+
5668 if (! (Test-Path - Path $quantizedModelPath )) {
5769
5870 Write-Host " Quantizing ${unquantizedModelPath} to ${quantizedModelPath} ..." - ForegroundColor " DarkYellow"
@@ -63,11 +75,17 @@ ForEach ($repositoryName in $repositoryDirectories) {
6375 }
6476 }
6577
66- if ((Test-Path - Path $unquantizedModelPath )) {
78+ if ($cleanCache -and (Test-Path - Path $unquantizedModelPath )) {
6779
6880 Write-Host " Removing intermediate unquantized model ${unquantizedModelPath} ..." - ForegroundColor " DarkYellow"
6981 Remove-Item " ${unquantizedModelPath} " - Recurse - Force
7082 }
83+
84+ if ($cleanCache -and (Test-Path - Path $importanceMatrixPath )) {
85+
86+ Write-Host " Removing intermediate unquantized model ${importanceMatrixPath} ..." - ForegroundColor " DarkYellow"
87+ Remove-Item " ${importanceMatrixPath} " - Recurse - Force
88+ }
7189}
7290
7391$stopwatch.Stop ()
0 commit comments