class_docstr: Greedy sequence generator based on the decoder followed by log_softmax.
  
  Args:
      embedding: nn.Module, transforms input_ids into vector embeddings
      decoder: nn.Module, takes embeddings and produces hidden_states
      log_softmax: nn.Module, takes hidden_states and produces log_probs
          which correspond to probability distribution of tokens (ids)
      pad: index of padding token in the vocabulary
      bos: index of beginning of sequence token in the vocabulary
      eos: index of end of sequence token in the vocabulary
      max_sequence_length: maximum allowed length for generated sequences
      max_delta_length: in case of encoder-decoder generation (e.g. NMT),
          forbids generated sequences to be longer than the length of
          source sequences plus max_delta_length
      batch_size: size of the batch of generated sequences if neither
          source nor target starting sequences are provided
class_docstr_tok: ["Greedy","sequence","generator","based","on","the","decoder","followed","by","log_softmax",".","Args",":","embedding",":","nn.Module",",","transforms","input_ids","into","vector","embeddings","decoder",":","nn.Module",",","takes","embeddings","and","produces","hidden_states","log_softmax",":","nn.Module",",","takes","hidden_states","and","produces","log_probs","which","correspond","to","probability","distribution","of","tokens","(","ids",")","pad",":","index","of","padding","token","in","the","vocabulary","bos",":","index","of","beginning","of","sequence","token","in","the","vocabulary","eos",":","index","of","end","of","sequence","token","in","the","vocabulary","max_sequence_length",":","maximum","allowed","length","for","generated","sequences","max_delta_length",":","in","case","of","encoder-decoder","generation","(","e.g",".","NMT",")",",","forbids","generated","sequences","to","be","longer","than","the","length","of","source","sequences","plus","max_delta_length","batch_size",":","size","of","the","batch","of","generated","sequences","if","neither","source","nor","target","starting","sequences","are","provided"]
docstr: Helper function which defines starting sequence to begin generating
  with and maximum allowed number of tokens to be generated.
docstr_tok: ["Helper","function","which","defines","starting","sequence","to","begin","generating","with","and","maximum","allowed","number","of","tokens","to","be","generated","."]
code: def _prepare_for_search(
      self, decoder_input_ids=None, encoder_hidden_states=None
  ):
      """
      Helper function which defines starting sequence to begin generating
      with and maximum allowed number of tokens to be generated.
      """
  
      decoder_parameter = next(self.decoder.parameters())
      batch_size = self.batch_size
  
      # for encoder-decoder generation, maximum length of generated sequence
      # is min(max_sequence_length, src_len + max_delta_length)
      if encoder_hidden_states is not None:
          batch_size, src_len, _ = encoder_hidden_states.size()
          if self.max_delta_len >= 0:
              max_seq_length = min(
                  self.max_seq_length, src_len + self.max_delta_len
              )
          else:
              max_seq_length = self.max_seq_length
      else:
          max_seq_length = self.max_seq_length
  
      # if no input is provided, start with the batch of <bos> tokens
      if decoder_input_ids is not None:
          tgt = decoder_input_ids
          batch_size, tgt_len = decoder_input_ids.size()
      else:
          tgt = (
              torch.zeros(batch_size, 1)
              .long()
              .fill_(self.bos)
              .to(decoder_parameter.device)
          )
          tgt_len = 1
      max_generation_length = max_seq_length - tgt_len
  
      return tgt, batch_size, max_generation_length
  
imports: from contextlib import contextmanager
  import torch
  from nemo.collections.common.parts import NEG_INF, mask_padded_tokens
label_desc: Use image node_id 3 for calling the GreedySequenceGenerator obj's underlying member method code with example usage: obj._prepare_for_search(decoder_input_ids, encoder_hidden_states) and returns: tgt,  batch_size,  max_generation_length