code: def __call__(
      self,
      prompts: Union[str, List[str]] = None,
      inference_steps: Union[int, List[int]] = None,
      classifier_free_guidance: Union[float, List[float]] = None,
      num_images_per_promt: Optional[int] = 0,
      thresholding_method: bool = None,
      output_type: Optional[str] = "pil",
      seed: Union[int, List[int]] = 2000,
      single_batch_mode: bool = False,
      output_res: Optional[int] = None,
      low_res_input: Optional[torch.Tensor] = None,
  ):
      if prompts is None:
          prompts = OmegaConf.to_object(self.cfg.texts)
      if num_images_per_promt == 0:
          num_images_per_promt = self.cfg.num_images_per_promt
      if thresholding_method is None:
          thresholding_method = self.cfg.thresholding_method
      device = self.device
      inference_precision = self.cfg.inference_precision
      assert inference_precision in [
          "16",
          "32",
          "AMP",
      ], "Inference Precision should be one of ['16', '32', 'AMP']"
      print(f"Running inference in {inference_precision} mode.")
      amp_enabled = inference_precision == "AMP"
  
      # Based on output_res and low_res_input, determine which models to run
      if output_res is not None or low_res_input is not None:
          models = []
          if output_res is not None:
              for model in self.models:
                  models.append(model)
                  if model.image_size == output_res:
                      break
          else:
              models = self.models
          if low_res_input is not None:
              print(f"Low-res input shape: {low_res_input.shape}")
              low_res_dim = low_res_input.shape[-1]
              num_images_per_promt = low_res_input.shape[0]
              for idx, model in enumerate(models):
                  if model.image_size == low_res_dim:
                      models = models[idx + 1 :]
                      break
          print(f"Running inference on {len(models)} models.")
      else:
          models = self.models
  
      if classifier_free_guidance is None:
          cfgs = [each.cfg for each in self.cfg.samplings]
          cfgs = cfgs[: len(models)]
      else:
          cfgs = classifier_free_guidance
          if isinstance(cfgs, int) or isinstance(cfgs, float):
              cfgs = [cfgs] * len(models)
  
      if inference_steps is None:
          steps = [each.step for each in self.cfg.samplings]
          steps = steps[: len(models)]
      else:
          steps = inference_steps
          if isinstance(steps, int):
              steps = [steps] * len(models)
  
      assert len(steps) == len(cfgs) == len(models)
  
      output = []
      all_res_output = [[] for _ in range(len(models))]
      if single_batch_mode:
          num_images_per_promt = len(prompts)
  
      throughputs = {"text-encoding": []}
      for idx in range(len(models)):
          throughputs[f"stage-{idx+1}"] = []
      for prompt in prompts:
          if single_batch_mode:
              text_input = prompts
          else:
              text_input = prompt.strip("\n")
          print("Input caption: {}".format(text_input))
          tic = time.perf_counter()
          text_encodings, text_mask = self.get_text_encodings(
              text_input,
              repeat=num_images_per_promt
              if not single_batch_mode
              else 1,
          )
          throughputs["text-encoding"].append(time.perf_counter() - tic)
  
          # Set seed
          noise_maps = []
          if isinstance(seed, int):
              # Single seed for the batch
              torch.random.manual_seed(seed)
              # Generate noise maps
              for model in models:
                  noise_map = torch.randn(
                      (
                          num_images_per_promt,
                          3,
                          model.unet.image_size,
                          model.unet.image_size,
                      ),
                      device=device,
                  )
                  noise_map = (
                      noise_map.half()
                      if inference_precision == "16"
                      else noise_map
                  )
                  noise_maps.append(noise_map)
          elif isinstance(seed, list):
              assert len(seed) == num_images_per_promt
              for model in models:
                  noise_map_batch = []
                  for single_seed in seed:
                      torch.random.manual_seed(single_seed)
                      noise_map_single = torch.randn(
                          (
                              1,
                              3,
                              model.unet.image_size,
                              model.unet.image_size,
                          ),
                          device=device,
                      )
                      noise_map_batch.append(noise_map_single)
                  noise_map_batch = torch.cat(noise_map_batch, dim=0)
                  noise_map_batch = (
                      noise_map_batch.half()
                      if inference_precision == "16"
                      else noise_map_batch
                  )
                  noise_maps.append(noise_map_batch)
          else:
              raise RuntimeError("Seed type incorrect.")
  
          x_low_res = low_res_input
          all_res = []
          for idx, (model, noise_map, cfg, step) in enumerate(
              zip(models, noise_maps, cfgs, steps)
          ):
              tic = time.perf_counter()
              with autocast(enabled=amp_enabled):
                  generated_images = model.sample_image(
                      noise_map=noise_map,
                      text_encoding=text_encodings,
                      text_mask=text_mask,
                      x_low_res=x_low_res,
                      cond_scale=cfg,
                      sampling_steps=step,
                      thresholding_method=thresholding_method,
                  )
              x_low_res = generated_images
              all_res.append(generated_images)
              throughputs[f"stage-{idx+1}"].append(
                  time.perf_counter() - tic
              )
          # recenter from [-1, 1] to [0, 1]
          assert generated_images is not None
          generated_images = ((generated_images + 1) / 2).clamp_(0, 1)
          all_res = [((each + 1) / 2).clamp_(0, 1) for each in all_res]
          output.append(generated_images)
          for idx, each in enumerate(all_res):
              all_res_output[idx].append(each)
          if single_batch_mode:
              break
  
      if output_type == "torch":
          return torch.cat(output, dim=0), [
              torch.cat(each, dim=0) for each in all_res_output
          ]
      output_new = []
      for x_samples_image in output:
          # Convert to numpy
          x_samples_image = (
              x_samples_image.cpu().permute(0, 2, 3, 1).numpy()
          )
          if output_type == "pil":
              x_samples_image = numpy_to_pil(x_samples_image)
          output_new.append(x_samples_image)
  
      all_res_output_new = [[] for each in range(len(models))]
      for idx, res_output in enumerate(all_res_output):
          for x_samples_image in res_output:
              # Convert to numpy
              x_samples_image = (
                  x_samples_image.cpu().permute(0, 2, 3, 1).numpy()
              )
              if output_type == "pil":
                  x_samples_image = numpy_to_pil(x_samples_image)
          all_res_output_new[idx].append(x_samples_image)
  
      for item in throughputs:
          throughputs[item] = sum(throughputs[item]) / len(
              throughputs[item]
          )
  
      return output_new, all_res_output_new, throughputs
  
imports: import os
  import time
  from dataclasses import dataclass, field
  from typing import Callable, List, Optional, Union
  import torch
  from omegaconf.omegaconf import OmegaConf
  from pytorch_lightning import Trainer
  from torch.cuda.amp import autocast
  from nemo.collections.multimodal.models.text_to_image.imagen.imagen import Imagen, MegatronImagen
  from nemo.collections.multimodal.parts.utils import numpy_to_pil, setup_trainer_and_models_for_inference
label_desc: Use image node_id 6 for calling the ImagenPipeline obj's underlying member method code with example usage: obj.__call__(prompts, inference_steps, classifier_free_guidance, num_images_per_promt, thresholding_method, output_type, seed, single_batch_mode, output_res, low_res_input) and returns: output_new,  all_res_output_new,  throughputs, torch,  unknown