bradhutchings commited on
Commit
e4460e1
·
verified ·
1 Parent(s): 3ad8e7c

Upload Start-Telugu-Indic-gemma-7b-finetuned-sft-Navarasa-2.0.ps1

Browse files
Start-Telugu-Indic-gemma-7b-finetuned-sft-Navarasa-2.0.ps1 ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ $huggingFaceRepoURL = "https://huggingface.co/bradhutchings/Brads-LLMs"
2
+ $llamafile = "Brads-LLMs-llamafile.exe"
3
+
4
+ $modelFile = 'Telugu-Indic-gemma-7b-finetuned-sft-Navarasa-2.0-q8_0.gguf'
5
+ $contextSize = 8192
6
+ $maxContextSize = 8192
7
+ $threads = 4
8
+ $parallel = 2
9
+ $ngl = 9999
10
+ $gpu = 'disable' # disable, auto, amd, apple, nvidia
11
+
12
+ ################################################################################
13
+ # Script location.
14
+ ################################################################################
15
+
16
+ $myPath = $MyInvocation.MyCommand.Path
17
+ $myParent = Split-Path $mypath -Parent
18
+ $myGrandParent = Split-Path $myParent -Parent
19
+
20
+ <#
21
+ "`$myPath: $myPath"
22
+ "`$myParent: $myParent"
23
+ "`$myGrandParent: $myGrandParent"
24
+ #>
25
+
26
+ ################################################################################
27
+ # Overrides file.
28
+ ################################################################################
29
+
30
+ $overridesJsonFilename = 'overrides.json'
31
+ $overridesJsonFile = "$myParent\$overridesJsonFilename"
32
+ if (Test-Path -Path $overridesJsonFile -PathType Leaf) {
33
+ try {
34
+ $contextSizeSave = $contextSize
35
+ $threadsSave = $threads
36
+ $parallelSave = $parallel
37
+ $nglSave = $ngl
38
+ $gpuSave = $gpu
39
+
40
+ $overridesJsonFileData = Get-Content -Path $overridesJsonFile -Raw
41
+ $jsonData = ConvertFrom-Json -InputObject $overridesJsonFileData
42
+
43
+ if ($jsonData | Get-Member 'contextSize'){
44
+ $contextSize = [Math]::Min($jsonData.contextSize, $maxContextSize)
45
+ }
46
+ if ($jsonData | Get-Member 'threads'){
47
+ $threads = $jsonData.threads
48
+ }
49
+ if ($jsonData | Get-Member 'parallel'){
50
+ $parallel = $jsonData.parallel
51
+ }
52
+ if ($jsonData | Get-Member 'ngl'){
53
+ $ngl = $jsonData.ngl
54
+ }
55
+
56
+ if ($jsonData | Get-Member 'gpu'){
57
+ $gpu = $jsonData.gpu
58
+ }
59
+ }
60
+ catch {
61
+ $contextSize = $contextSizeSave
62
+ $threads = $threadsSave
63
+ $parallel = $parallelSave
64
+ $ngl = $nglSave
65
+ $gpu = $gpuSave
66
+ }
67
+
68
+ <#
69
+ "overrides.json:"
70
+ "- `$contextSize: $contextSize"
71
+ "- `$threads: $threads"
72
+ "- `$parallel: $parallel"
73
+ "- `$ngl: $ngl"
74
+ "- `$gpu: $gpu"
75
+ #>
76
+ }
77
+
78
+ ################################################################################
79
+ # Models folder.
80
+ ################################################################################
81
+
82
+ $dev = ".dev"
83
+ $models = "models"
84
+ $myDev = "$myParent\$dev"
85
+ $myModels = "$myParent\$models"
86
+ $devModels = "$myGrandParent\$models"
87
+ $useModels = $myModels
88
+
89
+ <#
90
+ echo "`$myDev: $myDev"
91
+ echo "`$myModels: $myModels"
92
+ echo "`$devModels: $devModels"
93
+ echo "`$useModels: $useModels"
94
+
95
+ "`$myDev exists: " + (Test-Path -Path $myDev -PathType Leaf)
96
+ "`$devModels exists: " + (Test-Path -Path $devModels -PathType Container)
97
+ #>
98
+
99
+ if ((Test-Path -Path $myDev -PathType Leaf) -and (Test-Path -Path $devModels -PathType Container)) {
100
+ $useModels = $devModels
101
+ }
102
+ else {
103
+ if (!(Test-Path -Path $myModels -PathType Container)) {
104
+ mkdir $myModels
105
+ }
106
+ $useModels = $myModels
107
+ }
108
+
109
+ <#
110
+ echo "Models: $useModels"
111
+ echo "--------------------"
112
+ #>
113
+
114
+ ################################################################################
115
+ # Download llamafile.exe if not present.
116
+ ################################################################################
117
+
118
+ $myLlamafile = "$myParent\$llamafile"
119
+ $myLlamafileTemp = "$myParent\$llamafile-temp"
120
+ $myLlamafileDownloadURL = "$huggingFaceRepoURL/resolve/main/$($llamafile)?download=true"
121
+
122
+ <#
123
+ "`$llamafile: $llamafile"
124
+ "`$myLlamafile: $myLlamafile"
125
+ "`$myLlamafileTemp: $myLlamafileTemp"
126
+ "`$myLlamafileDownloadURL: $myLlamafileDownloadURL"
127
+ #>
128
+
129
+ if (!(Test-Path -Path $myLlamafile -PathType Leaf)) {
130
+ # Download from Hugging Face
131
+
132
+ "Downloading $llamafile from Hugging Face."
133
+ # ""
134
+
135
+ $progresspreference = 'SilentlyContinue'
136
+ $result = Invoke-WebRequest -Method HEAD -Uri $myLlamafileDownloadURL -UseBasicParsing
137
+ $progresspreference = 'Continue'
138
+
139
+ $downloadSizeRaw = $result.Headers."Content-Length"
140
+ $downloadSize = [int]($downloadSizeRaw / (1024 * 1024))
141
+ $downloadSize = $downloadSize.ToString("N0") + " MB"
142
+
143
+ "- Preparing to download $downloadSize."
144
+ # ""
145
+ Start-Sleep -Seconds 2
146
+
147
+ $sb = {
148
+ $progresspreference = 'SilentlyContinue'
149
+ Invoke-WebRequest -Uri $using:myLlamafileDownloadURL -Outfile $using:myLlamafileTemp | Out-Null
150
+ }
151
+ Start-Job -Name 'Download' -ScriptBlock $sb | Out-Null
152
+
153
+ while ((Get-Job -Name 'Download').State -eq 'Running') {
154
+ if (Test-Path -Path $myLlamafileTemp) {
155
+ $downloadedBytesRaw = $((Get-ChildItem $myLlamafileTemp).Length)
156
+ $downloadedBytes = [int]($downloadedBytesRaw / (1024 * 1024))
157
+ $downloadedBytes = $downloadedBytes.ToString("N0") + " MB"
158
+ $downloadPercent = [int](100 * ($downloadedBytesRaw / $downloadSizeRaw))
159
+
160
+ Write-Progress -Activity "Downloading $llamafile" -Status ("Progress: " + $downloadPercent + "%") -CurrentOperation "$downloadedBytes / $downloadSize" -PercentComplete $downloadPercent
161
+ }
162
+ else {
163
+ Write-Progress -Activity "Downloading $llamafile" -Status "Progress:" -CurrentOperation "Starting..."
164
+ }
165
+ Start-Sleep -Milliseconds 200
166
+ }
167
+ Write-Progress -Activity "Downloaded Bytes" -Completed
168
+ Move-Item -Path $myLlamafileTemp -Destination $myLlamafile -Force
169
+
170
+ "- Finished downloading $llamafile from Hugging Face."
171
+ ""
172
+ Start-Sleep -Seconds 2
173
+ }
174
+
175
+ ################################################################################
176
+ # Download model file if not present.
177
+ ################################################################################
178
+
179
+ $myModel = "$useModels\$modelFile"
180
+ $myModelTemp = "$useModels\$modelFile-temp"
181
+ $myModelDownloadURL = "$huggingFaceRepoURL/resolve/main/models/$($modelFile)?download=true"
182
+
183
+ <#
184
+ "`$myModel: $myModel"
185
+ "`$myModelTemp: $myModelTemp"
186
+ "`$myModelDownloadURL: $myModelDownloadURL"
187
+ #>
188
+
189
+ if (!(Test-Path -Path $myModel -PathType Leaf)) {
190
+ # Download from Hugging Face
191
+
192
+ "Downloading $modelFile from Hugging Face."
193
+ # ""
194
+ $progresspreference = 'SilentlyContinue'
195
+ $result = Invoke-WebRequest -Method HEAD -Uri $myModelDownloadURL -UseBasicParsing
196
+ $progresspreference = 'Continue'
197
+
198
+ $downloadSizeRaw = $result.Headers."Content-Length"
199
+ $downloadSize = [int]($downloadSizeRaw / (1024 * 1024))
200
+ $downloadSize = $downloadSize.ToString("N0") + " MB"
201
+
202
+ "- Preparing to download $downloadSize."
203
+ # ""
204
+ Start-Sleep -Seconds 2
205
+
206
+ $sb = {
207
+ $progresspreference = 'SilentlyContinue'
208
+ Invoke-WebRequest -Uri $using:myModelDownloadURL -Outfile $using:myModelTemp | Out-Null
209
+ }
210
+ Start-Job -Name 'Download' -ScriptBlock $sb | Out-Null
211
+
212
+ while ((Get-Job -Name 'Download').State -eq 'Running') {
213
+ if (Test-Path -Path $myModelTemp) {
214
+ $downloadedBytesRaw = $((Get-ChildItem $myModelTemp).Length)
215
+ $downloadedBytes = [int]($downloadedBytesRaw / (1024 * 1024))
216
+ $downloadedBytes = $downloadedBytes.ToString("N0") + " MB"
217
+ $downloadPercent = [int](100 * ($downloadedBytesRaw / $downloadSizeRaw))
218
+
219
+ Write-Progress -Activity "Downloading $modelFile" -Status ("Progress: " + $downloadPercent + "%") -CurrentOperation "$downloadedBytes / $downloadSize" -PercentComplete $downloadPercent
220
+ }
221
+ else {
222
+ Write-Progress -Activity "Downloading $modelFile" -Status "Progress:" -CurrentOperation "Starting..."
223
+ }
224
+ Start-Sleep -Seconds 4
225
+ }
226
+ Write-Progress -Activity "Downloaded Bytes" -Completed
227
+ Move-Item -Path $myModelTemp -Destination $myModel -Force
228
+
229
+ "- Finished downloading $modelFile from Hugging Face."
230
+ ""
231
+ Start-Sleep -Seconds 2
232
+ }
233
+
234
+ ################################################################################
235
+ # if llamafile and model are present, launch llamafile
236
+ ################################################################################
237
+
238
+ if ((Test-Path -Path "$myLlamafile" -PathType Leaf) -and (Test-Path -Path "$myModel" -PathType Leaf)) {
239
+ $process = Start-Process "$myLlamafile" -ArgumentList "-m `"$myModel`" --ctx-size $contextSize --threads $threads --parallel $parallel --server -ngl $ngl --gpu $gpu" -PassThru -NoNewWindow
240
+ $process.PriorityClass = [System.Diagnostics.ProcessPriorityClass]::High
241
+ }
242
+ else {
243
+ "There was an unkown problem downloading or saving the model."
244
+ Start-Sleep -s 20
245
+ }