From abbfae2fc0578008c25806ab88030e1687300070 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Mon, 7 Nov 2022 17:55:27 +0530 Subject: [PATCH] Simplify the logic used for displaying the GFPGAN warning --- ui/sd_internal/runtime.py | 4 ++-- ui/server.py | 23 +++++++---------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/ui/sd_internal/runtime.py b/ui/sd_internal/runtime.py index 69127d1f..00a4f691 100644 --- a/ui/sd_internal/runtime.py +++ b/ui/sd_internal/runtime.py @@ -136,12 +136,12 @@ def device_init(device_selection=None): return if not torch.cuda.is_available(): if device_selection == 'auto' or device_selection == 'current': - print('WARNING: torch.cuda is not available. Using the CPU, but this will be very slow!') + print('WARNING: Could not find a compatible GPU. Using the CPU, but this will be very slow!') thread_data.device = 'cpu' thread_data.device_name = get_processor_name() return else: - raise EnvironmentError('torch.cuda is not available.') + raise EnvironmentError(f'Could not find a compatible GPU for the requested device_selection: {device_selection}!') device_count = torch.cuda.device_count() if device_count <= 1 and device_selection == 'auto': device_selection = 'current' # Use 'auto' only when there is more than one compatible device found. diff --git a/ui/server.py b/ui/server.py index 00e5d0f1..50098cc1 100644 --- a/ui/server.py +++ b/ui/server.py @@ -407,7 +407,6 @@ config = getConfig() # Start the task_manager task_manager.default_model_to_load = resolve_ckpt_to_use() task_manager.default_vae_to_load = resolve_vae_to_use(ckpt_model_path=task_manager.default_model_to_load) -display_warning = False if 'render_devices' in config: # Start a new thread for each device. if isinstance(config['render_devices'], str): config['render_devices'] = config['render_devices'].split(',') @@ -422,32 +421,24 @@ if 'render_devices' in config: # Start a new thread for each device. if task_manager.is_alive() <= 0: # No running devices, probably invalid user config. print('WARNING: No active render devices after loading config. Validate "render_devices" in config.json') print('Loading default render devices to replace invalid render_devices field from config', config['render_devices']) - elif task_manager.is_alive(0) <= 0: # Missing GPU:0 - display_warning = True # Warn user to update settings... if task_manager.is_alive() <= 0: # Either no defauls or no devices after loading config. # Select best GPU device using free memory, if more than one device. if task_manager.start_render_thread('auto'): # Detect best device for renders - if task_manager.is_alive(0) <= 0: # has no cuda:0 - if task_manager.is_alive('cpu') >= 1: # auto used CPU. - pass # Maybe add warning here about CPU mode... - elif task_manager.start_render_thread('cuda'): # An other cuda device is better and cuda:0 is missing, try to start it... - display_warning = True # And warn user to update settings... - else: - print('Failed to start GPU:0...') + # if cuda:0 is missing, another cuda device is better. try to start it... + if task_manager.is_alive(0) <= 0 and task_manager.is_alive('cpu') <= 0 and not task_manager.start_render_thread('cuda'): + print('Failed to start GPU:0...') else: print('Failed to start gpu device.') - if task_manager.is_alive('cpu') <= 0: - # Allow CPU to be used for renders - if not task_manager.start_render_thread('cpu'): - print('Failed to start CPU render device...') + if task_manager.is_alive('cpu') <= 0 and not task_manager.start_render_thread('cpu'): # Allow CPU to be used for renders + print('Failed to start CPU render device...') -if display_warning: +is_using_a_gpu = (task_manager.is_alive() > task_manager.is_alive('cpu')) +if is_using_a_gpu and task_manager.is_alive(0) <= 0: print('WARNING: GFPGANer only works on GPU:0, use CUDA_VISIBLE_DEVICES if GFPGANer is needed on a specific GPU.') print('Using CUDA_VISIBLE_DEVICES will remap the selected devices starting at GPU:0 fixing GFPGANer') print('Add the line "@set CUDA_VISIBLE_DEVICES=N" where N is the GPUs to use to config.bat') print('Add the line "CUDA_VISIBLE_DEVICES=N" where N is the GPUs to use to config.sh') -del display_warning # start the browser ui import webbrowser; webbrowser.open('http://localhost:9000')