class_docstr: Encoder part of the encoder-decoder model for ONNX Runtime inference.
class_docstr_tok: ["Encoder","part","of","the","encoder-decoder","model","for","ONNX","Runtime","inference","."]
code: def forward(
      self,
      input_ids: torch.LongTensor,
      attention_mask: torch.LongTensor,
      **kwargs,
  ) -> BaseModelOutput:
      use_torch = isinstance(input_ids, torch.Tensor)
      self.parent_model.raise_on_numpy_input_io_binding(use_torch)
  
      if (
          self.device.type == "cuda"
          and self.parent_model.use_io_binding
      ):
          model_inputs = [input_ids]
          if "attention_mask" in self.input_names:
              model_inputs.append(attention_mask)
          (
              io_binding,
              output_shapes,
              output_buffers,
          ) = self.parent_model._prepare_io_binding(
              self.session,
              *model_inputs,
              ordered_input_names=self._ordered_input_names,
          )
  
          io_binding.synchronize_inputs()
          self.session.run_with_iobinding(io_binding)
          io_binding.synchronize_outputs()
  
          last_hidden_state = output_buffers["last_hidden_state"].view(
              output_shapes["last_hidden_state"]
          )
      else:
          if use_torch:
              onnx_inputs = {
                  "input_ids": input_ids.cpu().detach().numpy()
              }
  
              # Add the attention_mask inputs when needed
              if "attention_mask" in self.input_names:
                  onnx_inputs["attention_mask"] = (
                      attention_mask.cpu().detach().numpy()
                  )
          else:
              onnx_inputs = {"input_ids": input_ids}
  
              # Add the attention_mask inputs when needed
              if "attention_mask" in self.input_names:
                  onnx_inputs["attention_mask"] = attention_mask
  
          # Run inference
          outputs = self.session.run(None, onnx_inputs)
  
          last_hidden_state = outputs[
              self.output_names["last_hidden_state"]
          ]
          if use_torch:
              last_hidden_state = torch.from_numpy(
                  last_hidden_state
              ).to(self.device)
  
      return BaseModelOutput(last_hidden_state=last_hidden_state)
  
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 for calling the ORTEncoder obj's underlying member method code with example usage: obj.forward(input_ids, attention_mask) and returns: BaseModelOutput