Skip to content

Commit

Permalink
Merge branch 'lllyasviel:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
anapnoe authored Oct 27, 2024
2 parents 29cbe3c + 41a21f6 commit f5cbd6c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
3 changes: 3 additions & 0 deletions backend/text_processing/textual_inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,7 @@ def create_embedding_from_data(data, name, filename='unknown embedding file', fi
embedding.vectors = vectors
embedding.shape = shape

if filepath:
embedding.filename = filepath

return embedding
24 changes: 12 additions & 12 deletions modules/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,8 +829,8 @@ def process_images(p: StableDiffusionProcessing) -> Processed:
set_config(p.override_settings, is_api=True, run_callbacks=False, save_config=False)

# load/reload model and manage prompt cache as needed
if p.highresfix_quick == True:
# avoid model load here, as it could be redundant
if getattr(p, 'txt2img_upscale', False):
# avoid model load from hiresfix quickbutton, as it could be redundant
pass
else:
manage_model_and_prompt_cache(p)
Expand Down Expand Up @@ -930,7 +930,9 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed:
if state.interrupted or state.stopping_generation:
break

sd_models.forge_model_reload() # model can be changed for example by refiner, hiresfix fix
if not getattr(p, 'txt2img_upscale', False) or p.hr_checkpoint_name is None:
# hiresfix quickbutton may not need reload of firstpass model
sd_models.forge_model_reload() # model can be changed for example by refiner, hiresfix

p.sd_model.forge_objects = p.sd_model.forge_objects_original.shallow_copy()
p.prompts = p.all_prompts[n * p.batch_size:(n + 1) * p.batch_size]
Expand Down Expand Up @@ -1183,7 +1185,6 @@ def old_hires_fix_first_pass_dimensions(width, height):
@dataclass(repr=False)
class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
enable_hr: bool = False
highresfix_quick: bool = False
denoising_strength: float = 0.75
firstphase_width: int = 0
firstphase_height: int = 0
Expand Down Expand Up @@ -1402,24 +1403,24 @@ def sample(self, conditioning, unconditional_conditioning, seeds, subseeds, subs

reload = False
if 'Use same choices' not in self.hr_additional_modules:
if sorted(self.hr_additional_modules) != sorted(fp_additional_modules):
main_entry.modules_change(self.hr_additional_modules, save=False, refresh=False)
modules_changed = main_entry.modules_change(self.hr_additional_modules, save=False, refresh=False)
if modules_changed:
reload = True

if self.hr_checkpoint_name and self.hr_checkpoint_name != 'Use same checkpoint':
if self.hr_checkpoint_name != fp_checkpoint:
checkpoint_changed = main_entry.checkpoint_change(self.hr_checkpoint_name, save=False, refresh=False)
if checkpoint_changed:
self.firstpass_use_distilled_cfg_scale = self.sd_model.use_distilled_cfg_scale

main_entry.checkpoint_change(self.hr_checkpoint_name, save=False, refresh=False)
reload = True

if reload:
try:
main_entry.refresh_model_loading_parameters()
sd_models.forge_model_reload()
finally:
main_entry.modules_change(fp_additional_modules, save=False, refresh=False)
main_entry.checkpoint_change(fp_checkpoint, save=False)
main_entry.checkpoint_change(fp_checkpoint, save=False, refresh=False)
main_entry.refresh_model_loading_parameters()

if self.sd_model.use_distilled_cfg_scale:
self.extra_generation_params['Hires Distilled CFG Scale'] = self.hr_distilled_cfg
Expand Down Expand Up @@ -1652,7 +1653,6 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing):
force_task_id: str = None

hr_distilled_cfg: float = 3.5 # needed here for cached_params
highresfix_quick: bool = False

image_mask: Any = field(default=None, init=False)

Expand Down
5 changes: 3 additions & 2 deletions modules/sysinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ def set_config(req: dict[str, Any], is_api=False, run_callbacks=True, save_confi
if k == 'sd_model_checkpoint':
if v is not None and v not in sd_models.checkpoint_aliases:
raise RuntimeError(f"model {v!r} not found")
main_entry.checkpoint_change(v, save=False, refresh=False)
should_refresh_model_loading_params = True
checkpoint_changed = main_entry.checkpoint_change(v, save=False, refresh=False)
if checkpoint_changed:
should_refresh_model_loading_params = True
elif k == 'forge_additional_modules':
modules_changed = main_entry.modules_change(v, save=False, refresh=False)
if modules_changed:
Expand Down
1 change: 0 additions & 1 deletion modules/txt2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def txt2img_upscale_function(id_task: str, request: gr.Request, gallery, gallery
p.extra_generation_params['Original Size'] = f'{args[8]}x{args[7]}'

p.override_settings['save_images_before_highres_fix'] = False
p.highresfix_quick = True

with closing(p):
processed = modules.scripts.scripts_txt2img.run(p, *p.script_args)
Expand Down
10 changes: 8 additions & 2 deletions modules_forge/main_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,19 @@ def refresh_model_loading_parameters():


def checkpoint_change(ckpt_name:str, save=True, refresh=True):
""" checkpoint name can be a number of valid aliases. Returns True if checkpoint changed. """
new_ckpt_info = sd_models.get_closet_checkpoint_match(ckpt_name)
current_ckpt_info = sd_models.get_closet_checkpoint_match(shared.opts.data.get('sd_model_checkpoint', ''))
if new_ckpt_info == current_ckpt_info:
return False

shared.opts.set('sd_model_checkpoint', ckpt_name)

if save:
shared.opts.save(shared.config_filename)
if refresh:
refresh_model_loading_parameters()
return
return True


def modules_change(module_values:list, save=True, refresh=True) -> bool:
Expand All @@ -258,7 +264,7 @@ def modules_change(module_values:list, save=True, refresh=True) -> bool:
modules.append(module_list[module_name])

# skip further processing if value unchanged
if modules == shared.opts.data.get('forge_additional_modules'):
if sorted(modules) == sorted(shared.opts.data.get('forge_additional_modules', [])):
return False

shared.opts.set('forge_additional_modules', modules)
Expand Down

0 comments on commit f5cbd6c

Please sign in to comment.