

from __future__ import annotations

import unittest

from transformers import is_tf_available, is_torch_available
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, SMALL_MODEL_IDENTIFIER, is_pt_tf_cross_test, slow


if is_tf_available():
  from transformers import (
      AutoConfig,
      BertConfig,
      GPTaConfig,
      TaConfig,
      TFAutoModel,
      TFAutoModelForCausalLM,
      TFAutoModelForMaskedLM,
      TFAutoModelForPreTraining,
      TFAutoModelForQuestionAnswering,
      TFAutoModelForSeqaSeqLM,
      TFAutoModelForSequenceClassification,
      TFAutoModelWithLMHead,
      TFBertForMaskedLM,
      TFBertForPreTraining,
      TFBertForQuestionAnswering,
      TFBertForSequenceClassification,
      TFBertModel,
      TFGPTaLMHeadModel,
      TFRobertaForMaskedLM,
      TFTaForConditionalGeneration,
  )
  from transformers.models.bert.modeling_tf_bert import TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST
  from transformers.models.gpta.modeling_tf_gpta import TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST
  from transformers.models.ta.modeling_tf_ta import TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST

if is_torch_available():
  from transformers import (
      AutoModel,
      AutoModelForCausalLM,
      AutoModelForMaskedLM,
      AutoModelForPreTraining,
      AutoModelForQuestionAnswering,
      AutoModelForSeqaSeqLM,
      AutoModelForSequenceClassification,
      AutoModelWithLMHead,
      BertForMaskedLM,
      BertForPreTraining,
      BertForQuestionAnswering,
      BertForSequenceClassification,
      BertModel,
      GPTaLMHeadModel,
      RobertaForMaskedLM,
      TaForConditionalGeneration,
  )







@is_pt_tf_cross_test
class        a__       (   unittest.TestCase       ):







  """simple docstring"""




  @slow
  def  _lowercase      (			self    : Optional[int]		)					->Optional[int]:
        """simple docstring"""







        for model_name in ["bert-base-uncased"]:
              SCREAMING_SNAKE_CASE :      Union[str, Any]       =   AutoConfig.from_pretrained(UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      Dict       =   TFAutoModel.from_pretrained(UpperCAmelCase__				,				from_pt=UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      Union[str, Any]       =   AutoModel.from_pretrained(UpperCAmelCase__				,				from_tf=UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)


  @slow
  def  _lowercase      (			self    : Dict		)					->Optional[Any]:
        """simple docstring"""







        for model_name in ["bert-base-uncased"]:
              SCREAMING_SNAKE_CASE :      Tuple       =   AutoConfig.from_pretrained(UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      List[str]       =   TFAutoModelForPreTraining.from_pretrained(UpperCAmelCase__				,				from_pt=UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      Dict       =   AutoModelForPreTraining.from_pretrained(UpperCAmelCase__				,				from_tf=UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)


  @slow
  def  _lowercase      (			self    : Optional[int]		)					->Optional[int]:
        """simple docstring"""







        for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              SCREAMING_SNAKE_CASE :      Union[str, Any]       =   AutoConfig.from_pretrained(UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      Union[str, Any]       =   TFAutoModelForCausalLM.from_pretrained(UpperCAmelCase__				,				from_pt=UpperCAmelCase__		)
              SCREAMING_SNAKE_CASE     ,	SCREAMING_SNAKE_CASE :      int       =   TFAutoModelForCausalLM.from_pretrained(
                  UpperCAmelCase__				,				output_loading_info=UpperCAmelCase__				,				from_pt=UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      List[Any]       =   AutoModelForCausalLM.from_pretrained(UpperCAmelCase__				,				from_tf=UpperCAmelCase__		)
              SCREAMING_SNAKE_CASE     ,	SCREAMING_SNAKE_CASE :      int       =   AutoModelForCausalLM.from_pretrained(
                  UpperCAmelCase__				,				output_loading_info=UpperCAmelCase__				,				from_tf=UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)


  @slow
  def  _lowercase      (			self    : Optional[Any]		)					->List[str]:
        """simple docstring"""







        for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              SCREAMING_SNAKE_CASE :      List[Any]       =   AutoConfig.from_pretrained(UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      int       =   TFAutoModelWithLMHead.from_pretrained(UpperCAmelCase__				,				from_pt=UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      Tuple       =   AutoModelWithLMHead.from_pretrained(UpperCAmelCase__				,				from_tf=UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)


  @slow
  def  _lowercase      (			self    : Optional[Any]		)					->Dict:
        """simple docstring"""







        for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              SCREAMING_SNAKE_CASE :      List[str]       =   AutoConfig.from_pretrained(UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      Tuple       =   TFAutoModelForMaskedLM.from_pretrained(UpperCAmelCase__				,				from_pt=UpperCAmelCase__		)
              SCREAMING_SNAKE_CASE     ,	SCREAMING_SNAKE_CASE :      Dict       =   TFAutoModelForMaskedLM.from_pretrained(
                  UpperCAmelCase__				,				output_loading_info=UpperCAmelCase__				,				from_pt=UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      Any       =   AutoModelForMaskedLM.from_pretrained(UpperCAmelCase__				,				from_tf=UpperCAmelCase__		)
              SCREAMING_SNAKE_CASE     ,	SCREAMING_SNAKE_CASE :      Tuple       =   AutoModelForMaskedLM.from_pretrained(
                  UpperCAmelCase__				,				output_loading_info=UpperCAmelCase__				,				from_tf=UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)


  @slow
  def  _lowercase      (			self    : Any		)					->int:
        """simple docstring"""







        for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              SCREAMING_SNAKE_CASE :      int       =   AutoConfig.from_pretrained(UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      Tuple       =   TFAutoModelForSeqaSeqLM.from_pretrained(UpperCAmelCase__				,				from_pt=UpperCAmelCase__		)
              SCREAMING_SNAKE_CASE     ,	SCREAMING_SNAKE_CASE :      Any       =   TFAutoModelForSeqaSeqLM.from_pretrained(
                  UpperCAmelCase__				,				output_loading_info=UpperCAmelCase__				,				from_pt=UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      Tuple       =   AutoModelForSeqaSeqLM.from_pretrained(UpperCAmelCase__				,				from_tf=UpperCAmelCase__		)
              SCREAMING_SNAKE_CASE     ,	SCREAMING_SNAKE_CASE :      Optional[Any]       =   AutoModelForSeqaSeqLM.from_pretrained(
                  UpperCAmelCase__				,				output_loading_info=UpperCAmelCase__				,				from_tf=UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)


  @slow
  def  _lowercase      (			self    : List[str]		)					->Tuple:
        """simple docstring"""







        for model_name in ["bert-base-uncased"]:
              SCREAMING_SNAKE_CASE :      List[Any]       =   AutoConfig.from_pretrained(UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      Optional[Any]       =   TFAutoModelForSequenceClassification.from_pretrained(UpperCAmelCase__				,				from_pt=UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      Tuple       =   AutoModelForSequenceClassification.from_pretrained(UpperCAmelCase__				,				from_tf=UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)


  @slow
  def  _lowercase      (			self    : Dict		)					->Optional[int]:
        """simple docstring"""







        for model_name in ["bert-base-uncased"]:
              SCREAMING_SNAKE_CASE :      Dict       =   AutoConfig.from_pretrained(UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      Optional[int]       =   TFAutoModelForQuestionAnswering.from_pretrained(UpperCAmelCase__				,				from_pt=UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      List[str]       =   AutoModelForQuestionAnswering.from_pretrained(UpperCAmelCase__				,				from_tf=UpperCAmelCase__		)
              self.assertIsNotNone(UpperCAmelCase__		)
              self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)


  def  _lowercase      (			self    : List[str]		)					->Tuple:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      int       =   TFAutoModelWithLMHead.from_pretrained(UpperCAmelCase__				,				from_pt=UpperCAmelCase__		)
        self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)
        self.assertEqual(model.num_parameters()				,				1_4_4_1_0		)
        self.assertEqual(model.num_parameters(only_trainable=UpperCAmelCase__		)				,				1_4_4_1_0		)

        SCREAMING_SNAKE_CASE :      List[str]       =   AutoModelWithLMHead.from_pretrained(UpperCAmelCase__				,				from_tf=UpperCAmelCase__		)
        self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)
        self.assertEqual(model.num_parameters()				,				1_4_4_1_0		)
        self.assertEqual(model.num_parameters(only_trainable=UpperCAmelCase__		)				,				1_4_4_1_0		)




  def  _lowercase      (			self    : int		)					->List[Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Dict       =   TFAutoModelWithLMHead.from_pretrained(UpperCAmelCase__				,				from_pt=UpperCAmelCase__		)
        self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)
        self.assertEqual(model.num_parameters()				,				1_4_4_1_0		)
        self.assertEqual(model.num_parameters(only_trainable=UpperCAmelCase__		)				,				1_4_4_1_0		)

        SCREAMING_SNAKE_CASE :      List[str]       =   AutoModelWithLMHead.from_pretrained(UpperCAmelCase__				,				from_tf=UpperCAmelCase__		)
        self.assertIsInstance(UpperCAmelCase__				,				UpperCAmelCase__		)
        self.assertEqual(model.num_parameters()				,				1_4_4_1_0		)
        self.assertEqual(model.num_parameters(only_trainable=UpperCAmelCase__		)				,				1_4_4_1_0		)







from __future__ import annotations

import numpy as np






def 					__lowercase      (     _A			)     ->						tuple[np.ndarray, np.ndarray]:
      SCREAMING_SNAKE_CASE     ,	SCREAMING_SNAKE_CASE :      Dict       =   np.shape(_A			)
      if rows != columns:
            SCREAMING_SNAKE_CASE :      int       =   (
                """'table' has to be of square shaped array but got a """
                F"{rows}x{columns} array:\n{table}"
            )
            raise ValueError(_A			)

      SCREAMING_SNAKE_CASE :      Union[str, Any]       =   np.zeros((rows, columns)			)
      SCREAMING_SNAKE_CASE :      Optional[Any]       =   np.zeros((rows, columns)			)
      for i in range(_A			):
            for j in range(_A			):
                  SCREAMING_SNAKE_CASE :      Tuple       =   sum(lower[i][k] * upper[k][j] for k in range(_A			)			)
                  if upper[j][j] == 0:
                        raise ArithmeticError("""No LU decomposition exists"""			)
                  SCREAMING_SNAKE_CASE :      Union[str, Any]       =   (table[i][j] - total) / upper[j][j]
            SCREAMING_SNAKE_CASE :      Optional[Any]       =   1
            for j in range(_A						,    _A			):
                  SCREAMING_SNAKE_CASE :      List[str]       =   sum(lower[i][k] * upper[k][j] for k in range(_A			)			)
                  SCREAMING_SNAKE_CASE :      Optional[Any]       =   table[i][j] - total
      return lower, upper


if __name__ == "__main__":
  import doctest

  doctest.testmod()




