class_docstr: Load LoRA layers into a [`UNet2DCondtionModel`].
code: def _load_ip_adapter_weights(self, state_dict):
      from ..models.attention_processor import (
          AttnProcessor,
          AttnProcessor2_0,
          IPAdapterAttnProcessor,
          IPAdapterAttnProcessor2_0,
      )
  
      if "proj.weight" in state_dict["image_proj"]:
          # IP-Adapter
          num_image_text_embeds = 4
      elif "proj.3.weight" in state_dict["image_proj"]:
          # IP-Adapter Full Face
          num_image_text_embeds = 257  # 256 CLIP tokens + 1 CLS token
      else:
          # IP-Adapter Plus
          num_image_text_embeds = state_dict["image_proj"][
              "latents"
          ].shape[1]
  
      # Set encoder_hid_proj after loading ip_adapter weights,
      # because `IPAdapterPlusImageProjection` also has `attn_processors`.
      self.encoder_hid_proj = None
  
      # set ip-adapter cross-attention processors & load state_dict
      attn_procs = {}
      key_id = 1
      for name in self.attn_processors.keys():
          cross_attention_dim = (
              None
              if name.endswith("attn1.processor")
              else self.config.cross_attention_dim
          )
          if name.startswith("mid_block"):
              hidden_size = self.config.block_out_channels[-1]
          elif name.startswith("up_blocks"):
              block_id = int(name[len("up_blocks.")])
              hidden_size = list(
                  reversed(self.config.block_out_channels)
              )[block_id]
          elif name.startswith("down_blocks"):
              block_id = int(name[len("down_blocks.")])
              hidden_size = self.config.block_out_channels[block_id]
          if cross_attention_dim is None or "motion_modules" in name:
              attn_processor_class = (
                  AttnProcessor2_0
                  if hasattr(F, "scaled_dot_product_attention")
                  else AttnProcessor
              )
              attn_procs[name] = attn_processor_class()
          else:
              attn_processor_class = (
                  IPAdapterAttnProcessor2_0
                  if hasattr(F, "scaled_dot_product_attention")
                  else IPAdapterAttnProcessor
              )
              attn_procs[name] = attn_processor_class(
                  hidden_size=hidden_size,
                  cross_attention_dim=cross_attention_dim,
                  scale=1.0,
                  num_tokens=num_image_text_embeds,
              ).to(dtype=self.dtype, device=self.device)
  
              value_dict = {}
              for k, w in attn_procs[name].state_dict().items():
                  value_dict.update(
                      {
                          f"{k}": state_dict["ip_adapter"][
                              f"{key_id}.{k}"
                          ]
                      }
                  )
  
              attn_procs[name].load_state_dict(value_dict)
              key_id += 2
  
      self.set_attn_processor(attn_procs)
  
      # convert IP-Adapter Image Projection layers to diffusers
      image_projection = (
          self._convert_ip_adapter_image_proj_to_diffusers(
              state_dict["image_proj"]
          )
      )
  
      self.encoder_hid_proj = image_projection.to(
          device=self.device, dtype=self.dtype
      )
      self.config.encoder_hid_dim_type = "ip_image_proj"
  
imports: import inspect
  import os
  from collections import defaultdict
  from contextlib import nullcontext
  from functools import partial
  from typing import Callable, Dict, List, Optional, Union
  import safetensors
  import torch
  import torch.nn.functional
  from huggingface_hub.utils import validate_hf_hub_args
  from torch import nn
  from ..models.embeddings import ImageProjection, IPAdapterFullImageProjection, IPAdapterPlusImageProjection
  from ..models.modeling_utils import _LOW_CPU_MEM_USAGE_DEFAULT, load_model_dict_into_meta
  from ..utils import USE_PEFT_BACKEND, _get_model_file, delete_adapter_layers, is_accelerate_available, logging, set_adapter_layers, set_weights_and_activate_adapters
  from .utils import AttnProcsLayers
label_desc: Use image node_id 13 for calling the UNet2DConditionLoadersMixin obj's underlying member method code with example usage: obj._load_ip_adapter_weights(state_dict) without return types