class_docstr: Hugging Face Transformers Decoder.
  
  Args:
      encoder_output_size: dimension of encoder attention
      model_name_or_path: Hugging Face Transformers model name
class_docstr_tok: ["Hugging","Face","Transformers","Decoder",".","Args",":","encoder_output_size",":","dimension","of","encoder","attention","model_name_or_path",":","Hugging","Face","Transformers","model","name"]
code: def __init__(
      self,
      vocab_size: int,
      encoder_output_size: int,
      model_name_or_path: str,
      causal_lm: bool = False,
      prefix: str = "",
      postfix: str = "",
  ):
      assert check_argument_types()
      super().__init__()
  
      if not is_transformers_available:
          raise ImportError(
              "`transformers` is not available. Please install it via `pip install"
              " transformers` or `cd /path/to/espnet/tools && . ./activate_python.sh"
              " && ./installers/install_transformers.sh`."
          )
  
      self.causal_lm = causal_lm
  
      if self.causal_lm:
          model = AutoModelForCausalLM.from_pretrained(
              model_name_or_path
          )
          self.decoder = get_hugging_face_model_network(model)
  
          if hasattr(self.decoder, "word_embeddings"):
              self.decoder_word_embeddings = (
                  self.decoder.word_embeddings
              )
          elif hasattr(self.decoder, "embed_in"):
              self.decoder_word_embeddings = self.decoder.embed_in
          elif hasattr(self.decoder, "embed_tokens"):
              self.decoder_word_embeddings = self.decoder.embed_tokens
          else:
              raise Exception(
                  "Can not find the word embeddings attribute"
              )
  
          if (
              self.decoder.config.pad_token_id is not None
              and self.decoder.config.pad_token_id != -1
          ):
              self.decoder_pad_token_id = (
                  self.decoder.config.pad_token_id
              )
          else:
              self.decoder_pad_token_id = 1
  
          tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
          self.tokenizer_padding_side = tokenizer.padding_side
  
          self.prefix = self.decoder_word_embeddings(
              tokenizer.encode(prefix, return_tensors="pt").long()
          ).detach()
  
          self.postfix = self.decoder_word_embeddings(
              tokenizer.encode(postfix, return_tensors="pt").long()
          ).detach()
      else:
          model = AutoModelForSeq2SeqLM.from_pretrained(
              model_name_or_path
          )
  
          if hasattr(model, "model"):
              self.decoder = model.model.decoder
          else:
              self.decoder = model.decoder
  
      model.resize_token_embeddings(vocab_size)
  
      self.lm_head = get_hugging_face_model_lm_head(model)
  
      self.model_name_or_path = model_name_or_path
  
      self.decoder_pretrained_params = copy.deepcopy(
          self.decoder.state_dict()
      )
      self.lm_head_pretrained_params = copy.deepcopy(
          self.lm_head.state_dict()
      )
  
      if encoder_output_size != self.decoder.config.hidden_size:
          self.linear_in = torch.nn.Linear(
              encoder_output_size, self.decoder.config.hidden_size
          )
      else:
          self.linear_in = torch.nn.Identity()
  
file_path: espnet/espnet2/asr/decoder/hugging_face_transformers_decoder.py
imports: import copy
  import logging
  from typing import Any, List, Tuple
  import torch
  import torch.nn.functional
  from typeguard import check_argument_types
  from espnet2.asr.decoder.abs_decoder import AbsDecoder
  from espnet.nets.pytorch_backend.nets_utils import make_pad_mask
  from espnet.nets.scorer_interface import BatchScorerInterface
label_desc: Use image node_id 1 to create a new HuggingFaceTransformersDecoder object from inherited base classes: AbsDecoder, BatchScorerInterface with example: obj = HuggingFaceTransformersDecoder(vocab_size, encoder_output_size, model_name_or_path, causal_lm, prefix, postfix)