code: def load_model_weights(
      model, checkpoint_info: CheckpointInfo, state_dict, timer
  ):
      sd_model_hash = checkpoint_info.calculate_shorthash()
      timer.record("calculate hash")
  
      if not SkipWritingToConfig.skip:
          shared.opts.data[
              "sd_model_checkpoint"
          ] = checkpoint_info.title
  
      if state_dict is None:
          state_dict = get_checkpoint_state_dict(checkpoint_info, timer)
  
      model.is_sdxl = hasattr(model, "conditioner")
      model.is_sd2 = not model.is_sdxl and hasattr(
          model.cond_stage_model, "model"
      )
      model.is_sd1 = not model.is_sdxl and not model.is_sd2
      model.is_ssd = (
          model.is_sdxl
          and "model.diffusion_model.middle_block.1.transformer_blocks.0.attn1.to_q.weight"
          not in state_dict.keys()
      )
      if model.is_sdxl:
          sd_models_xl.extend_sdxl(model)
  
      if model.is_ssd:
          sd_hijack.model_hijack.convert_sdxl_to_ssd(model)
  
      if shared.opts.sd_checkpoint_cache > 0:
          # cache newly loaded model
          checkpoints_loaded[checkpoint_info] = state_dict.copy()
  
      model.load_state_dict(state_dict, strict=False)
      timer.record("apply weights to model")
  
      del state_dict
  
      if shared.cmd_opts.opt_channelslast:
          model.to(memory_format=torch.channels_last)
          timer.record("apply channels_last")
  
      if shared.cmd_opts.no_half:
          model.float()
          devices.dtype_unet = torch.float32
          timer.record("apply float()")
      else:
          vae = model.first_stage_model
          depth_model = getattr(model, "depth_model", None)
  
          # with --no-half-vae, remove VAE from model when doing half() to prevent its weights from being converted to float16
          if shared.cmd_opts.no_half_vae:
              model.first_stage_model = None
          # with --upcast-sampling, don't convert the depth model weights to float16
          if shared.cmd_opts.upcast_sampling and depth_model:
              model.depth_model = None
  
          model.half()
          model.first_stage_model = vae
          if depth_model:
              model.depth_model = depth_model
  
          devices.dtype_unet = torch.float16
          timer.record("apply half()")
  
      devices.unet_needs_upcast = (
          shared.cmd_opts.upcast_sampling
          and devices.dtype == torch.float16
          and devices.dtype_unet == torch.float16
      )
  
      model.first_stage_model.to(devices.dtype_vae)
      timer.record("apply dtype to VAE")
  
      # clean up cache if limit is reached
      while len(checkpoints_loaded) > shared.opts.sd_checkpoint_cache:
          checkpoints_loaded.popitem(last=False)
  
      model.sd_model_hash = sd_model_hash
      model.sd_model_checkpoint = checkpoint_info.filename
      model.sd_checkpoint_info = checkpoint_info
      shared.opts.data["sd_checkpoint_hash"] = checkpoint_info.sha256
  
      if hasattr(model, "logvar"):
          model.logvar = model.logvar.to(
              devices.device
          )  # fix for training
  
      sd_vae.delete_base_vae()
      sd_vae.clear_loaded_vae()
      vae_file, vae_source = sd_vae.resolve_vae(
          checkpoint_info.filename
      ).tuple()
      sd_vae.load_vae(model, vae_file, vae_source)
      timer.record("load VAE")
  
imports: import collections
  import os.path
  import sys
  import threading
  import torch
  import re
  import safetensors.torch
  from omegaconf import OmegaConf, ListConfig
  from os import mkdir
  from urllib import request
  import ldm.modules.midas
  from ldm.util import instantiate_from_config
  from modules import paths, shared, modelloader, devices, script_callbacks, sd_vae, sd_disable_initialization, errors, hashes, sd_models_config, sd_unet, sd_models_xl, cache, extra_networks, processing, lowvram, sd_hijack, patches
  from modules.timer import Timer
  import tomesd
  import numpy
label_desc: Use image node_id 13 for calling a global function with example usage: load_model_weights(model, checkpoint_info, state_dict, timer) without return types