code: def greedy_generate(
      decoder,
      tokens=None,
      state=None,
      max_length=20,
      max_len_a=0.0,
      num_beams=1,
      bos_token_id=None,
      eos_token_id=None,
      pad_token_id=0,
      repetition_penalty=1,
      length_penalty=1.0,
      restricter=None,
  ):
      if num_beams == 1:
          token_ids = _no_beam_search_generate(
              decoder,
              tokens=tokens,
              state=state,
              max_length=max_length,
              max_len_a=max_len_a,
              bos_token_id=bos_token_id,
              eos_token_id=eos_token_id,
              repetition_penalty=repetition_penalty,
              length_penalty=length_penalty,
              pad_token_id=pad_token_id,
              restricter=restricter,
          )
      else:
          token_ids = _beam_search_generate(
              decoder,
              tokens=tokens,
              state=state,
              max_length=max_length,
              max_len_a=max_len_a,
              num_beams=num_beams,
              bos_token_id=bos_token_id,
              eos_token_id=eos_token_id,
              do_sample=False,
              repetition_penalty=repetition_penalty,
              length_penalty=length_penalty,
              pad_token_id=pad_token_id,
              restricter=restricter,
          )
  
      return token_ids
  
imports: import torch
  from torch import nn
  from torch.nn import functional
  from transformers.models.bart.configuration_bart import BartConfig
  from .modeling_bart import BartModel
  from ..utils.util import avg_token_embeddings, seq_to_mask, get_model_device
  from functools import partial
  from typing import Union
label_desc: Use image node_id 1 for calling a global function with example usage: greedy_generate(decoder, tokens, state, max_length, max_len_a, num_beams, bos_token_id, eos_token_id, pad_token_id, repetition_penalty, length_penalty, restricter) and returns: token_ids