code: def retrieve_latents(
      encoder_output: torch.Tensor,
      generator: Optional[torch.Generator] = None,
      sample_mode: str = "sample",
  ):
      if (
          hasattr(encoder_output, "latent_dist")
          and sample_mode == "sample"
      ):
          return encoder_output.latent_dist.sample(generator)
      elif (
          hasattr(encoder_output, "latent_dist")
          and sample_mode == "argmax"
      ):
          return encoder_output.latent_dist.mode()
      elif hasattr(encoder_output, "latents"):
          return encoder_output.latents
      else:
          raise AttributeError(
              "Could not access latents of provided encoder_output"
          )
  
imports: import inspect
  from typing import Callable, Dict, List, Optional, Union
  import numpy
  import PIL.Image
  import torch
  from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer, CLIPVisionModelWithProjection
  from ...image_processor import PipelineImageInput, VaeImageProcessor
  from ...loaders import IPAdapterMixin, LoraLoaderMixin, TextualInversionLoaderMixin
  from ...models import AutoencoderKL, ImageProjection, UNet2DConditionModel
  from ...schedulers import KarrasDiffusionSchedulers
  from ...utils import PIL_INTERPOLATION, deprecate, logging
  from ...utils.torch_utils import randn_tensor
  from ..pipeline_utils import DiffusionPipeline
  from .None import StableDiffusionPipelineOutput
  from .safety_checker import StableDiffusionSafetyChecker
label_desc: Use image node_id 2 for calling a global function with example usage: retrieve_latents(encoder_output, generator, sample_mode) and returns: encoder_output, encoder_output, encoder_output