bradhutchings commited on
Commit
782b123
·
verified ·
1 Parent(s): 3862eee

Delete Start-Mistral-AI-Mistral-7B-Instruct-v0.2.ps1

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