nextgpt-chapter6-report / code /scripts /start_cpu_preview.ps1
CollinMa's picture
Publish NExT-GPT course code and actual execution records
15c46ce verified
Raw History Blame Contribute Delete
1.7 kB
param(
[switch]$Install,
[switch]$CheckOnly
)
$ErrorActionPreference = 'Stop'
$projectRoot = Split-Path -Parent $PSScriptRoot
$runtimePath = Join-Path $projectRoot '.runtime'
$pythonPath = Join-Path $runtimePath 'python.exe'
Push-Location $projectRoot
try {
if (-not (Test-Path -LiteralPath $pythonPath)) {
if (-not $Install) { throw 'Runtime missing. Run this script with -Install first.' }
$condaCommand = Get-Command conda -ErrorAction Stop
& $condaCommand create --prefix $runtimePath python=3.10 pip -y
if ($LASTEXITCODE -ne 0) { throw 'Conda environment creation failed.' }
}
if ($Install) {
& $pythonPath -m pip install pip==24.3.1 setuptools==69.5.1 wheel==0.44.0
if ($LASTEXITCODE -ne 0) { throw 'Build tools installation failed.' }
& $pythonPath -m pip install torch==1.13.1+cpu torchvision==0.14.1+cpu torchaudio==0.13.1+cpu --extra-index-url https://download.pytorch.org/whl/cpu
if ($LASTEXITCODE -ne 0) { throw 'CPU PyTorch installation failed.' }
& $pythonPath -m pip install -r requirements.txt
if ($LASTEXITCODE -ne 0) { throw 'Runtime dependencies installation failed.' }
& $pythonPath -m pip check
if ($LASTEXITCODE -ne 0) { throw 'Dependency validation failed.' }
}
if ($CheckOnly) {
& $pythonPath -X utf8 scripts/check_environment.py
if ($LASTEXITCODE -ne 0) { throw 'Environment check failed.' }
} else {
# start-preview.cmd scopes these environment settings with setlocal.
& (Join-Path $projectRoot 'start-preview.cmd')
if ($LASTEXITCODE -ne 0) { throw 'CPU preview failed.' }
}
} finally {
Pop-Location
}