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 _update_model_kwargs_for_generation(
      outputs: ModelOutput,
      model_kwargs: Dict[str, Any],
      is_encoder_decoder: bool = False,
  ) -> Dict[str, Any]:
      # update past
      if "past_key_values" in outputs:
          model_kwargs["past"] = outputs.past_key_values
      elif "mems" in outputs:
          model_kwargs["past"] = outputs.mems
      elif "past_buckets_states" in outputs:
          model_kwargs["past"] = outputs.past_buckets_states
      else:
          model_kwargs["past"] = None
  
      # update token_type_ids with last value
      if "token_type_ids" in model_kwargs:
          token_type_ids = model_kwargs["token_type_ids"]
          model_kwargs["token_type_ids"] = torch.cat(
              [token_type_ids, token_type_ids[:, -1].unsqueeze(-1)],
              dim=-1,
          )
  
      # update attention mask
      if not is_encoder_decoder:
          if "attention_mask" in model_kwargs:
              attention_mask = model_kwargs["attention_mask"]
              model_kwargs["attention_mask"] = torch.cat(
                  [
                      attention_mask,
                      attention_mask.new_ones(
                          (attention_mask.shape[0], 1)
                      ),
                  ],
                  dim=-1,
              )
  
      return 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 10 for calling the GenerationMixin obj's underlying member method code with example usage: obj._update_model_kwargs_for_generation(outputs, model_kwargs, is_encoder_decoder) and returns: model_kwargs