code: def load_from_unet(self, from_pretrained_unet, from_NeMo=True):
      if not from_NeMo:
          print(
              "loading from other source of unet is experimental! Carefully check if keys are loaded correctly."
          )
      else:
          print("Loading unet blocks from sd")
  
          state_dict = torch.load(
              from_pretrained_unet, map_location="cpu"
          )
          state_dict = state_dict["state_dict"]
          model_state_dict = self.state_dict()
  
          re_state_dict = {}
          for key_, value_ in state_dict.items():
              if key_.startswith("model.model.diffusion_model"):
                  re_state_dict[
                      key_.replace("model.model.diffusion_model.", "")
                  ] = value_
              if key_.startswith("model.diffusion_model"):
                  re_state_dict[
                      key_.replace("model.diffusion_model.", "")
                  ] = value_
              if key_.startswith(
                  "model.model._orig_mod.diffusion_model"
              ):
                  re_state_dict[
                      key_.replace(
                          "model.model._orig_mod.diffusion_model.", ""
                      )
                  ] = value_
              if key_.startswith("model._orig_mod.diffusion_model"):
                  re_state_dict[
                      key_.replace(
                          "model._orig_mod.diffusion_model.", ""
                      )
                  ] = value_
  
          expected_keys = list(model_state_dict.keys())
          loaded_keys = list(re_state_dict.keys())
          missing_keys = list(set(expected_keys) - set(loaded_keys))
          unexpected_keys = list(set(loaded_keys) - set(expected_keys))
  
          if (
              "input_blocks.1.0.in_layers.2.weight" in loaded_keys
              and "input_blocks.1.0.in_layers.1.weight" in expected_keys
          ):
              # GroupNormOpt fuses activation function to one layer, thus the indexing of weights are shifted for following
              for key_ in missing_keys:
                  if key_.startswith("input_blocks") or key_.startswith(
                      "middle_block."
                  ):
                      s = key_.split(".")
                      idx = int(s[-2])
                      new_key_ = ".".join(
                          s[:-2] + [str(int(idx + 1))] + [s[-1]]
                      )
                      re_state_dict[key_] = re_state_dict[new_key_]
  
              loaded_keys = list(re_state_dict.keys())
              missing_keys = list(set(expected_keys) - set(loaded_keys))
              unexpected_keys = list(
                  set(loaded_keys) - set(expected_keys)
              )
  
          self.load_state_dict(re_state_dict, strict=False)
  
          if len(missing_keys) > 42:
              print(
                  "warning: only input hint blocks and zero conv layers are randomly initialized. This message indicates some unet blocks are not loaded correctly."
              )
              print(f"There is {len(missing_keys)} total missing keys")
              print("Missing:", missing_keys)
              print("Unexpected:", unexpected_keys)
          else:
              print("sd blocks loaded successfully")
  
imports: from typing import Any
  import einops
  import torch
  import torch.nn
  from einops import rearrange, repeat
  from omegaconf import DictConfig
  from pytorch_lightning import Trainer
  from pytorch_lightning.utilities.rank_zero import rank_zero_only
  from torch._inductor import config
  from nemo.collections.multimodal.data.controlnet.controlnet_dataset import build_train_valid_datasets
  from nemo.collections.multimodal.models.text_to_image.stable_diffusion.ldm.ddpm import LatentDiffusion
  from nemo.collections.multimodal.models.text_to_image.stable_diffusion.samplers.ddim import DDIMSampler
  from nemo.collections.multimodal.modules.stable_diffusion.attention import SpatialTransformer
  from nemo.collections.multimodal.modules.stable_diffusion.diffusionmodules.openaimodel import AttentionBlock, Downsample, ResBlock, TimestepEmbedSequential, UNetModel
  from nemo.collections.multimodal.modules.stable_diffusion.diffusionmodules.util import conv_nd, linear, timestep_embedding, zero_module
  from nemo.collections.multimodal.parts.stable_diffusion.utils import exists, log_txt_as_img
  from nemo.collections.nlp.models.language_modeling.megatron_base_model import MegatronBaseModel
  from nemo.collections.nlp.modules.common.megatron.module import Float16Module
  from nemo.utils import logging
label_desc: Use image node_id 2 for calling the ControlNet obj's underlying member method code with example usage: obj.load_from_unet(from_pretrained_unet, from_NeMo) without return types