From 6d6f1de295b836acbe07b3c0d0bdf5f199dcc4fa Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sat, 8 Jun 2024 14:14:48 -0400 Subject: [PATCH] additional python 3.12 compatibility --- installer.py | 5 +++++ modules/devices.py | 2 +- modules/postprocess/sdupscaler_model.py | 1 - modules/postprocessing.py | 2 +- modules/sd_models.py | 2 -- scripts/face-details.py | 2 +- webui.py | 1 + 7 files changed, 9 insertions(+), 6 deletions(-) diff --git a/installer.py b/installer.py index 5de54feea..9c77a1cf2 100644 --- a/installer.py +++ b/installer.py @@ -402,6 +402,8 @@ def check_python(supported_minors=[9, 10, 11, 12], reason=None): log.error(reason) if not args.ignore: sys.exit(1) + if int(sys.version_info.minor) == 12: + os.environ.setdefault('SETUPTOOLS_USE_DISTUTILS', 'local') # hack for python 3.11 setuptools if not args.skip_git: git_cmd = os.environ.get('GIT', "git") if shutil.which(git_cmd) is None: @@ -432,6 +434,7 @@ def check_onnx(): def install_rocm_zluda(torch_command): + check_python(supported_minors=[10,11], reason='RocM or Zluda backends require Python 3.10 or 3.11') is_windows = platform.system() == 'Windows' log.info('AMD ROCm toolkit detected') os.environ.setdefault('PYTORCH_HIP_ALLOC_CONF', 'garbage_collection_threshold:0.8,max_split_size_mb:512') @@ -539,6 +542,7 @@ def install_rocm_zluda(torch_command): def install_ipex(torch_command): + check_python(supported_minors=[10,11], reason='IPEX backend requires Python 3.10 or 3.11') args.use_ipex = True # pylint: disable=attribute-defined-outside-init log.info('Intel OneAPI Toolkit detected') if os.environ.get("NEOReadDebugKeys", None) is None: @@ -579,6 +583,7 @@ def install_ipex(torch_command): def install_openvino(torch_command): + check_python(supported_minors=[10,11], reason='IPEX backend requires Python 3.10 or 3.11') log.info('Using OpenVINO') torch_command = os.environ.get('TORCH_COMMAND', 'torch==2.2.0 torchvision==0.17.0 --index-url https://download.pytorch.org/whl/cpu') install(os.environ.get('OPENVINO_PACKAGE', 'openvino==2023.3.0'), 'openvino') diff --git a/modules/devices.py b/modules/devices.py index 8ff3ad04b..675fcac19 100644 --- a/modules/devices.py +++ b/modules/devices.py @@ -235,7 +235,7 @@ def set_cuda_params(): torch.use_deterministic_algorithms(shared.opts.cudnn_deterministic) log.debug(f'Torch mode: deterministic={shared.opts.cudnn_deterministic}') if shared.opts.cudnn_deterministic: - os.environ['CUBLAS_WORKSPACE_CONFIG'] = ':4096:8' + os.environ.setdefault('CUBLAS_WORKSPACE_CONFIG', ':4096:8') torch.backends.cudnn.benchmark = True if shared.opts.cudnn_benchmark: log.debug('Torch cuDNN: enable benchmark') diff --git a/modules/postprocess/sdupscaler_model.py b/modules/postprocess/sdupscaler_model.py index 0a3106289..e5b1c8b45 100644 --- a/modules/postprocess/sdupscaler_model.py +++ b/modules/postprocess/sdupscaler_model.py @@ -28,7 +28,6 @@ class UpscalerSD(Upscaler): shared.log.debug(f"Upscaler cached: type={scaler.name} model={path}") return self.models[path] else: - devices.set_cuda_params() model = diffusers.DiffusionPipeline.from_pretrained(path, cache_dir=shared.opts.diffusers_dir, torch_dtype=devices.dtype) if hasattr(model, "set_progress_bar_config"): model.set_progress_bar_config(bar_format='Progress {rate_fmt}{postfix} {bar} {percentage:3.0f}% {n_fmt}/{total_fmt} {elapsed} {remaining} ' + '\x1b[38;5;71m' + 'Upscale', ncols=80, colour='#327fba') diff --git a/modules/postprocessing.py b/modules/postprocessing.py index 2288401df..346758851 100644 --- a/modules/postprocessing.py +++ b/modules/postprocessing.py @@ -78,7 +78,7 @@ def run_postprocessing(extras_mode, image, image_folder: List[tempfile.NamedTemp pp.image.info[k] = v if 'parameters' in items: info = items['parameters'] + ', ' - info = info + ", ".join([k if k == v else f'{k}: {info.quote(v)}' for k, v in pp.info.items() if v is not None]) + info = info + ", ".join([k if k == v else f'{k}: {infotext.quote(v)}' for k, v in pp.info.items() if v is not None]) pp.image.info["postprocessing"] = info processed_images.append(pp.image) if save_output: diff --git a/modules/sd_models.py b/modules/sd_models.py index f9f89f189..00b0343ba 100644 --- a/modules/sd_models.py +++ b/modules/sd_models.py @@ -890,7 +890,6 @@ def load_diffuser(checkpoint_info=None, already_loaded_state_dict=None, timer=No timer = Timer() logging.getLogger("diffusers").setLevel(logging.ERROR) timer.record("diffusers") - devices.set_cuda_params() diffusers_load_config = { "low_cpu_mem_usage": True, "torch_dtype": devices.dtype, @@ -1420,7 +1419,6 @@ def load_model(checkpoint_info=None, already_loaded_state_dict=None, timer=None, from modules import sd_hijack_inpainting sd_hijack_inpainting.do_inpainting_hijack() - devices.set_cuda_params() if already_loaded_state_dict is not None: state_dict = already_loaded_state_dict else: diff --git a/scripts/face-details.py b/scripts/face-details.py index f5e554f15..2a53b4234 100644 --- a/scripts/face-details.py +++ b/scripts/face-details.py @@ -32,7 +32,7 @@ class FaceRestorerYolo(FaceRestoration): def dependencies(self): import installer - installer.install('ultralytics', ignore=True) + installer.install('ultralytics', ignore=True, quiet=True) def predict( self, diff --git a/webui.py b/webui.py index fd22fef73..408724eff 100644 --- a/webui.py +++ b/webui.py @@ -156,6 +156,7 @@ def initialize(): def load_model(): + modules.devices.set_cuda_params() if not opts.sd_checkpoint_autoload or (shared.cmd_opts.ckpt is not None and shared.cmd_opts.ckpt.lower() != 'none'): log.debug('Model auto load disabled') else: