code: def repetition_penalty(logits, repetition_penalty, used_tokens):
      """Implement the repetition penalty, check paper
      https://arxiv.org/pdf/1909.05858.pdf
      """
      if used_tokens is not None and repetition_penalty != 1.0:
          logits_update = torch.gather(logits, 1, used_tokens)
          logits = torch.scatter(
              logits, 1, used_tokens, logits_update / repetition_penalty
          )
      return logits
  
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 9 for calling a global function with example usage: repetition_penalty(logits, repetition_penalty, used_tokens) and returns: logits