mirror of
https://github.com/lllyasviel/stable-diffusion-webui-forge.git
synced 2026-02-01 13:59:47 +00:00
Improve options management (#2078)
- `/sdapi/v1/options` GET now calls `get_config()` from **sysinfo** module, instead of from its own version of the function. - Defined a new, flexible and more robust `set_config()` function in **sysinfo** module, which: - obsoletes redundant code - skips updating values that are unchanged - has flexible args for both API and UI use - `/sdapi/v1/options` POST and `override_settings` now use the new `set_config()` function. `set_config()` could possibly obsolete additional functions, but I'm not going to get into that just yet. - Options for `forge_additional_modules` can now be provided either as the file path, or just the module name. - Most importantly, `refresh_model_loading_parameters()` is now only called ONCE per request, and **only** if necessary. - It is now much easier to call `shared.opts.save()` as needed
This commit is contained in:
@@ -20,6 +20,7 @@ from modules import devices, prompt_parser, masking, sd_samplers, lowvram, infot
|
||||
from modules.rng import slerp, get_noise_source_type # noqa: F401
|
||||
from modules.sd_samplers_common import images_tensor_to_samples, decode_first_stage, approximation_indexes
|
||||
from modules.shared import opts, cmd_opts, state
|
||||
from modules.sysinfo import set_config
|
||||
import modules.shared as shared
|
||||
import modules.paths as paths
|
||||
import modules.face_restoration
|
||||
@@ -818,24 +819,8 @@ def process_images(p: StableDiffusionProcessing) -> Processed:
|
||||
if sd_models.checkpoint_aliases.get(p.override_settings.get('sd_model_checkpoint')) is None:
|
||||
p.override_settings.pop('sd_model_checkpoint', None)
|
||||
|
||||
temp_memory_changes = {}
|
||||
memory_keys = ['forge_inference_memory', 'forge_async_loading', 'forge_pin_shared_memory']
|
||||
|
||||
for k, v in p.override_settings.items():
|
||||
# options for memory/modules/checkpoints are set in their dedicated functions
|
||||
if k in memory_keys:
|
||||
mem_k = k[len('forge_'):] # remove 'forge_' prefix
|
||||
temp_memory_changes[mem_k] = v
|
||||
elif k == 'forge_additional_modules':
|
||||
main_entry.modules_change(v)
|
||||
elif k == 'sd_model_checkpoint':
|
||||
main_entry.checkpoint_change(v)
|
||||
# set all other options
|
||||
else:
|
||||
opts.set(k, v, is_api=True, run_callbacks=False)
|
||||
|
||||
if temp_memory_changes:
|
||||
main_entry.refresh_memory_management_settings(**temp_memory_changes)
|
||||
# apply any options overrides
|
||||
set_config(p.override_settings, is_api=True, run_callbacks=False, save_config=False)
|
||||
|
||||
# load/reload model and manage prompt cache as needed
|
||||
manage_model_and_prompt_cache(p)
|
||||
@@ -850,18 +835,9 @@ def process_images(p: StableDiffusionProcessing) -> Processed:
|
||||
res = process_images_inner(p)
|
||||
|
||||
finally:
|
||||
# restore opts to original state
|
||||
# restore original options
|
||||
if p.override_settings_restore_afterwards:
|
||||
for k, v in stored_opts.items():
|
||||
if k == 'forge_additional_modules':
|
||||
main_entry.modules_change(v)
|
||||
elif k == 'sd_model_checkpoint':
|
||||
main_entry.checkpoint_change(v)
|
||||
else:
|
||||
setattr(opts, k, v)
|
||||
|
||||
if temp_memory_changes:
|
||||
main_entry.refresh_memory_management_settings() # applies the set options by default
|
||||
set_config(stored_opts, save_config=False)
|
||||
|
||||
return res
|
||||
|
||||
|
||||
Reference in New Issue
Block a user