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 _expand_inputs_for_generation(
      input_ids: "torch.LongTensor",
      expand_size: int = 1,
      is_encoder_decoder: bool = False,
      attention_mask: "torch.LongTensor" = None,
      encoder_outputs: ModelOutput = None,
      **model_kwargs,
  ) -> Tuple["torch.LongTensor", Dict[str, Any]]:
      expanded_return_idx = (
          torch.arange(input_ids.shape[0])
          .view(-1, 1)
          .repeat(1, expand_size)
          .view(-1)
          .to(input_ids.device)
      )
      input_ids = input_ids.index_select(0, expanded_return_idx)
  
      if "token_type_ids" in model_kwargs:
          token_type_ids = model_kwargs["token_type_ids"]
          model_kwargs["token_type_ids"] = token_type_ids.index_select(
              0, expanded_return_idx
          )
  
      if attention_mask is not None:
          model_kwargs["attention_mask"] = attention_mask.index_select(
              0, expanded_return_idx
          )
  
      if is_encoder_decoder:
          assert encoder_outputs is not None
          encoder_outputs[
              "last_hidden_state"
          ] = encoder_outputs.last_hidden_state.index_select(
              0,
              expanded_return_idx.to(
                  encoder_outputs.last_hidden_state.device
              ),
          )
          model_kwargs["encoder_outputs"] = encoder_outputs
      return input_ids, model_kwargs
  
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 9 for calling the GenerationMixin obj's underlying member method code with example usage: obj._expand_inputs_for_generation(input_ids, expand_size, is_encoder_decoder, attention_mask, encoder_outputs) and returns: input_ids,  model_kwargs