code: def load_model_from_config(config, ckpt, verbose=True, freeze=True):
      print(f"Loading model from {ckpt}")
      if ckpt.endswith("ckpt"):
          pl_sd = torch.load(ckpt, map_location="cpu")
          if "global_step" in pl_sd:
              print(f"Global Step: {pl_sd['global_step']}")
          sd = pl_sd["state_dict"]
      elif ckpt.endswith("safetensors"):
          sd = load_safetensors(ckpt)
      else:
          raise NotImplementedError
  
      model = instantiate_from_config(config.model)
  
      m, u = model.load_state_dict(sd, strict=False)
  
      if len(m) > 0 and verbose:
          print("missing keys:")
          print(m)
      if len(u) > 0 and verbose:
          print("unexpected keys:")
          print(u)
  
      if freeze:
          for param in model.parameters():
              param.requires_grad = False
  
      model.eval()
      return model
  
imports: import functools
  import importlib
  import os
  from functools import partial
  from inspect import isfunction
  import fsspec
  import numpy
  import torch
  from PIL import Image, ImageDraw, ImageFont
  from safetensors.torch import load_file
label_desc: Use image node_id 22 for calling a global function with example usage: load_model_from_config(config, ckpt, verbose, freeze) and returns: model