code: def megatron_neva_generate(
      model,
      prompt_dict_list,
      length_params,
      sampling_params,
      inference_config,
      **strategy_args,
  ):
      conv_template = model.cfg.data.get("conv_template", "nvgpt")
      final_response = []
      for idx, prompt_dict in enumerate(prompt_dict_list):
          img = os.path.join(
              inference_config.inference.images_base_path,
              prompt_dict["image"],
          )
          response = generate(
              model,
              inputs=prompt_dict.get("prompt")
              or prompt_dict.get("text"),
              tokens_to_generate=length_params["max_length"],
              all_probs=sampling_params["all_probs"],
              compute_logprob=sampling_params["compute_logprob"],
              temperature=sampling_params["temperature"],
              add_BOS=sampling_params["add_BOS"],
              top_k=sampling_params["top_k"],
              top_p=sampling_params["top_p"],
              greedy=sampling_params["use_greedy"],
              repetition_penalty=sampling_params["repetition_penalty"],
              end_strings=sampling_params["end_strings"],
              min_tokens_to_generate=length_params["min_length"],
              compute_attention_mask=sampling_params.get(
                  "compute_attention_mask", True
              ),
              image_list=img,
              **strategy_args,
          )
  
          # Regular expression pattern to match the sequence
          pattern = re.compile(r"<extra_id_4>( ⁇ )+<extra_id_5>")
          clean_text = re.sub(
              pattern, "<image>", response["sentences"][0]
          )
  
          clean_response = clean_text
          for string in sampling_params["end_strings"]:
              clean_response = clean_response.rstrip(string)
          if conv_template == "nvgpt":
              labels_str_regexp = re.compile(
                  f"<extra_id_2>quality:.*\n"
              )
              last_match_end_position = None
              for match in re.finditer(
                  labels_str_regexp, clean_response
              ):
                  last_match_end_position = match.end()
              if last_match_end_position is not None:
                  clean_response = clean_response[
                      last_match_end_position:
                  ]
          elif conv_template == "llama_2":
              clean_response = clean_response.rsplit("[/INST] ", 1)[-1]
          clean_response.strip()
          response["clean_text"] = clean_text
          response["clean_response"] = clean_response
          final_response.append(response)
  
          if torch.cuda.current_device() == 0:
              print(
                  f"------------- PROMPT {idx} of {len(prompt_dict_list)} ------------ "
              )
              print(clean_text)
              print()
              print(f"CLEAN RESPONSE: {clean_response}")
              print("---------------------------------------------\n")
  
      return final_response
  
imports: import os
  import pickle
  import re
  from collections.abc import Iterable
  from functools import partial
  from typing import Callable, Tuple
  import numpy
  import torch
  import torch.nn.functional
  from nemo.collections.common.tokenizers.tabular_tokenizer import TabularTokenizer
  from nemo.collections.nlp.modules.common.megatron.utils import get_ltor_masks_and_position_ids
  from nemo.collections.nlp.modules.common.text_generation_strategy import model_inference_strategy_dispatcher
  from nemo.collections.nlp.modules.common.transformer.text_generation import LengthParam, OutputType, SamplingParam
  from nemo.utils import AppState
label_desc: Use image node_id 4 for calling a global function with example usage: megatron_neva_generate(model, prompt_dict_list, length_params, sampling_params, inference_config) and returns: final_response