def prepare_ip_adapter_image_embeds(
        self, ip_adapter_image, ip_adapter_image_embeds, device, num_images_per_prompt, do_classifier_free_guidance
    ):
        """Prepares and processes IP-Adapter image embeddings."""
        image_embeds = []
        if do_classifier_free_guidance:
            negative_image_embeds = []
        if ip_adapter_image_embeds is None:
            for image in ip_adapter_image:
                if not isinstance(image, torch.Tensor):
                    image = self.image_processor.preprocess(image)
                    image = image.to(device=device)
                if len(image.shape) == 3:
                    image = image.unsqueeze(0)
                image_emb, neg_image_emb = self.encode_image(image, device, num_images_per_prompt, True)
                image_embeds.append(image_emb)
                if do_classifier_free_guidance:
                    negative_image_embeds.append(neg_image_emb)

            if len(image_embeds) == 1:
                image_embeds = image_embeds[0]
                if do_classifier_free_guidance:
                    negative_image_embeds = negative_image_embeds[0]
            else:
                image_embeds = torch.cat(image_embeds, dim=0)
                if do_classifier_free_guidance:
                    negative_image_embeds = torch.cat(negative_image_embeds, dim=0)
        else:
            repeat_dim = 2 if do_classifier_free_guidance else 1
            image_embeds = ip_adapter_image_embeds.repeat_interleave(repeat_dim, dim=0)
            if do_classifier_free_guidance:
                negative_image_embeds = torch.zeros_like(image_embeds)

        if do_classifier_free_guidance:
            image_embeds = torch.cat([negative_image_embeds, image_embeds])

        return image_embeds
Prepares and processes IP-Adapter image embeddings.
examples/community/regional_prompting_stable_diffusion.py