code: def generate(
      model,
      inputs=None,
      tokens_to_generate=0,
      all_probs=False,
      temperature=1.0,
      add_BOS=False,
      top_k=0,
      top_p=0.0,
      greedy=False,
      compute_attention_mask=True,
      compute_logprob=False,
      repetition_penalty=1.0,
      end_strings=["<|endoftext|>"],
      image_list=None,
      min_tokens_to_generate=0,
      **strategy_args,
  ) -> OutputType:
      """
      Args:
          model (NLPModel): text generative model
          inputs (Union[tuple, List[str]]): if it is a tuple, it is assumed to be (context_tokens_tensor, context_length_tensor). Otherwise it it a list of prompt text strings
          tokens_to_generate (int): The maximum length of the tokens to be generated.
          all_probs (bool): Return the log prob for all the tokens
          temperature (float): sampling temperature
          add_BOS (bool): add the bos token at the begining of the prompt
          top_k (int): The number of highest probability vocabulary tokens to keep for top-k-filtering.
          top_p (float): If set to float < 1, only the most probable tokens with probabilities that add up to top_p or higher are kept for generation.
          greedy (bool):  Whether or not to use sampling ; use greedy decoding otherwise
          repetition_penalty (float): The parameter for repetition penalty. 1.0 means no penalty
          min_tokens_to_generate (int): The minimum length of the tokens to be generated
          strategy_args, the extra arguments are treated as inference strategy arguments
          end_strings, a list of strings to stop generation when they are encountered in the output.
      Returns:
          OutputType: It generates the output in a dictionary type. It has the following keys:
              sentences: List[str], output sentences
              tokens: List[List[str]], output sentences borken into tokens
              logprob: List[Tensor], log prob of generated tokens
              full_logprob: List[Tensor], log prob of all the tokens in the vocab
              token_ids: List[Tensor], output sentence token ids
              offsets: List[List[int]]  # list of tokens start positions in text
      """
      if "strategy" in strategy_args:
          inference_strategy = strategy_args["strategy"]
      else:
          inference_strategy = model_inference_strategy_dispatcher(
              model, **strategy_args
          )
      tokenizer = model.tokenizer
      if torch.distributed.get_rank() == get_model_parallel_src_rank():
          if isinstance(inputs, tuple):
              context_tokens_tensor, context_length_tensor = inputs
          else:
              (
                  context_tokens_tensor,
                  context_length_tensor,
              ) = inference_strategy.tokenize_batch(
                  inputs, tokens_to_generate, add_BOS
              )
  
          send_generate_info(
              context_tokens_tensor,
              context_length_tensor,
              tokens_to_generate,
              all_probs,
              compute_logprob,
              temperature,
              top_k,
              top_p,
              greedy,
              repetition_penalty,
              min_tokens_to_generate,
              end_strings,
          )
      else:
          (
              context_length_tensor,
              context_tokens_tensor,
              tokens_to_generate,
              all_probs,
              compute_logprob,
              temperature,
              top_k,
              top_p,
              greedy,
              repetition_penalty,
              min_tokens_to_generate,
              end_strings,
          ) = receive_generate_info()
  
      output = synced_generate(
          model,
          inference_strategy,
          context_tokens_tensor,
          context_length_tensor,
          tokens_to_generate,
          all_probs,
          temperature,
          compute_attention_mask=compute_attention_mask,
          compute_logprob=compute_logprob,
          top_k=top_k,
          top_p=top_p,
          greedy=greedy,
          repetition_penalty=repetition_penalty,
          end_strings=end_strings,
          min_tokens_to_generate=min_tokens_to_generate,
          image_list=image_list,
      )
      special_tokens = set()
      if (
          hasattr(tokenizer, "pad_token")
          and tokenizer.pad_token is not None
      ):
          special_tokens.add(tokenizer.pad_token)
      if (
          hasattr(tokenizer, "eos_token")
          and tokenizer.eos_token is not None
      ):
          special_tokens.add(tokenizer.eos_token)
      if (
          hasattr(tokenizer, "bos_token")
          and tokenizer.bos_token is not None
      ):
          special_tokens.add(tokenizer.bos_token)
      if (
          hasattr(tokenizer, "cls_token")
          and tokenizer.cls_token is not None
      ):
          special_tokens.add(tokenizer.cls_token)
      if (
          hasattr(tokenizer, "unk_token")
          and tokenizer.unk_token is not None
      ):
          special_tokens.add(tokenizer.unk_token)
      if (
          hasattr(tokenizer, "sep_token")
          and tokenizer.sep_token is not None
      ):
          special_tokens.add(tokenizer.sep_token)
      if (
          hasattr(tokenizer, "mask_token")
          and tokenizer.mask_token is not None
      ):
          special_tokens.add(tokenizer.mask_token)
      if output is not None:
          decode_tokens, output_logits, full_logits = output
          resp_sentences = []
          resp_sentences_seg = []
  
          decode_tokens = decode_tokens.cpu().numpy().tolist()
          for decode_token in decode_tokens:
              sentence = tokenizer.ids_to_text(decode_token)
              resp_sentences.append(sentence)
              if not isinstance(tokenizer, TabularTokenizer):
                  words = []
                  for token in decode_token:
                      if not isinstance(token, Iterable):
                          token = [token]
                      word = tokenizer.ids_to_tokens(token)
                      if isinstance(word, Iterable):
                          word = word[0]
                      if hasattr(tokenizer.tokenizer, "byte_decoder"):
                          word = bytearray(
                              [
                                  tokenizer.tokenizer.byte_decoder[c]
                                  for c in word
                              ]
                          ).decode("utf-8", errors="replace")
                      words.append(word)
                  resp_sentences_seg.append(words)
              else:
                  words = tokenizer.text_to_tokens(sentence)
                  resp_sentences_seg.append(words)
  
          # offsets calculation
          all_offsets = []
          for item in resp_sentences_seg:
              offsets = [0]
              for index, token in enumerate(item):
                  if index != len(item) - 1:
                      if token in special_tokens:
                          offsets.append(offsets[-1])
                      else:
                          offsets.append(len(token) + offsets[-1])
              all_offsets.append(offsets)
  
          output = {}
          output["sentences"] = resp_sentences
          output["tokens"] = resp_sentences_seg
          output["logprob"] = output_logits
          output["full_logprob"] = full_logits
          output["token_ids"] = decode_tokens
          output["offsets"] = all_offsets
          output = inference_strategy.post_generation_process(output)
          return output
  
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 14 for calling a global function with example usage: generate(model, inputs, tokens_to_generate, all_probs, temperature, add_BOS, top_k, top_p, greedy, compute_attention_mask, compute_logprob, repetition_penalty, end_strings, image_list, min_tokens_to_generate) and returns: output