From 1fc591e44030347267f363490c3cc9afea62c801 Mon Sep 17 00:00:00 2001 From: ClashSAN <98228077+ClashSAN@users.noreply.github.com> Date: Thu, 5 Jan 2023 02:00:06 +0000 Subject: [PATCH] add .ps1 powershell launch scripts --- Install-and-Run-on-NVidia-GPUs.md | 155 ++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) diff --git a/Install-and-Run-on-NVidia-GPUs.md b/Install-and-Run-on-NVidia-GPUs.md index f15893b..db4878a 100644 --- a/Install-and-Run-on-NVidia-GPUs.md +++ b/Install-and-Run-on-NVidia-GPUs.md @@ -6,6 +6,161 @@ Run `webui-user.bat` from Windows Explorer as normal, ***non-administrator***, u See [Troubleshooting](Troubleshooting) section for what to do if things go wrong. +#### Powershell + +Alternatively, here are 2 launch scripts for using powershell: + +
Scripts (Click to show) + +#### webui.ps1 +``` +if ($env:PYTHON -eq "" -or $env:PYTHON -eq $null) { + $PYTHON = "Python.exe" +} else { + $PYTHON = $env:PYTHON +} + +if ($env:VENV_DIR -eq "" -or $env:VENV_DIR -eq $null) { + $VENV_DIR = "$PSScriptRoot\venv" +} else { + $VENV_DIR = $env:VENV_DIR +} + +if ($env:LAUNCH_SCRIPT -eq "" -or $env:LAUNCH_SCRIPT -eq $null) { + $LAUNCH_SCRIPT = "$PSScriptRoot\launch.py" +} else { + $LAUNCH_SCRIPT = $env:LAUNCH_SCRIPT +} + +$ERROR_REPORTING = $false + +mkdir tmp 2>$null + +function Start-Venv { + if ($VENV_DIR -eq '-') { + Skip-Venv + } + + if (Test-Path -Path "$VENV_DIR\Scripts\$python") { + Activate-Venv + } else { + $PYTHON_FULLNAME = & $PYTHON -c "import sys; print(sys.executable)" + Write-Output "Creating venv in directory $VENV_DIR using python $PYTHON_FULLNAME" + Invoke-Expression "$PYTHON_FULLNAME -m venv $VENV_DIR > tmp/stdout.txt 2> tmp/stderr.txt" + if ($LASTEXITCODE -eq 0) { + Activate-Venv + } else { + Write-Output "Unable to create venv in directory $VENV_DIR" + } + } +} + +function Activate-Venv { + $PYTHON = "$VENV_DIR\Scripts\Python.exe" + $ACTIVATE = "$VENV_DIR\Scripts\activate.bat" + Invoke-Expression "cmd.exe /c $ACTIVATE" + Write-Output "Venv set to $VENV_DIR." + if ($ACCELERATE -eq 'True') { + Check-Accelerate + } else { + Launch-App + } +} + +function Skip-Venv { + Write-Output "Venv set to $VENV_DIR." + if ($ACCELERATE -eq 'True') { + Check-Accelerate + } else { + Launch-App + } +} + +function Check-Accelerate { + Write-Output 'Checking for accelerate' + $ACCELERATE = "$VENV_DIR\Scripts\accelerate.exe" + if (Test-Path -Path $ACCELERATE) { + Accelerate-Launch + } else { + Launch-App + } +} + +function Launch-App { + Write-Output "Launching with python" + Invoke-Expression "$PYTHON $LAUNCH_SCRIPT" + #pause + exit +} + +function Accelerate-Launch { + Write-Output 'Accelerating' + Invoke-Expression "$ACCELERATE launch --num_cpu_threads_per_process=6 $LAUNCH_SCRIPT" + #pause + exit +} + + +try { + if(Get-Command $PYTHON){ + Start-Venv + } +} Catch { + Write-Output "Couldn't launch python." +} +``` + + + +#### webui-user.ps1 +``` +[Environment]::SetEnvironmentVariable("PYTHON", "") +[Environment]::SetEnvironmentVariable("GIT", "") +[Environment]::SetEnvironmentVariable("VENV_DIR","") + +# Commandline arguments for webui.py, for example: [Environment]::SetEnvironmentVariable("COMMANDLINE_ARGS", "--medvram --opt-split-attention") +[Environment]::SetEnvironmentVariable("COMMANDLINE_ARGS", "") + +# script to launch to start the app +# [Environment]::SetEnvironmentVariable("LAUNCH_SCRIPT", "launch.py") + +# install command for torch +# [Environment]::SetEnvironmentVariable("TORCH_COMMAND", "pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113") + +# Requirements file to use for stable-diffusion-webui +# [Environment]::SetEnvironmentVariable("REQS_FILE", "requirements_versions.txt") + +# [Environment]::SetEnvironmentVariable("GFPGAN_PACKAGE", "") +# [Environment]::SetEnvironmentVariable("CLIP_PACKAGE", "") +# [Environment]::SetEnvironmentVariable("OPENCLIP_PACKAGE", "") + +# URL to a WHL if you wish to override default xformers windows +# [Environment]::SetEnvironmentVariable("XFORMERS_WINDOWS_PACKAGE", "") + +# Uncomment and set to enable an alternate repository URL +# [Environment]::SetEnvironmentVariable("STABLE_DIFFUSION_REPO", "") +# [Environment]::SetEnvironmentVariable("TAMING_TRANSFORMERS_REPO", "") +# [Environment]::SetEnvironmentVariable("K_DIFFUSION_REPO", "") +# [Environment]::SetEnvironmentVariable("CODEFORMER_REPO", "") +# [Environment]::SetEnvironmentVariable("BLIP_REPO", "") + +# Uncomment and set to enable a specific revision of a repository +# [Environment]::SetEnvironmentVariable("STABLE_DIFFUSION_COMMIT_HASH", "") +# [Environment]::SetEnvironmentVariable("TAMING_TRANSFORMERS_COMMIT_HASH", "") +# [Environment]::SetEnvironmentVariable("K_DIFFUSION_COMMIT_HASH", "") +# [Environment]::SetEnvironmentVariable("CODEFORMER_COMMIT_HASH", "") +# [Environment]::SetEnvironmentVariable("BLIP_COMMIT_HASH", "") + + +# Uncomment to enable accelerated launch +# [Environment]::SetEnvironmentVariable("ACCELERATE", "True") + +$SCRIPT = "$PSScriptRoot\webui.ps1" +Invoke-Expression "$SCRIPT" +``` + +
+ ## Linux To install in the default directory `/home/$(whoami)/stable-diffusion-webui/`, run: ```bash