code: def test_ip_adapter(self):
      (
          init_dict,
          inputs_dict,
      ) = self.prepare_init_args_and_inputs_for_common()
  
      init_dict["attention_head_dim"] = (8, 16)
  
      model = self.model_class(**init_dict)
      model.to(torch_device)
  
      # forward pass without ip-adapter
      with torch.no_grad():
          sample1 = model(**inputs_dict).sample
  
      # update inputs_dict for ip-adapter
      batch_size = inputs_dict["encoder_hidden_states"].shape[0]
      image_embeds = floats_tensor(
          (batch_size, 1, model.cross_attention_dim)
      ).to(torch_device)
      inputs_dict["added_cond_kwargs"] = {"image_embeds": image_embeds}
  
      # make ip_adapter_1 and ip_adapter_2
      ip_adapter_1 = create_ip_adapter_state_dict(model)
  
      image_proj_state_dict_2 = {
          k: w + 1.0 for k, w in ip_adapter_1["image_proj"].items()
      }
      cross_attn_state_dict_2 = {
          k: w + 1.0 for k, w in ip_adapter_1["ip_adapter"].items()
      }
      ip_adapter_2 = {}
      ip_adapter_2.update(
          {
              "image_proj": image_proj_state_dict_2,
              "ip_adapter": cross_attn_state_dict_2,
          }
      )
  
      # forward pass ip_adapter_1
      model._load_ip_adapter_weights(ip_adapter_1)
      assert model.config.encoder_hid_dim_type == "ip_image_proj"
      assert model.encoder_hid_proj is not None
      assert model.down_blocks[0].attentions[0].transformer_blocks[
          0
      ].attn2.processor.__class__.__name__ in (
          "IPAdapterAttnProcessor",
          "IPAdapterAttnProcessor2_0",
      )
      with torch.no_grad():
          sample2 = model(**inputs_dict).sample
  
      # forward pass with ip_adapter_2
      model._load_ip_adapter_weights(ip_adapter_2)
      with torch.no_grad():
          sample3 = model(**inputs_dict).sample
  
      # forward pass with ip_adapter_1 again
      model._load_ip_adapter_weights(ip_adapter_1)
      with torch.no_grad():
          sample4 = model(**inputs_dict).sample
  
      assert not sample1.allclose(sample2, atol=1e-4, rtol=1e-4)
      assert not sample2.allclose(sample3, atol=1e-4, rtol=1e-4)
      assert sample2.allclose(sample4, atol=1e-4, rtol=1e-4)
  
imports: import copy
  import gc
  import os
  import tempfile
  import unittest
  from collections import OrderedDict
  import torch
  from parameterized import parameterized
  from pytest import mark
  from diffusers import UNet2DConditionModel
  from diffusers.models.attention_processor import CustomDiffusionAttnProcessor, IPAdapterAttnProcessor
  from diffusers.models.embeddings import ImageProjection, IPAdapterPlusImageProjection
  from diffusers.utils import logging
  from diffusers.utils.import_utils import is_xformers_available
  from diffusers.utils.testing_utils import backend_empty_cache, enable_full_determinism, floats_tensor, load_hf_numpy, require_torch_accelerator, require_torch_accelerator_with_fp16, require_torch_accelerator_with_training, require_torch_gpu, skip_mps, slow, torch_all_close, torch_device
  from .test_modeling_common import ModelTesterMixin, UNetTesterMixin
label_desc: Use image node_id 23 for calling the UNet2DConditionModelTests obj's underlying member method code with example usage: obj.test_ip_adapter() without return types