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 Any, Callable, Dict, List, Optional, Union
  import numpy
  import PIL.Image
  import torch
  from packaging import version
  from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer
  from ....configuration_utils import FrozenDict
  from ....image_processor import PipelineImageInput, VaeImageProcessor
  from ....loaders import LoraLoaderMixin, TextualInversionLoaderMixin
  from ....models import AutoencoderKL, UNet2DConditionModel
  from ....models.lora import adjust_lora_scale_text_encoder
  from ....schedulers import DDIMScheduler
  from ....utils import PIL_INTERPOLATION, USE_PEFT_BACKEND, deprecate, logging, scale_lora_layers, unscale_lora_layers
  from ....utils.torch_utils import randn_tensor
  from ...pipeline_utils import DiffusionPipeline
  from ...stable_diffusion.pipeline_output import StableDiffusionPipelineOutput
  from ...stable_diffusion.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