From fc472f3f3a90de9b3c6fce3390f402ea973d9a18 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Mon, 6 Oct 2025 20:20:46 -0400 Subject: [PATCH] reinstall if torch-cpu and use-cuda or use-rocm Signed-off-by: Vladimir Mandic --- CHANGELOG.md | 1 + installer.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4d78920c..a707ffb6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ `torch-directml` received no updates in over 1 year and its currently superceded by `rocm` or `zluda` - command line params `--use-zluda` and `--use-rocm` will attempt desired operation or fail if not possible previously sdnext was performing a fallback to `torch-cpu` which is not desired + - if `--use-cuda` or `--use-rocm` are specified and `torch-cpu` is installed, installer will attempt to reinstall correct torch package - **installer**: warn if cuda or rocm are available and `torch-cpu` is installed - **Extensions** - [Agent-Scheduler](https://github.com/SipherAGI/sd-webui-agent-scheduler) diff --git a/installer.py b/installer.py index 63e678bef..55b198ff8 100644 --- a/installer.py +++ b/installer.py @@ -953,9 +953,19 @@ def check_torch(): pass if 'cpu' in torch.__version__: if is_cuda_available: - log.warning(f'Torch: version="{torch.__version__}" CPU version installed and CUDA is available - consider reinstalling') + if args.use_cuda: + log.warning(f'Torch: version="{torch.__version__}" CPU version installed and CUDA is selected - reinstalling') + uninstall(['torch', 'torchvision'], quiet=True) + install(torch_command, 'torch torchvision', quiet=True) # foce reinstall + else: + log.warning(f'Torch: version="{torch.__version__}" CPU version installed and CUDA is available - consider reinstalling') elif is_rocm_available: - log.warning(f'Torch: version="{torch.__version__}" CPU version installed and ROCm is available - consider reinstalling') + if args.use_rocm: + log.warning(f'Torch: version="{torch.__version__}" CPU version installed and ROCm is selected - reinstalling') + uninstall(['torch', 'torchvision'], quiet=True) + install(torch_command, 'torch torchvision', quiet=True) # foce reinstall + else: + log.warning(f'Torch: version="{torch.__version__}" CPU version installed and ROCm is available - consider reinstalling') if hasattr(torch, "xpu") and torch.xpu.is_available() and allow_ipex: if shutil.which('icpx') is not None: log.info(f'{os.popen("icpx --version").read().rstrip()}')