code: def images_tensor_to_samples(image, approximation=None, model=None):
      """image[0, 1] -> latent"""
      if approximation is None:
          approximation = approximation_indexes.get(
              opts.sd_vae_encode_method, 0
          )
  
      if approximation == 3:
          image = image.to(devices.device, devices.dtype)
          x_latent = sd_vae_taesd.encoder_model()(image)
      else:
          if model is None:
              model = shared.sd_model
          model.first_stage_model.to(devices.dtype_vae)
  
          image = image.to(shared.device, dtype=devices.dtype_vae)
          image = image * 2 - 1
          if len(image) > 1:
              x_latent = torch.stack(
                  [
                      model.get_first_stage_encoding(
                          model.encode_first_stage(
                              torch.unsqueeze(img, 0)
                          )
                      )[0]
                      for img in image
                  ]
              )
          else:
              x_latent = model.get_first_stage_encoding(
                  model.encode_first_stage(image)
              )
  
      return x_latent
  
imports: import inspect
  from collections import namedtuple
  import numpy
  import torch
  from PIL import Image
  from modules import devices, images, sd_vae_approx, sd_samplers, sd_vae_taesd, shared, sd_models
  from modules.shared import opts, state
  import k_diffusion.sampling
label_desc: Use image node_id 7 for calling a global function with example usage: images_tensor_to_samples(image, approximation, model) and returns: x_latent