-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathstart.ps1
More file actions
122 lines (102 loc) · 4.23 KB
/
start.ps1
File metadata and controls
122 lines (102 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
param (
[Parameter(Mandatory = $true)]
[int]$Port # Local port to run this app on.
)
$ErrorActionPreference = "Stop"
# Is debug mode enabled?
$debug = (Test-Path "DEBUG") -or (Test-Path "DEBUG.txt")
$DebugPreference = if ($debug) { "Continue" } else { "SilentlyContinue" }
$title = (Get-Content metadata\NAME, metadata\VERSION) -join ' '
# Console is hidden by its title once webview is displayed (see console.cpp)
# unless debug mode is enabled:
if ($debug) { $Host.UI.RawUI.WindowTitle = "Debug $title" }
else { $Host.UI.RawUI.WindowTitle = $title }
# Project homepage URL.
$homeUrl = Get-Content "metadata\HOME_URL"
trap {
Write-Host $_.Exception.Message -ForegroundColor Red
Write-Host "Please report issue at $homeUrl/issues" -ForegroundColor Cyan
Write-Host "You can now close this window..." -NoNewline
$null = Read-Host
exit 1
}
Write-Host "Detecting GPUs..." -ForegroundColor Blue
. "source\ps\gpu_detection.ps1"
try {
$gpus = Get-Gpus
if ($gpus.Count -eq 0) { throw "No GPUs found" }
Write-Debug "Well detected $($gpus.Count) GPUs:"
foreach ($gpu in $gpus) {
Write-Debug "- $($gpu.Name) ($($gpu.Memory / 1GB)GB)"
}
$gpu = $gpus | Sort-Object Memory -Descending | Select-Object -First 1
Write-Host "$($gpu.Name) selected."
}
catch {
Write-Warning "GPU detection failed, venv may not be optimized."
$gpu = [Gpu]@{
Name = "None"
Memory = 0
Vendor = "Unknown"
}
}
. "source\ps\app_invoking.ps1"
# Path to uv executable distributed with this app.
# So we don't rely on a global uv that maybe uninstalled outside of this app.
$uv = "tools\astral\uv.exe"
if (-not (Test-Path $uv)) {
throw "uv executable not found at $uv"
}
# Python venv was previously optimized?
if (Test-Path ".venv\optimized") {
Write-Host "Optimized Python venv found. Skipping install." -ForegroundColor Green
try {
Write-Host "Loading model, please wait..." -ForegroundColor Blue
Invoke-App -Port $Port -Uv $uv
exit # to not go to install since app ran successfully if we reach this stage.
}
catch {
Write-Warning "Failed to run app, let's try reinstall."
}
}
Write-Host "Installing..." -ForegroundColor Blue
. "source\ps\venv_creation.ps1"
. "source\ps\package_utils.ps1"
# Python venv is currently optimized?
$optimized = $false
if ($gpu.Vendor -eq "NVIDIA") {
New-VirtualEnv -Python "3.13.11" -Uv $uv
try {
Write-Host "Trying optimized setup for your NVIDIA GPU..."
Install-Torch -Version "2.10.0+cu130" -IndexUrl "cu130" -Uv $Uv
Install-Package -Id "triton-windows" -Version "3.6.0.post26" -Uv $Uv
Install-Archive -Source "https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.7.13/flash_attn-2.8.3+cu130torch2.10-cp313-cp313-win_amd64.whl" -Uv $Uv
Install-Archive -Source "diffusers @ https://github.com/huggingface/diffusers/archive/b757035df6fe080b56a672c4000e458bb442821a.zip" -Uv $Uv
Install-Package -Id "peft" -Version "0.18.1" -Uv $Uv
Install-Package -Id "sdnq" -Version "0.1.6" -Uv $Uv
Install-Package -Id "platformdirs" -Version "4.9.4" -Uv $Uv
Install-Package -Id "gradio" -Version "6.10.0" -Uv $Uv
$optimized = $true
}
catch {
Write-Warning "NVIDIA setup failed, falling back to default setup."
}
}
if ($optimized) {
# We leave a marker in venv for next start to skip installation.
New-Item -ItemType File -Path ".venv\optimized" -Force | Out-Null
}
else {
# This marker is removed by `uv venv --clear`, that's consistent.
New-VirtualEnv -Python "3.13.11" -Uv $uv
Write-Host "Trying default setup..."
Install-Torch -Version "2.10.0" -Backend "auto" -Uv $Uv
Install-Archive -Source "diffusers @ https://github.com/huggingface/diffusers/archive/b757035df6fe080b56a672c4000e458bb442821a.zip" -Uv $Uv
Install-Package -Id "peft" -Version "0.18.1" -Uv $Uv
Install-Package -Id "sdnq" -Version "0.1.6" -Uv $Uv
Install-Package -Id "platformdirs" -Version "4.9.4" -Uv $Uv
Install-Package -Id "gradio" -Version "6.10.0" -Uv $Uv
}
Write-Host "Installation complete." -ForegroundColor Green
Write-Host "Loading model... We are nearly there!" -ForegroundColor Blue
Invoke-App -Port $Port -Uv $uv