class_docstr: Decoder model with a language modeling head on top for ONNX Runtime inference.
class_docstr_tok: ["Decoder","model","with","a","language","modeling","head","on","top","for","ONNX","Runtime","inference","."]
code: def __init__(
      self,
      session: InferenceSession,
      parent_model: "ORTModel",
  ):
      super().__init__(session, parent_model)
  
      # TODO: make this less hacky.
      self.key_value_input_names = [
          key
          for key in self.input_names
          if (".key" in key) or (".value" in key)
      ]
      self.key_value_output_names = [
          key
          for key in self.output_names
          if (".key" in key) or (".value" in key)
      ]
  
      # To handle the old case when past_key_values were following the format: past_key_values_{idx}
      if len(self.key_value_input_names) == 0:
          self.key_value_input_names = [
              key for key in self.input_names if "key_values" in key
          ]
      if len(self.key_value_output_names) == 0:
          self.key_value_output_names = [
              key for key in self.output_names if "key_values" in key
          ]
  
      if (
          self.parent_model.use_cache is True
          and len(self.key_value_output_names) == 0
      ):
          raise RuntimeError(
              "Could not find the past key values in the provided model."
          )
  
      self.use_past_in_outputs = len(self.key_value_output_names) > 0
      self.use_past_in_inputs = len(self.key_value_input_names) > 0
      self.use_fp16 = False
      for inp in session.get_inputs():
          if (
              "past_key_values" in inp.name
              and inp.type == "tensor(float16)"
          ):
              self.use_fp16 = True
              break
  
      # We may use ORTDecoderForSeq2Seq for vision-encoder-decoder models, where models as gpt2
      # can be used but do not support KV caching for the cross-attention key/values, see:
      # https://github.com/huggingface/transformers/blob/v4.31.0/src/transformers/models/gpt2/modeling_gpt2.py#L302-L311
      # This attribute is used to avoid returning cross-attention KV-cache in this case.
      self.no_cross_attention_cache = getattr(
          self.parent_model, "no_cross_attention_cache", False
      )
  
      if (
          not self.parent_model.use_merged and self.use_past_in_inputs
      ) or self.no_cross_attention_cache:
          self.num_pkv = 2
      else:
          # When using a merged model, we always have the same number of output whether we use past key values or not,
          # and in the case past key values are used, empty tensors are given as cross-attention past key values as they
          # are constants
          self.num_pkv = 4
  
      self.past_key_values_cross_attention_output_names = set()
      for output_name in self.output_names:
          if (
              output_name.startswith("present")
              and "encoder" in output_name
          ):
              self.past_key_values_cross_attention_output_names.add(
                  output_name
              )
  
      self.use_legacy_outputs = (
          self.parent_model.use_merged is False
          and len(self.past_key_values_cross_attention_output_names) > 0
      )
  
imports: from abc import abstractmethod
  from typing import TYPE_CHECKING, Dict, Optional, Set, Tuple, Union
  import numpy
  import torch
  from transformers.modeling_outputs import BaseModelOutput, Seq2SeqLMOutput
  from onnxruntime import InferenceSession
  from ..utils import NormalizedConfigManager
  from ..utils.logging import warn_once
  from .utils import get_ordered_input_names, logging
label_desc: Use image node_id 1 to create a new ORTDecoderForSeq2Seq object from inherited base classes: ORTModelPart with example: obj = ORTDecoderForSeq2Seq(session, parent_model)