redo timers

This commit is contained in:
Vladimir Mandic
2023-04-04 10:18:39 -04:00
parent 0d18460fe8
commit 8cc3a64201
5 changed files with 37 additions and 39 deletions
+1 -1
View File
@@ -176,7 +176,7 @@
"sd_hypernetwork_strength": 1.0,
"sd_hypernetwork": "None",
"sd_lora": "",
"sd_model_checkpoint": "v1-5-pruned-emaonly.safetensors [6ce0161689]",
"sd_model_checkpoint": "sd-v15-runwayml.ckpt [cc6cb27103]",
"sd_vae_as_default": false,
"sd_vae_checkpoint_cache": 0,
"sd_vae": "vae-ft-mse-840000-ema-pruned.ckpt",
+15 -17
View File
@@ -269,14 +269,14 @@ def get_checkpoint_state_dict(checkpoint_info: CheckpointInfo, timer):
return checkpoints_loaded[checkpoint_info]
res = read_state_dict(checkpoint_info.filename)
timer.record("load weights")
timer.record("load")
return res
def load_model_weights(model, checkpoint_info: CheckpointInfo, state_dict, timer):
sd_model_hash = checkpoint_info.calculate_shorthash()
timer.record("calculate hash")
timer.record("hash")
shared.opts.data["sd_model_checkpoint"] = checkpoint_info.title
@@ -285,7 +285,7 @@ def load_model_weights(model, checkpoint_info: CheckpointInfo, state_dict, timer
model.load_state_dict(state_dict, strict=False)
del state_dict
timer.record("apply weights")
timer.record("apply")
if shared.opts.sd_checkpoint_cache > 0:
# cache newly loaded model
@@ -293,7 +293,7 @@ def load_model_weights(model, checkpoint_info: CheckpointInfo, state_dict, timer
if shared.cmd_opts.opt_channelslast:
model.to(memory_format=torch.channels_last)
timer.record("apply channels_last")
timer.record("channels")
if not shared.cmd_opts.no_half:
vae = model.first_stage_model
@@ -333,7 +333,7 @@ def load_model_weights(model, checkpoint_info: CheckpointInfo, state_dict, timer
sd_vae.clear_loaded_vae()
vae_file, vae_source = sd_vae.resolve_vae(checkpoint_info.filename)
sd_vae.load_vae(model, vae_file, vae_source)
timer.record("load vae")
timer.record("vae")
def enable_midas_autodownload():
@@ -432,12 +432,10 @@ def load_model(checkpoint_info=None, already_loaded_state_dict=None):
clip_is_included_into_sd = sd1_clip_weight in state_dict or sd2_clip_weight in state_dict
timer.record("find config")
sd_config = OmegaConf.load(checkpoint_config)
repair_config(sd_config)
timer.record("load config")
timer.record("config")
print(f"Creating model from config: {checkpoint_config}")
@@ -450,7 +448,7 @@ def load_model(checkpoint_info=None, already_loaded_state_dict=None):
sd_model.used_config = checkpoint_config
timer.record("create model")
timer.record("create")
load_model_weights(sd_model, checkpoint_info, state_dict, timer)
@@ -459,7 +457,7 @@ def load_model(checkpoint_info=None, already_loaded_state_dict=None):
else:
sd_model.to(shared.device)
timer.record("device move")
timer.record("move")
sd_hijack.model_hijack.hijack(sd_model)
@@ -470,13 +468,13 @@ def load_model(checkpoint_info=None, already_loaded_state_dict=None):
sd_hijack.model_hijack.embedding_db.load_textual_inversion_embeddings(force_reload=True) # Reload embeddings after model load as they may or may not fit the model
timer.record("load textual inversion embeddings")
timer.record("embeddings")
script_callbacks.model_loaded_callback(sd_model)
timer.record("scripts callbacks")
timer.record("callbacks")
print(f"Model loaded in {timer.summary()}.")
print(f"Model loaded in {timer.summary()}")
return sd_model
@@ -527,13 +525,13 @@ def reload_model_weights(sd_model=None, info=None):
timer.record("hijack")
script_callbacks.model_loaded_callback(sd_model)
timer.record("script callbacks")
timer.record("callbacks")
if not shared.cmd_opts.lowvram and not shared.cmd_opts.medvram:
sd_model.to(devices.device)
timer.record("device move")
timer.record("device")
print(f"Weights loaded in {timer.summary()}.")
print(f"Weights loaded in {timer.summary()}")
def unload_model_weights(sd_model=None, info=None):
from modules import lowvram, devices, sd_hijack
@@ -551,6 +549,6 @@ def unload_model_weights(sd_model=None, info=None):
devices.torch_gc()
torch.cuda.empty_cache()
print(f"Unloaded weights {timer.summary()}.")
print(f"Unloaded weights {timer.summary()}")
return sd_model
+2 -2
View File
@@ -24,12 +24,12 @@ class Timer:
def summary(self):
res = f"{self.total:.1f}s"
additions = [x for x in self.records.items() if x[1] >= 0.1]
additions = [x for x in self.records.items() if x[1] >= 0.05]
if not additions:
return res
res += " ("
res += ", ".join([f"{category}: {time_taken:.1f}s" for category, time_taken in additions])
res += " ".join([f"{category}={time_taken:.1f}s" for category, time_taken in additions])
res += ")"
return res
+18 -18
View File
@@ -23,7 +23,7 @@ import torchvision
import pytorch_lightning # pytorch_lightning should be imported after torch, but it re-enables warnings on import so import once to disable them
warnings.filterwarnings(action="ignore", category=DeprecationWarning, module="pytorch_lightning")
warnings.filterwarnings(action="ignore", category=UserWarning, module="torchvision")
startup_timer.record("import torch")
startup_timer.record("torch")
import gradio
import ldm.modules.encoders.modules
@@ -58,7 +58,7 @@ from modules import modelloader
from modules.shared import cmd_opts
import modules.hypernetworks.hypernetwork
startup_timer.record("import libraries")
startup_timer.record("libraries")
if cmd_opts.server_name:
@@ -79,7 +79,7 @@ def initialize():
print(f'Torch {getattr(torch, "__long_version__", torch.__version__)} running on CPU')
extensions.list_extensions()
startup_timer.record("list extensions")
startup_timer.record("extensions")
if cmd_opts.ui_debug_mode:
shared.sd_upscalers = upscaler.UpscalerLanczos().scalers
@@ -88,28 +88,28 @@ def initialize():
modelloader.cleanup_models()
modules.sd_models.setup_model()
startup_timer.record("list models")
startup_timer.record("models")
codeformer.setup_model(cmd_opts.codeformer_models_path)
startup_timer.record("setup codeformer")
startup_timer.record("codeformer")
gfpgan.setup_model(cmd_opts.gfpgan_models_path)
startup_timer.record("setup gfpgan")
startup_timer.record("gfpgan")
modelloader.list_builtin_upscalers()
startup_timer.record("list builtin upscalers")
startup_timer.record("upscalers")
modules.scripts.load_scripts()
startup_timer.record("load scripts")
startup_timer.record("scripts")
modelloader.load_upscalers()
startup_timer.record("load upscalers")
startup_timer.record("upscalers")
modules.sd_vae.refresh_vae_list()
startup_timer.record("refresh VAE")
startup_timer.record("vae")
modules.textual_inversion.textual_inversion.list_textual_inversion_templates()
startup_timer.record("refresh textual inversion templates")
startup_timer.record("embeddings")
shared.opts.onchange("sd_vae", wrap_queued_call(lambda: modules.sd_vae.reload_vae_weights()), call=False)
shared.opts.onchange("sd_vae_as_default", wrap_queued_call(lambda: modules.sd_vae.reload_vae_weights()), call=False)
@@ -117,7 +117,7 @@ def initialize():
startup_timer.record("opts onchange")
shared.reload_hypernetworks()
startup_timer.record("reload hypernets")
startup_timer.record("hypernets")
ui_extra_networks.intialize()
ui_extra_networks.register_page(ui_extra_networks_textual_inversion.ExtraNetworksPageTextualInversion())
@@ -165,7 +165,7 @@ def load_model():
shared.opts.data["sd_model_checkpoint"] = shared.sd_model.sd_checkpoint_info.title
shared.opts.onchange("sd_model_checkpoint", wrap_queued_call(lambda: modules.sd_models.reload_model_weights()))
shared.state.end()
startup_timer.record("load checkpoint")
startup_timer.record("checkpoint")
def setup_middleware(app):
@@ -196,7 +196,7 @@ def api_only():
modules.script_callbacks.app_started_callback(None, app)
print(f"Startup time: {startup_timer.summary()}.")
print(f"Startup time: {startup_timer.summary()}")
api.launch(server_name="0.0.0.0" if cmd_opts.listen else "127.0.0.1", port=cmd_opts.port if cmd_opts.port else 7861)
@@ -206,13 +206,13 @@ def webui():
if shared.opts.clean_temp_dir_at_start:
ui_tempdir.cleanup_tmpdr()
startup_timer.record("cleanup temp dir")
startup_timer.record("cleanup")
modules.script_callbacks.before_ui_callback()
startup_timer.record("scripts before_ui_callback")
shared.demo = modules.ui.create_ui()
startup_timer.record("create ui")
startup_timer.record("ui")
if not cmd_opts.no_gradio_queue:
shared.demo.queue(16)
@@ -247,7 +247,7 @@ def webui():
cmd_opts.autolaunch = False
startup_timer.record("gradio launch")
startup_timer.record("gradio")
app.user_middleware = [x for x in app.user_middleware if x.cls.__name__ != 'CORSMiddleware']
@@ -265,7 +265,7 @@ def webui():
load_model()
print(f"Startup time: {startup_timer.summary()}.")
print(f"Startup time: {startup_timer.summary()}")
while True:
time.sleep(0.1)