Skip to content

Commit

Permalink
fix corner-case model load on startup
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Mandic <mandic00@live.com>
  • Loading branch information
vladmandic committed Oct 9, 2024
1 parent f5ad8e5 commit f17fbe0
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 19 deletions.
2 changes: 2 additions & 0 deletions extensions-builtin/Lora/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@


def assign_network_names_to_compvis_modules(sd_model):
if sd_model is None:
return
network_layer_mapping = {}
if shared.native:
if hasattr(shared.sd_model, 'text_encoder') and shared.sd_model.text_encoder is not None:
Expand Down
14 changes: 7 additions & 7 deletions html/reference.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"Tempest SD-XL v0.1": {
"path": "TempestV0.1-Artistic.safetensors@https://huggingface.co/dataautogpt3/TempestV0.1/resolve/main/TempestV0.1-Artistic.safetensors?download=true",
"preview": "TempestV0.1-Artistic.jpg",
"desc": "The TempestV0.1 Initiative is a powerhouse in image generation, leveraging an unparalleled dataset of over 6 million images. The collection's vast scale, with resolutions from 1400x2100 to 4800x7200, encompasses 200GB of high-quality content.",
"extras": "width: 2048, height: 1024, sampler: DEIS, steps: 40, cfg_scale: 6.0"
},

"Juggernaut SD-XL XI": {
"path": "juggernautXL_juggXIByRundiffusion.safetensors@https://civitai.com/api/download/models/782002",
"preview": "juggernautXL_v9Rundiffusionphoto2.jpg",
Expand Down Expand Up @@ -45,13 +52,6 @@
"extras": "width: 1024, height: 1024, sampler: DPM SDE, steps: 8, cfg_scale: 2.0"
},

"Tempest SD-XL v0.1": {
"path": "TempestV0.1-Artistic.safetensors@https://huggingface.co/dataautogpt3/TempestV0.1/resolve/main/TempestV0.1-Artistic.safetensors?download=true",
"preview": "TempestV0.1-Artistic.jpg",
"desc": "The TempestV0.1 Initiative is a powerhouse in image generation, leveraging an unparalleled dataset of over 6 million images. The collection's vast scale, with resolutions from 1400x2100 to 4800x7200, encompasses 200GB of high-quality content.",
"extras": "width: 2048, height: 1024, sampler: DEIS, steps: 40, cfg_scale: 6.0"
},

"SDXS DreamShaper 512": {
"path": "IDKiro/sdxs-512-dreamshaper",
"preview": "IDKiro--sdxs-512-dreamshaper.jpg",
Expand Down
7 changes: 1 addition & 6 deletions modules/modelloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,7 @@ def find_diffuser(name: str):
if len(repo) > 0:
return repo['name']
hf_api = hf.HfApi()
hf_filter = hf.ModelFilter(
model_name=name,
# task='text-to-image',
library=['diffusers'],
)
models = list(hf_api.list_models(filter=hf_filter, full=True, limit=20, sort="downloads", direction=-1))
models = list(hf_api.list_models(model_name=name, library=['diffusers'], full=True, limit=20, sort="downloads", direction=-1))
shared.log.debug(f'Searching diffusers models: {name} {len(models) > 0}')
if len(models) > 0:
return models[0].id
Expand Down
2 changes: 1 addition & 1 deletion modules/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
extensions_builtin_dir = "extensions-builtin"
sd_configs_path = os.path.join(script_path, "configs")
sd_default_config = os.path.join(sd_configs_path, "v1-inference.yaml")
sd_model_file = cli.ckpt or os.path.join(script_path, 'model.ckpt') # not used
sd_model_file = cli.ckpt or os.path.join(script_path, 'model.safetensors') # not used
default_sd_model_file = sd_model_file # not used
debug = log.trace if os.environ.get('SD_PATH_DEBUG', None) is not None else lambda *args, **kwargs: None
debug('Trace: PATH')
Expand Down
7 changes: 4 additions & 3 deletions modules/sd_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def select_checkpoint(op='model'):
return None
# checkpoint_info = next(iter(checkpoints_list.values()))
if model_checkpoint is not None:
if model_checkpoint != 'model.ckpt' and model_checkpoint != 'stabilityai/stable-diffusion-xl-base-1.0':
if model_checkpoint != 'model.safetensors' and model_checkpoint != 'stabilityai/stable-diffusion-xl-base-1.0':
shared.log.warning(f'Load {op}: select="{model_checkpoint}" not found')
else:
shared.log.info("Selecting first available checkpoint")
Expand Down Expand Up @@ -1035,7 +1035,7 @@ def load_diffuser(checkpoint_info=None, already_loaded_state_dict=None, timer=No
if shared.opts.diffusers_pipeline == 'Custom Diffusers Pipeline' and len(shared.opts.custom_diffusers_pipeline) > 0:
shared.log.debug(f'Model pipeline: pipeline="{shared.opts.custom_diffusers_pipeline}"')
diffusers_load_config['custom_pipeline'] = shared.opts.custom_diffusers_pipeline
if shared.opts.data.get('sd_model_checkpoint', '') == 'model.ckpt' or shared.opts.data.get('sd_model_checkpoint', '') == '':
if shared.opts.data.get('sd_model_checkpoint', '') == 'model.safetensors' or shared.opts.data.get('sd_model_checkpoint', '') == '':
shared.opts.data['sd_model_checkpoint'] = "stabilityai/stable-diffusion-xl-base-1.0"

if op == 'model' or op == 'dict':
Expand Down Expand Up @@ -1351,7 +1351,8 @@ def load_diffuser(checkpoint_info=None, already_loaded_state_dict=None, timer=No
errors.display(e, "Model")

devices.torch_gc(force=True)
script_callbacks.model_loaded_callback(sd_model)
if sd_model is not None:
script_callbacks.model_loaded_callback(sd_model)
shared.log.info(f"Load {op}: time={timer.summary()} native={get_native(sd_model)} memory={memory_stats()}")


Expand Down
2 changes: 1 addition & 1 deletion modules/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def list_checkpoint_tiles():
import modules.sd_models # pylint: disable=W0621
return modules.sd_models.checkpoint_tiles()

default_checkpoint = list_checkpoint_tiles()[0] if len(list_checkpoint_tiles()) > 0 else "model.ckpt"
default_checkpoint = list_checkpoint_tiles()[0] if len(list_checkpoint_tiles()) > 0 else "model.safetensors"


def is_url(string):
Expand Down
2 changes: 1 addition & 1 deletion webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def sigint_handler(_sig, _frame):


def load_model():
if not shared.opts.sd_checkpoint_autoload or (shared.cmd_opts.ckpt is not None and shared.cmd_opts.ckpt.lower() != 'none'):
if not shared.opts.sd_checkpoint_autoload and shared.cmd_opts.ckpt is not None:
log.debug('Model auto load disabled')
else:
shared.state.begin('Load')
Expand Down

0 comments on commit f17fbe0

Please sign in to comment.