More fixes to devices changing names.

This commit is contained in:
Marc-Andre Ferland 2022-10-18 21:08:04 -04:00
parent fcdb086daf
commit 53cdeeff03
2 changed files with 12 additions and 21 deletions

View File

@ -351,23 +351,14 @@ def do_mk_img(req: Request):
thread_data.ckpt_file = req.use_stable_diffusion_model thread_data.ckpt_file = req.use_stable_diffusion_model
needs_model_reload = True needs_model_reload = True
if req.use_cpu: if thread_data.has_valid_gpu:
if thread_data.device != 'cpu': if (thread_data.precision == 'autocast' and (req.use_full_precision or not thread_data.model_is_half)) or \
thread_data.device = 'cpu' (thread_data.precision == 'full' and not req.use_full_precision and not thread_data.force_full_precision):
if thread_data.model_is_half: thread_data.precision = 'full' if req.use_full_precision else 'autocast'
load_model_ckpt() load_model_ckpt()
needs_model_reload = False
load_model_gfpgan() load_model_gfpgan()
load_model_real_esrgan() load_model_real_esrgan()
else: needs_model_reload = False
if thread_data.has_valid_gpu:
if (thread_data.precision == 'autocast' and (req.use_full_precision or not thread_data.model_is_half)) or \
(thread_data.precision == 'full' and not req.use_full_precision and not thread_data.force_full_precision):
thread_data.precision = 'full' if req.use_full_precision else 'autocast'
load_model_ckpt()
load_model_gfpgan()
load_model_real_esrgan()
needs_model_reload = False
if needs_model_reload: if needs_model_reload:
load_model_ckpt() load_model_ckpt()
@ -593,7 +584,8 @@ def do_mk_img(req: Request):
move_fs_to_cpu() move_fs_to_cpu()
gc() gc()
del x_samples, x_samples_ddim, x_sample del x_samples, x_samples_ddim, x_sample
print(f'memory_final = {round(torch.cuda.memory_allocated(thread_data.device) / 1e6, 2)}Mo') if thread_data.device != 'cpu':
print(f'memory_final = {round(torch.cuda.memory_allocated(thread_data.device) / 1e6, 2)}Mo')
print('Task completed') print('Task completed')

View File

@ -346,21 +346,21 @@ async def check_status(): # Task to Validate user config shortly after startup.
# Issues found, try to fix and warn the user. # Issues found, try to fix and warn the user.
device_count = 0 device_count = 0
for i in range(10): # Wait for devices to register and/or change names. for i in range(10): # Wait for devices to register and/or change names.
await asyncio.sleep(3)
new_count = task_manager.is_alive() new_count = task_manager.is_alive()
if device_count == new_count: break; if device_count == new_count: break;
device_count = new_count device_count = new_count
await asyncio.sleep(3)
if 'render_devices' in config and task_manager.is_alive() <= 0: # No running devices, probably invalid user config. Try to apply defaults. if 'render_devices' in config and task_manager.is_alive() <= 0: # No running devices, probably invalid user config. Try to apply defaults.
task_manager.start_render_thread('auto') # Detect best device for renders task_manager.start_render_thread('auto') # Detect best device for renders
task_manager.start_render_thread('cpu') # Allow CPU to be used for renders task_manager.start_render_thread('cpu') # Allow CPU to be used for renders
await asyncio.sleep(10) # delay message after thread start. await asyncio.sleep(3) # delay message after thread start.
display_warning = False display_warning = False
if not 'render_devices' in config and task_manager.is_alive(0) <= 0: # No config set, is on auto mode and without cuda:0 if not 'render_devices' in config and task_manager.is_alive(0) <= 0: # No config set, is on auto mode and without cuda:0
task_manager.start_render_thread('cuda') # An other cuda device is better and cuda:0 is missing, start it... task_manager.start_render_thread('cuda') # An other cuda device is better and cuda:0 is missing, start it...
display_warning = True # And warn user to update settings... display_warning = True # And warn user to update settings...
await asyncio.sleep(10) # delay message after thread start. await asyncio.sleep(3) # delay message after thread start.
if display_warning or task_manager.is_alive(0) <= 0: if display_warning or task_manager.is_alive(0) <= 0:
print('WARNING: GFPGANer only works on CPU or GPU:0, use CUDA_VISIBLE_DEVICES if GFPGANer is needed on a specific GPU.') print('WARNING: GFPGANer only works on CPU or GPU:0, use CUDA_VISIBLE_DEVICES if GFPGANer is needed on a specific GPU.')
@ -378,8 +378,7 @@ if 'render_devices' in config: # Start a new thread for each device.
for device in config['render_devices']: for device in config['render_devices']:
task_manager.start_render_thread(device) task_manager.start_render_thread(device)
else: else:
# Select best device GPU device using free memory if more than one device. # Select best GPU device using free memory, if more than one device.
#task_manager.start_render_thread('cuda') # Starts silently on cuda:0
task_manager.start_render_thread('auto') # Detect best device for renders task_manager.start_render_thread('auto') # Detect best device for renders
task_manager.start_render_thread('cpu') # Allow CPU to be used for renders task_manager.start_render_thread('cpu') # Allow CPU to be used for renders