class_docstr: Pipeline for generating image prior for Kandinsky
  
  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:
      prior ([`PriorTransformer`]):
          The canonincal unCLIP prior to approximate the image embedding from the text embedding.
      image_encoder ([`CLIPVisionModelWithProjection`]):
          Frozen image-encoder.
      text_encoder ([`CLIPTextModelWithProjection`]):
          Frozen text-encoder.
      tokenizer (`CLIPTokenizer`):
          Tokenizer of class
          [CLIPTokenizer](https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer).
      scheduler ([`UnCLIPScheduler`]):
          A scheduler to be used in combination with `prior` to generate image embedding.
class_docstr_tok: ["Pipeline","for","generating","image","prior","for","Kandinsky","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",":","prior","(","[","`","PriorTransformer","`","]",")",":","The","canonincal","unCLIP","prior","to","approximate","the","image","embedding","from","the","text","embedding",".","image_encoder","(","[","`","CLIPVisionModelWithProjection","`","]",")",":","Frozen","image-encoder",".","text_encoder","(","[","`","CLIPTextModelWithProjection","`","]",")",":","Frozen","text-encoder",".","tokenizer","(","`","CLIPTokenizer","`",")",":","Tokenizer","of","class","[","CLIPTokenizer","]","(","https",":","\/\/huggingface.co\/docs\/transformers\/v4.21.0\/en\/model_doc\/clip","#","transformers.CLIPTokenizer",")",".","scheduler","(","[","`","UnCLIPScheduler","`","]",")",":","A","scheduler","to","be","used","in","combination","with","`","prior","`","to","generate","image","embedding","."]
code: def prepare_latents(
      self, shape, dtype, device, generator, latents, scheduler
  ):
      if latents is None:
          latents = randn_tensor(
              shape, generator=generator, device=device, dtype=dtype
          )
      else:
          if latents.shape != shape:
              raise ValueError(
                  f"Unexpected latents shape, got {latents.shape}, expected {shape}"
              )
          latents = latents.to(device)
  
      latents = latents * scheduler.init_noise_sigma
      return latents
  
imports: from dataclasses import dataclass
  from typing import List, Optional, Union
  import numpy
  import PIL.Image
  import torch
  from transformers import CLIPImageProcessor, CLIPTextModelWithProjection, CLIPTokenizer, CLIPVisionModelWithProjection
  from ...models import PriorTransformer
  from ...schedulers import UnCLIPScheduler
  from ...utils import BaseOutput, logging, replace_example_docstring
  from ...utils.torch_utils import randn_tensor
  from ..pipeline_utils import DiffusionPipeline
label_desc: Use image node_id 3 for calling the KandinskyPriorPipeline obj's underlying member method code with example usage: obj.prepare_latents(shape, dtype, device, generator, latents, scheduler) and returns: latents