class_docstr: Pipeline for text-guided image inpainting using Kandinsky2.1
  
  This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods the
  library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)
  
  Args:
      text_encoder ([`MultilingualCLIP`]):
          Frozen text-encoder.
      tokenizer ([`XLMRobertaTokenizer`]):
          Tokenizer of class
      scheduler ([`DDIMScheduler`]):
          A scheduler to be used in combination with `unet` to generate image latents.
      unet ([`UNet2DConditionModel`]):
          Conditional U-Net architecture to denoise the image embedding.
      movq ([`VQModel`]):
          MoVQ image encoder and decoder
code: def _encode_prompt(
      self,
      prompt,
      device,
      num_images_per_prompt,
      do_classifier_free_guidance,
      negative_prompt=None,
  ):
      batch_size = len(prompt) if isinstance(prompt, list) else 1
      # get prompt text embeddings
      text_inputs = self.tokenizer(
          prompt,
          padding="max_length",
          max_length=77,
          truncation=True,
          return_attention_mask=True,
          add_special_tokens=True,
          return_tensors="pt",
      )
  
      text_input_ids = text_inputs.input_ids
      untruncated_ids = self.tokenizer(
          prompt, padding="longest", return_tensors="pt"
      ).input_ids
  
      if untruncated_ids.shape[-1] >= text_input_ids.shape[
          -1
      ] and not torch.equal(text_input_ids, untruncated_ids):
          removed_text = self.tokenizer.batch_decode(
              untruncated_ids[
                  :, self.tokenizer.model_max_length - 1 : -1
              ]
          )
          logger.warning(
              "The following part of your input was truncated because CLIP can only handle sequences up to"
              f" {self.tokenizer.model_max_length} tokens: {removed_text}"
          )
  
      text_input_ids = text_input_ids.to(device)
      text_mask = text_inputs.attention_mask.to(device)
  
      prompt_embeds, text_encoder_hidden_states = self.text_encoder(
          input_ids=text_input_ids, attention_mask=text_mask
      )
  
      prompt_embeds = prompt_embeds.repeat_interleave(
          num_images_per_prompt, dim=0
      )
      text_encoder_hidden_states = (
          text_encoder_hidden_states.repeat_interleave(
              num_images_per_prompt, dim=0
          )
      )
      text_mask = text_mask.repeat_interleave(
          num_images_per_prompt, dim=0
      )
  
      if do_classifier_free_guidance:
          uncond_tokens: List[str]
          if negative_prompt is None:
              uncond_tokens = [""] * batch_size
          elif type(prompt) is not type(negative_prompt):
              raise TypeError(
                  f"`negative_prompt` should be the same type to `prompt`, but got {type(negative_prompt)} !="
                  f" {type(prompt)}."
              )
          elif isinstance(negative_prompt, str):
              uncond_tokens = [negative_prompt]
          elif batch_size != len(negative_prompt):
              raise ValueError(
                  f"`negative_prompt`: {negative_prompt} has batch size {len(negative_prompt)}, but `prompt`:"
                  f" {prompt} has batch size {batch_size}. Please make sure that passed `negative_prompt` matches"
                  " the batch size of `prompt`."
              )
          else:
              uncond_tokens = negative_prompt
  
          uncond_input = self.tokenizer(
              uncond_tokens,
              padding="max_length",
              max_length=77,
              truncation=True,
              return_attention_mask=True,
              add_special_tokens=True,
              return_tensors="pt",
          )
          uncond_text_input_ids = uncond_input.input_ids.to(device)
          uncond_text_mask = uncond_input.attention_mask.to(device)
  
          (
              negative_prompt_embeds,
              uncond_text_encoder_hidden_states,
          ) = self.text_encoder(
              input_ids=uncond_text_input_ids,
              attention_mask=uncond_text_mask,
          )
  
          # duplicate unconditional embeddings for each generation per prompt, using mps friendly method
  
          seq_len = negative_prompt_embeds.shape[1]
          negative_prompt_embeds = negative_prompt_embeds.repeat(
              1, num_images_per_prompt
          )
          negative_prompt_embeds = negative_prompt_embeds.view(
              batch_size * num_images_per_prompt, seq_len
          )
  
          seq_len = uncond_text_encoder_hidden_states.shape[1]
          uncond_text_encoder_hidden_states = (
              uncond_text_encoder_hidden_states.repeat(
                  1, num_images_per_prompt, 1
              )
          )
          uncond_text_encoder_hidden_states = (
              uncond_text_encoder_hidden_states.view(
                  batch_size * num_images_per_prompt, seq_len, -1
              )
          )
          uncond_text_mask = uncond_text_mask.repeat_interleave(
              num_images_per_prompt, dim=0
          )
  
          # done duplicates
  
          # For classifier free guidance, we need to do two forward passes.
          # Here we concatenate the unconditional and text embeddings into a single batch
          # to avoid doing two forward passes
          prompt_embeds = torch.cat(
              [negative_prompt_embeds, prompt_embeds]
          )
          text_encoder_hidden_states = torch.cat(
              [
                  uncond_text_encoder_hidden_states,
                  text_encoder_hidden_states,
              ]
          )
  
          text_mask = torch.cat([uncond_text_mask, text_mask])
  
      return prompt_embeds, text_encoder_hidden_states, text_mask
  
imports: from copy import deepcopy
  from typing import Callable, List, Optional, Union
  import numpy
  import PIL.Image
  import torch
  import torch.nn.functional
  from packaging import version
  from PIL import Image
  from transformers import XLMRobertaTokenizer
  from ...None import __version__
  from ...models import UNet2DConditionModel, VQModel
  from ...schedulers import DDIMScheduler
  from ...utils import logging, replace_example_docstring
  from ...utils.torch_utils import randn_tensor
  from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
  from .text_encoder import MultilingualCLIP
label_desc: Use image node_id 3 for calling the KandinskyInpaintPipeline obj's underlying member method code with example usage: obj._encode_prompt(prompt, device, num_images_per_prompt, do_classifier_free_guidance, negative_prompt) and returns: prompt_embeds,  text_encoder_hidden_states,  text_mask