Repository navigation
Expand file tree
/
Copy pathinstall.ps1
More file actions
153 lines (134 loc) · 7.1 KB
/
Copy pathinstall.ps1
File metadata and controls
153 lines (134 loc) · 7.1 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<#
Idempotent setup for the SHARP Image2Splat service on a CUDA GPU host.
Safe to re-run. It will:
1. verify Python 3.13 + git + NVIDIA driver
2. clone apple/ml-sharp as a sibling of this repo and pin commit cdb4ddc6
3. create a Python 3.13 venv at <repo>/.venv (reused if present)
4. pip install ml-sharp deps, -e ml-sharp, -e this repo, service deps
5. FORCE the CUDA torch build (ml-sharp's requirements pull CPU-only torch)
6. install OpenEXR (depth reader; imageio has no EXR backend on Windows)
7. verify torch.cuda.is_available() AND `import sharp, sharp_ext`
Usage: powershell -ExecutionPolicy Bypass -File service\install.ps1
# older CUDA: -File service\install.ps1 -TorchIndex https://download.pytorch.org/whl/cu121
#>
param(
# Match your installed CUDA runtime: cu128 (12.8), cu126 (12.6), cu121 (12.1), cu118 (11.8).
[string]$TorchIndex = "https://download.pytorch.org/whl/cu128",
[string]$TorchSpec = "torch==2.8.0 torchvision==0.23.0",
# Interpreter to build the venv from. Default: auto-detect (prefers 3.13).
[string]$PythonExe = ""
)
$ErrorActionPreference = "Stop"
function Resolve-PythonExe {
<# Find an interpreter to build the venv from: prefer 3.13 (the tested version),
otherwise the newest 3.11+. Probes the `py` launcher and plain python names. #>
param([string]$Explicit)
$ErrorActionPreference = "SilentlyContinue" # function-scoped: probing is allowed to fail
if ($Explicit) {
$cmd = Get-Command $Explicit -ErrorAction SilentlyContinue
$exe = if ($cmd) { $cmd.Source } else { $Explicit }
if (-not (Test-Path $exe)) { throw "-PythonExe '$Explicit' not found." }
return $exe
}
# No quotes in the probe: PowerShell 5.1 mangles embedded double quotes passed to native exes.
$probe = 'import sys; print(sys.version_info[0]); print(sys.version_info[1]); print(sys.executable)'
$found = @()
if (Get-Command py -ErrorAction SilentlyContinue) {
foreach ($sw in @("-3.13", "-3")) {
$out = @(& py $sw -c $probe 2>$null)
if ($LASTEXITCODE -eq 0 -and $out.Count -ge 3) {
$found += [pscustomobject]@{ Ver = [version]("" + $out[0] + "." + $out[1]); Exe = $out[2] }
}
}
}
foreach ($n in @("python3.13", "python3", "python")) {
$c = Get-Command $n -ErrorAction SilentlyContinue
if (-not $c) { continue }
$out = @(& $c.Source -c $probe 2>$null)
if ($LASTEXITCODE -eq 0 -and $out.Count -ge 3) {
$found += [pscustomobject]@{ Ver = [version]("" + $out[0] + "." + $out[1]); Exe = $out[2] }
}
}
$exact = $found | Where-Object { $_.Ver.Major -eq 3 -and $_.Ver.Minor -eq 13 } | Select-Object -First 1
if ($exact) { return $exact.Exe }
$alt = $found | Where-Object { $_.Ver.Major -eq 3 -and $_.Ver.Minor -ge 11 } |
Sort-Object Ver -Descending | Select-Object -First 1
if ($alt) {
Write-Warning ("Python 3.13 not found; using " + $alt.Ver + " (" + $alt.Exe + "). 3.13 is the tested version.")
return $alt.Exe
}
throw @"
No suitable Python found (3.13 preferred, 3.11+ accepted).
Install it, then open a NEW terminal (so PATH refreshes) and re-run:
winget install -e --id Python.Python.3.13
-- or download from https://www.python.org/downloads/ (tick 'Add python.exe to PATH')
Already have one somewhere? Point at it directly:
... -PythonExe "C:\path\to\python.exe"
"@
}
$ServiceDir = $PSScriptRoot
$RepoRoot = Split-Path -Parent $ServiceDir
$MlSharp = Join-Path (Split-Path -Parent $RepoRoot) "ml-sharp"
$Venv = Join-Path $RepoRoot ".venv"
$VenvPy = Join-Path $Venv "Scripts\python.exe"
$PinCommit = "cdb4ddc6"
Write-Host "== SHARP service install ==" -ForegroundColor Cyan
Write-Host "repo: $RepoRoot"
Write-Host "ml-sharp: $MlSharp"
Write-Host "venv: $Venv"
# 1) Prereqs -----------------------------------------------------------------
Write-Host "`n[1/7] Checking prerequisites ..."
$Python = Resolve-PythonExe -Explicit $PythonExe
Write-Host (" python: " + $Python)
& $Python --version
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
throw "git not found. Install it (winget install -e --id Git.Git), open a NEW terminal, and re-run."
}
try { & nvidia-smi --query-gpu=name --format=csv,noheader | Select-Object -First 1 }
catch { Write-Warning "nvidia-smi not found; CUDA may be unavailable." }
# 2) ml-sharp at the pinned commit ------------------------------------------
Write-Host "`n[2/7] ml-sharp @ $PinCommit ..."
if (-not (Test-Path $MlSharp)) {
& git clone https://github.com/apple/ml-sharp.git $MlSharp
if ($LASTEXITCODE -ne 0) { throw "git clone ml-sharp failed." }
} else {
Write-Host " ml-sharp already present; fetching to ensure the pin is available ..."
& git -C $MlSharp fetch --quiet
}
& git -C $MlSharp checkout $PinCommit
if ($LASTEXITCODE -ne 0) { throw "git checkout $PinCommit failed." }
# 3) venv --------------------------------------------------------------------
Write-Host "`n[3/7] Python 3.13 venv ..."
if (-not (Test-Path $VenvPy)) {
& $Python -m venv $Venv
if ($LASTEXITCODE -ne 0) { throw "venv creation failed." }
} else {
Write-Host " venv already exists; reusing."
}
& $VenvPy -m pip install --upgrade pip | Out-Null
# 4) installs ----------------------------------------------------------------
Write-Host "`n[4/7] Installing ml-sharp + extension + service deps ..."
& $VenvPy -m pip install -r (Join-Path $MlSharp "requirements.txt")
if ($LASTEXITCODE -ne 0) { throw "pip install ml-sharp requirements failed." }
& $VenvPy -m pip install -e $MlSharp
if ($LASTEXITCODE -ne 0) { throw "pip install -e ml-sharp failed." }
& $VenvPy -m pip install -e $RepoRoot
if ($LASTEXITCODE -ne 0) { throw "pip install -e <repo> failed." }
& $VenvPy -m pip install -r (Join-Path $ServiceDir "requirements.txt")
if ($LASTEXITCODE -ne 0) { throw "pip install service requirements failed." }
# 5) FORCE CUDA torch (ml-sharp reqs install CPU-only torch) ------------------
Write-Host "`n[5/7] Forcing CUDA torch build ($TorchIndex) ..."
& $VenvPy -m pip install --force-reinstall ($TorchSpec.Trim() -split '\s+') --index-url $TorchIndex
if ($LASTEXITCODE -ne 0) { throw "CUDA torch install failed." }
# 6) OpenEXR (depth reader) --------------------------------------------------
Write-Host "`n[6/7] Installing OpenEXR ..."
& $VenvPy -m pip install "OpenEXR>=3.4"
if ($LASTEXITCODE -ne 0) { throw "OpenEXR install failed." }
# 7) verify ------------------------------------------------------------------
Write-Host "`n[7/7] Verifying ..."
& $VenvPy -c "import torch; assert torch.cuda.is_available(), 'CUDA not available after install'; print('torch', torch.__version__, 'cuda', torch.cuda.is_available())"
if ($LASTEXITCODE -ne 0) { throw "CUDA verification failed." }
& $VenvPy -c "import sharp, sharp_ext; from sharp_ext import predict_image_with_depth, load_depth_exr; print('sharp + sharp_ext import OK')"
if ($LASTEXITCODE -ne 0) { throw "import verification failed." }
Write-Host "`n== install complete ==" -ForegroundColor Green
Write-Host "Next: powershell -ExecutionPolicy Bypass -File service\run.ps1"