diff --git a/Launcher.bat b/Launcher.bat index 2d93e92..ce23d13 100644 --- a/Launcher.bat +++ b/Launcher.bat @@ -516,34 +516,41 @@ if not exist "%st_install_path%" ( goto :no_st_install_path ) -REM Run PowerShell command to retrieve VRAM size and divide by 1GB +REM Initialize variables for VRAM detection set /a iteration=0 set /a last_UVRAM=0 +set "GPU_name=Unknown" +set "last_GPU=Unknown" + REM Detect GPU and store name, excluding integrated GPUs if discrete GPUs are found -for /f "tokens=2 delims==" %%f in ('wmic path Win32_VideoController get name /value ^| find "="') do ( - REM Run PowerShell command to retrieve VRAM size and divide by 1GB - for /f "usebackq tokens=*" %%i in (`powershell -Command "$qwMemorySize = (Get-ItemProperty -Path 'HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*' -Name HardwareInformation.qwMemorySize -ErrorAction SilentlyContinue).'HardwareInformation.qwMemorySize'; if ($null -ne $qwMemorySize -and $qwMemorySize -is [array]) { $qwMemorySize = [double]$qwMemorySize[!iteration!] } else { $qwMemorySize = [double]$qwMemorySize }; if ($null -ne $qwMemorySize) { [math]::Round($qwMemorySize/1GB) } else { 'Property not found' }"`) do ( - set "UVRAM=%%i" - ) - set /a iteration=!iteration!+1 - REM If the VRAM is greater than 0 (it always should be, but just in case...) AND the lastUVRAM is not the same as VRAM - REM (might have to change this in the case where two cards have the same VRAM, but the user wants the first card... - REM in which case we would want to see if it is the first iteration or not... but I'm not here to do all your work!) - REM AND the lastUVRAM is Grt than VRAM... set it to the previous card. We don't have to check the other way, because - REM we already set VRAM. This way takes more builds into account... but not all. - if /i !lastUVRAM! gtr 0 ( - if /i !lastUVRAM! neq !UVRAM! ( - if /i !lastUVRAM! gtr !UVRAM! ( - set "UVRAM=!lastUVRAM!" - @REM set "GPU_name=!last_GPU!" - - ) - ) - ) else ( - set "lastUVRAM=!UVRAM!" - ) +for /f "tokens=*" %%f in ('powershell -Command "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name"') do ( + REM Update GPU name and store previous name + if "!GPU_name!"=="" ( + set "GPU_name=%%f" + ) else if "!GPU_name!" neq "%%f" ( + set "last_GPU=!GPU_name!" + set "GPU_name=%%f" + ) + + REM Run PowerShell command to retrieve VRAM size and divide by 1GB + for /f "usebackq tokens=*" %%i in (`powershell -Command "$qwMemorySize = (Get-ItemProperty -Path 'HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*' -Name HardwareInformation.qwMemorySize -ErrorAction SilentlyContinue).'HardwareInformation.qwMemorySize'; if ($null -ne $qwMemorySize -and $qwMemorySize -is [array]) { $qwMemorySize = [double]$qwMemorySize[!iteration!] } else { $qwMemorySize = [double]$qwMemorySize }; if ($null -ne $qwMemorySize) { [math]::Round($qwMemorySize/1GB) } else { 'Property not found' }"`) do ( + set "UVRAM=%%i" + ) + + REM Increment iteration for array indexing + set /a iteration=!iteration!+1 + + REM Update UVRAM and GPU name only if current UVRAM is greater than last_UVRAM + if /i !UVRAM! gtr !last_UVRAM! ( + set /a last_UVRAM=!UVRAM! + set "last_GPU=!GPU_name!" + ) ) +REM Restore the GPU name and UVRAM to the one with the highest VRAM +set "UVRAM=!last_UVRAM!" +set "GPU_name=!last_GPU!" + REM Change the current directory to 'sillytavern' folder cd /d "%st_install_path%" diff --git a/bin/functions/Home/info_vram.bat b/bin/functions/Home/info_vram.bat index 60edac1..e3d9583 100644 --- a/bin/functions/Home/info_vram.bat +++ b/bin/functions/Home/info_vram.bat @@ -4,7 +4,6 @@ title STL [VRAM INFO] chcp 65001 > nul setlocal enabledelayedexpansion - REM Confirm script start and input arguments set "UVRAM=%~1" @@ -17,10 +16,10 @@ if not defined UVRAM ( set "UVRAM=0" ) -REM Get GPU information safely +REM Get GPU information safely using PowerShell set "gpu_info=" -for /f "skip=1 delims=" %%i in ('wmic path win32_videocontroller get caption') do ( - if not "%%i"=="" set "gpu_info=!gpu_info! %%i" +for /f "tokens=*" %%i in ('powershell -Command "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name -First 1"') do ( + if not "%%i"=="" set "gpu_info=%%i" ) cls diff --git a/bin/functions/Toolbox/App_Installer/Image_Generation/install_invokeai.bat b/bin/functions/Toolbox/App_Installer/Image_Generation/install_invokeai.bat index 74001c6..03a11e7 100644 --- a/bin/functions/Toolbox/App_Installer/Image_Generation/install_invokeai.bat +++ b/bin/functions/Toolbox/App_Installer/Image_Generation/install_invokeai.bat @@ -14,8 +14,9 @@ echo 0. Cancel setlocal enabledelayedexpansion chcp 65001 > nul REM Get GPU information -for /f "skip=1 delims=" %%i in ('wmic path win32_videocontroller get caption') do ( - set "gpu_info=!gpu_info! %%i" +set "gpu_info=" +for /f "tokens=*" %%i in ('powershell -Command "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name -First 1"') do ( + set "gpu_info=%%i" ) echo. diff --git a/bin/functions/Toolbox/App_Installer/Text_Completion/install_koboldcpp.bat b/bin/functions/Toolbox/App_Installer/Text_Completion/install_koboldcpp.bat index fcbbc30..e7e42b3 100644 --- a/bin/functions/Toolbox/App_Installer/Text_Completion/install_koboldcpp.bat +++ b/bin/functions/Toolbox/App_Installer/Text_Completion/install_koboldcpp.bat @@ -14,8 +14,9 @@ echo 0. Cancel setlocal enabledelayedexpansion chcp 65001 > nul REM Get GPU information -for /f "skip=1 delims=" %%i in ('wmic path win32_videocontroller get caption') do ( - set "gpu_info=!gpu_info! %%i" +set "gpu_info=" +for /f "tokens=*" %%i in ('powershell -Command "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name -First 1"') do ( + set "gpu_info=%%i" ) echo. diff --git a/bin/functions/Toolbox/App_Installer/Text_Completion/install_tabbyapi.bat b/bin/functions/Toolbox/App_Installer/Text_Completion/install_tabbyapi.bat index 6c7b992..6d999e0 100644 --- a/bin/functions/Toolbox/App_Installer/Text_Completion/install_tabbyapi.bat +++ b/bin/functions/Toolbox/App_Installer/Text_Completion/install_tabbyapi.bat @@ -14,8 +14,9 @@ echo 0. Cancel setlocal enabledelayedexpansion chcp 65001 > nul REM Get GPU information -for /f "skip=1 delims=" %%i in ('wmic path win32_videocontroller get caption') do ( - set "gpu_info=!gpu_info! %%i" +set "gpu_info=" +for /f "tokens=*" %%i in ('powershell -Command "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name -First 1"') do ( + set "gpu_info=%%i" ) echo. diff --git a/bin/functions/Toolbox/App_Installer/Voice_Generation/install_alltalk.bat b/bin/functions/Toolbox/App_Installer/Voice_Generation/install_alltalk.bat index ec54d9b..63456f5 100644 --- a/bin/functions/Toolbox/App_Installer/Voice_Generation/install_alltalk.bat +++ b/bin/functions/Toolbox/App_Installer/Voice_Generation/install_alltalk.bat @@ -14,8 +14,9 @@ echo 0. Cancel setlocal enabledelayedexpansion chcp 65001 > nul REM Get GPU information -for /f "skip=1 delims=" %%i in ('wmic path win32_videocontroller get caption') do ( - set "gpu_info=!gpu_info! %%i" +set "gpu_info=" +for /f "tokens=*" %%i in ('powershell -Command "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name -First 1"') do ( + set "gpu_info=%%i" ) echo. diff --git a/bin/functions/Toolbox/App_Installer/Voice_Generation/install_alltalk_v2.bat b/bin/functions/Toolbox/App_Installer/Voice_Generation/install_alltalk_v2.bat index e3a1eea..a5277ae 100644 --- a/bin/functions/Toolbox/App_Installer/Voice_Generation/install_alltalk_v2.bat +++ b/bin/functions/Toolbox/App_Installer/Voice_Generation/install_alltalk_v2.bat @@ -14,8 +14,9 @@ echo 0. Cancel setlocal enabledelayedexpansion chcp 65001 > nul REM Get GPU information -for /f "skip=1 delims=" %%i in ('wmic path win32_videocontroller get caption') do ( - set "gpu_info=!gpu_info! %%i" +set "gpu_info=" +for /f "tokens=*" %%i in ('powershell -Command "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name -First 1"') do ( + set "gpu_info=%%i" ) echo. diff --git a/bin/functions/Toolbox/App_Installer/Voice_Generation/install_rvc.bat b/bin/functions/Toolbox/App_Installer/Voice_Generation/install_rvc.bat index 1c9fe3b..56dba68 100644 --- a/bin/functions/Toolbox/App_Installer/Voice_Generation/install_rvc.bat +++ b/bin/functions/Toolbox/App_Installer/Voice_Generation/install_rvc.bat @@ -16,8 +16,9 @@ echo 0. Cancel setlocal enabledelayedexpansion chcp 65001 > nul REM Get GPU information -for /f "skip=1 delims=" %%i in ('wmic path win32_videocontroller get caption') do ( - set "gpu_info=!gpu_info! %%i" +set "gpu_info=" +for /f "tokens=*" %%i in ('powershell -Command "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name -First 1"') do ( + set "gpu_info=%%i" ) echo. diff --git a/bin/functions/Toolbox/App_Installer/Voice_Generation/install_rvc_python.bat b/bin/functions/Toolbox/App_Installer/Voice_Generation/install_rvc_python.bat index 29f2f6f..83eeaba 100644 --- a/bin/functions/Toolbox/App_Installer/Voice_Generation/install_rvc_python.bat +++ b/bin/functions/Toolbox/App_Installer/Voice_Generation/install_rvc_python.bat @@ -16,8 +16,9 @@ echo 0. Cancel setlocal enabledelayedexpansion chcp 65001 > nul REM Get GPU information -for /f "skip=1 delims=" %%i in ('wmic path win32_videocontroller get caption') do ( - set "gpu_info=!gpu_info! %%i" +set "gpu_info=" +for /f "tokens=*" %%i in ('powershell -Command "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name -First 1"') do ( + set "gpu_info=%%i" ) echo. diff --git a/bin/functions/Toolbox/App_Installer/Voice_Generation/install_xtts.bat b/bin/functions/Toolbox/App_Installer/Voice_Generation/install_xtts.bat index e34de3c..b6af0f8 100644 --- a/bin/functions/Toolbox/App_Installer/Voice_Generation/install_xtts.bat +++ b/bin/functions/Toolbox/App_Installer/Voice_Generation/install_xtts.bat @@ -15,8 +15,9 @@ echo 0. Cancel setlocal enabledelayedexpansion chcp 65001 > nul REM Get GPU information -for /f "skip=1 delims=" %%i in ('wmic path win32_videocontroller get caption') do ( - set "gpu_info=!gpu_info! %%i" +set "gpu_info=" +for /f "tokens=*" %%i in ('powershell -Command "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name -First 1"') do ( + set "gpu_info=%%i" ) echo. diff --git a/bin/functions/Toolbox/Troubleshooting/gpu_info.bat b/bin/functions/Toolbox/Troubleshooting/gpu_info.bat index a9c4d73..bc6d3cb 100644 --- a/bin/functions/Toolbox/Troubleshooting/gpu_info.bat +++ b/bin/functions/Toolbox/Troubleshooting/gpu_info.bat @@ -8,40 +8,37 @@ set "last_GPU=Unknown" set "GPU_name=Unknown" set "VRAM=Unknown" set "primary_gpu_found=false" + REM Detect GPU and store name, excluding integrated GPUs if discrete GPUs are found -for /f "tokens=2 delims==" %%f in ('wmic path Win32_VideoController get name /value ^| find "="') do ( - REM If GPU name is blank, set it; else, if it is not blank and does not equal the current value of f, - REM move gpu name to last_gpu and set gpu_name to the new value. This is here so that if the current card has less - REM VRAM than the previous card, we can set the name back properly. I doubt it would be needed... but you never know. - if /i !GPU_name! equ "" ( - set "GPU_name=%%f" - ) else if !GPU_name! neq %%f ( - set "last_GPU=!GPU_name!" - set "GPU_name=%%f" - ) - REM Run PowerShell command to retrieve VRAM size and divide by 1GB - for /f "usebackq tokens=*" %%i in (`powershell -Command "$qwMemorySize = (Get-ItemProperty -Path 'HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*' -Name HardwareInformation.qwMemorySize -ErrorAction SilentlyContinue).'HardwareInformation.qwMemorySize'; if ($null -ne $qwMemorySize -and $qwMemorySize -is [array]) { $qwMemorySize = [double]$qwMemorySize[!iteration!] } else { $qwMemorySize = [double]$qwMemorySize }; if ($null -ne $qwMemorySize) { [math]::Round($qwMemorySize/1GB) } else { 'Property not found' }"`) do ( - set "VRAM=%%i" - ) - REM iterate so we can move through the objects in the powershell script... - set /a iteration=!iteration!+1 - REM If the VRAM is greater than 0 (it always should be, but just in case...) AND the lastVRAM is not the same as VRAM - REM (might have to change this in the case where two cards have the same VRAM, but the user wants the first card... - REM in which case we would want to see if it is the first iteration or not... but I'm not here to do all your work!) - REM AND the lastVRAM is Grt than VRAM... set it to the previous card. We don't have to check the other way, because - REM we already set VRAM. This way takes more builds into account... but not all. - if /i !lastVRAM! gtr 0 ( - if /i !lastVRAM! neq !VRAM! ( - if /i !lastVRAM! gtr !VRAM! ( - set "VRAM=!lastVRAM!" - set "GPU_name=!last_GPU!" - ) - ) - ) else ( - set "lastVRAM=!VRAM!" - ) +for /f "tokens=*" %%f in ('powershell -Command "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name"') do ( + REM If GPU name is blank, set it; else, if it is not blank and does not equal the current value of f, + REM move gpu name to last_gpu and set gpu_name to the new value. + if /i "!GPU_name!" equ "" ( + set "GPU_name=%%f" + ) else if "!GPU_name!" neq "%%f" ( + set "last_GPU=!GPU_name!" + set "GPU_name=%%f" + ) + + REM Run PowerShell command to retrieve VRAM size and divide by 1GB + for /f "usebackq tokens=*" %%i in (`powershell -Command "$qwMemorySize = (Get-ItemProperty -Path 'HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*' -Name HardwareInformation.qwMemorySize -ErrorAction SilentlyContinue).'HardwareInformation.qwMemorySize'; if ($null -ne $qwMemorySize -and $qwMemorySize -is [array]) { $qwMemorySize = [double]$qwMemorySize[!iteration!] } else { $qwMemorySize = [double]$qwMemorySize }; if ($null -ne $qwMemorySize) { [math]::Round($qwMemorySize/1GB) } else { 'Property not found' }"`) do ( + set "VRAM=%%i" + ) + + REM Iterate to move through the objects in the PowerShell script + set /a iteration=!iteration!+1 + + REM Update VRAM and GPU name only if current VRAM is greater than last_VRAM + if /i !VRAM! gtr !last_VRAM! ( + set /a last_VRAM=!VRAM! + set "last_GPU=!GPU_name!" + ) ) +REM Restore the GPU name and VRAM to the one with the highest VRAM +set "GPU_name=!last_GPU!" +set "VRAM=!last_VRAM!" + REM Display GPU name and VRAM -echo GPU: %cyan_fg_strong%%GPU_name%%reset% - VRAM: %cyan_fg_strong%%VRAM%%reset% GB -endlocal +echo GPU: %cyan_fg_strong%!GPU_name!%reset% - VRAM: %cyan_fg_strong%!VRAM!%reset% GB +endlocal \ No newline at end of file diff --git a/installer.bat b/installer.bat index e02702f..b077b0b 100644 --- a/installer.bat +++ b/installer.bat @@ -454,8 +454,9 @@ echo 0. Cancel install setlocal enabledelayedexpansion chcp 65001 > nul REM Get GPU information -for /f "skip=1 delims=" %%i in ('wmic path win32_videocontroller get caption') do ( - set "gpu_info=!gpu_info! %%i" +set "gpu_info=" +for /f "tokens=*" %%i in ('powershell -Command "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name -First 1"') do ( + set "gpu_info=%%i" ) echo. @@ -624,8 +625,9 @@ echo 0. Cancel setlocal enabledelayedexpansion chcp 65001 > nul REM Get GPU information -for /f "skip=1 delims=" %%i in ('wmic path win32_videocontroller get caption') do ( - set "gpu_info=!gpu_info! %%i" +set "gpu_info=" +for /f "tokens=*" %%i in ('powershell -Command "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name -First 1"') do ( + set "gpu_info=%%i" ) echo. @@ -779,8 +781,9 @@ echo 0. Cancel install setlocal enabledelayedexpansion chcp 65001 > nul REM Get GPU information -for /f "skip=1 delims=" %%i in ('wmic path win32_videocontroller get caption') do ( - set "gpu_info=!gpu_info! %%i" +set "gpu_info=" +for /f "tokens=*" %%i in ('powershell -Command "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name -First 1"') do ( + set "gpu_info=%%i" ) echo.