update processing

This commit is contained in:
Vladimir Mandic
2023-07-11 11:40:53 -04:00
parent 6b26c55138
commit 6d277305f6
4 changed files with 27 additions and 32 deletions
+16 -25
View File
@@ -712,18 +712,19 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed:
shared.state.set_current_image()
shared.sd_model.to(devices.device)
output = shared.sd_model( # pylint: disable=not-callable
prompt=prompts,
negative_prompt=negative_prompts,
num_inference_steps=p.steps,
guidance_scale=p.cfg_scale,
generator=generator,
callback_steps = 1,
callback = diffusers_callback,
output_type='np' if shared.sd_refiner is None else 'latent',
cross_attention_kwargs=cross_attention_kwargs,
**task_specific_kwargs
)
pipe_args = { # TODO needs dynamic discovery of possible args
"prompt": prompts,
"negative_prompt": negative_prompts,
"num_inference_steps": p.steps,
"guidance_scale": p.cfg_scale,
"generator": generator,
"output_type": 'np' if shared.sd_refiner is None else 'latent',
"callback_steps": 1, # TODO not supported by Kandinsky
"callback": diffusers_callback, # TODO not supported by Kandinsky
"cross_attention_kwargs": cross_attention_kwargs, # TODO not supported by Kandinsky
}
output = shared.sd_model(**pipe_args, **task_specific_kwargs) # pylint: disable=not-callable
if shared.sd_refiner is not None:
if shared.opts.diffusers_move_base:
@@ -732,23 +733,13 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed:
shared.sd_refiner.to(devices.device)
devices.torch_gc()
init_image = output.images[0]
output = shared.sd_refiner( # pylint: disable=not-callable
prompt=prompts,
negative_prompt=negative_prompts,
num_inference_steps=p.steps,
guidance_scale=p.cfg_scale,
generator=generator,
callback_steps = 1,
callback = diffusers_callback,
output_type='np',
cross_attention_kwargs=cross_attention_kwargs,
image=init_image
)
pipe_args['image'] = init_image
pipe_args['output_type'] = 'np'
output = shared.sd_refiner(**pipe_args) # pylint: disable=not-callable
if shared.opts.diffusers_move_refiner:
shared.log.debug('Moving refiner model to CPU')
shared.sd_refiner.to('cpu')
x_samples_ddim = output.images
if p.is_hr_pass:
+8 -4
View File
@@ -77,7 +77,11 @@ class CheckpointInfo:
if os.path.isfile(repo[0]['model_info']):
file_path = repo[0]['model_info']
with open(file_path, "r", encoding="utf-8") as json_file:
self.model_info = json.load(json_file)
try:
self.model_info = json.load(json_file)
except Exception as e:
shared.log.error(f'Error loading model info: {json_file} {e}')
self.model_info = {}
self.shorthash = self.sha256[0:10] if self.sha256 else None
self.title = self.name if self.shorthash is None else f'{self.name} [{self.shorthash}]'
@@ -726,9 +730,9 @@ def load_diffuser(checkpoint_info=None, already_loaded_state_dict=None, timer=No
base_sent_to_cpu=False
else:
if not refiner_enough_vram and not (shared.opts.diffusers_move_base and shared.opts.diffusers_move_refiner):
shared.log.warning(f"Not enough VRAM to use refiner, using RAM as fallback. Free VRAM: {free_vram} GB\n"
+ "Enabled 'Move base model to CPU when using refiner' and 'Move refiner model to CPU when not in use'\n"
+ "Enable the settings above and apply the settings to suppress this warning.")
shared.log.warning(f"Insufficient GPU memory, using system memory as fallback: free={free_vram} GB")
shared.log.debug('Enabled moving base model to CPU')
shared.log.debug('Enabled moving base model to CPU')
shared.opts.diffusers_move_base=True
shared.opts.diffusers_move_refiner=True
shared.log.debug('Moving base model to CPU')