class_docstr: A class containing all of the functions supporting generation, to be used as a mixin in
  :class:`~transformers.PreTrainedModel`.
class_docstr_tok: ["A","class","containing","all","of","the","functions","supporting","generation",",","to","be","used","as","a","mixin","in",":","class",":","`","~transformers.PreTrainedModel","`","."]
code: def _prepare_attention_mask_for_generation(
      self,
      input_ids: "torch.Tensor",
      pad_token_id: int,
      eos_token_id: int,
  ) -> "torch.LongTensor":
      is_pad_token_in_inputs_ids = (pad_token_id is not None) and (
          pad_token_id in input_ids
      )
      is_pad_token_not_equal_to_eos_token_id = (
          eos_token_id is None
      ) or (
          (eos_token_id is not None) and (pad_token_id != eos_token_id)
      )
      if (
          is_pad_token_in_inputs_ids
          and is_pad_token_not_equal_to_eos_token_id
      ):
          return input_ids.ne(pad_token_id).long()
      return input_ids.new_ones(input_ids.shape, dtype=torch.long)
  
imports: from dataclasses import dataclass
  from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
  from .file_utils import ModelOutput
  from .generation_beam_search import BeamScorer, BeamSearchScorer
  from .generation_logits_process import EncoderNoRepeatNGramLogitsProcessor, ForcedBOSTokenLogitsProcessor, ForcedEOSTokenLogitsProcessor, HammingDiversityLogitsProcessor, InfNanRemoveLogitsProcessor, LogitsProcessorList, MinLengthLogitsProcessor, NoBadWordsLogitsProcessor, NoRepeatNGramLogitsProcessor, PrefixConstrainedLogitsProcessor, RepetitionPenaltyLogitsProcessor, TemperatureLogitsWarper, TopKLogitsWarper, TopPLogitsWarper
  from .generation_stopping_criteria import MaxLengthCriteria, MaxNewTokensCriteria, MaxTimeCriteria, StoppingCriteriaList, validate_stopping_criteria
  from fastNLP.envs.imports import _NEED_IMPORT_TORCH
  from fastNLP.core.log import logger
label_desc: Use image node_id 4 for calling the GenerationMixin obj's underlying member method code with example usage: obj._prepare_attention_mask_for_generation(input_ids, pad_token_id, eos_token_id) and returns: input_ids, input_ids