



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   snake_case_ (unittest.TestCase  ):




       """simple docstring"""






       @slow
       def  A_   (     self):

             """simple docstring"""





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

                   UpperCAmelCase_  :	Any				      =		TFAutoModel.from_pretrained(lowercase     ,from_pt=lowercase)
                   self.assertIsNotNone(lowercase)
                   self.assertIsInstance(lowercase     ,lowercase)

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



       @slow
       def  A_   (     self):

             """simple docstring"""





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

                   UpperCAmelCase_  :	List[Any]				      =		TFAutoModelForPreTraining.from_pretrained(lowercase     ,from_pt=lowercase)
                   self.assertIsNotNone(lowercase)
                   self.assertIsInstance(lowercase     ,lowercase)

                   UpperCAmelCase_  :	Optional[int]				      =		AutoModelForPreTraining.from_pretrained(lowercase     ,from_tf=lowercase)
                   self.assertIsNotNone(lowercase)
                   self.assertIsInstance(lowercase     ,lowercase)



       @slow
       def  A_   (     self):

             """simple docstring"""





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

                   UpperCAmelCase_  :	Dict				      =		TFAutoModelForCausalLM.from_pretrained(lowercase     ,from_pt=lowercase)
                   UpperCAmelCase_      ,      UpperCAmelCase_  :	List[str]				      =		TFAutoModelForCausalLM.from_pretrained(
                       lowercase     ,output_loading_info=lowercase     ,from_pt=lowercase)
                   self.assertIsNotNone(lowercase)
                   self.assertIsInstance(lowercase     ,lowercase)

                   UpperCAmelCase_  :	Optional[int]				      =		AutoModelForCausalLM.from_pretrained(lowercase     ,from_tf=lowercase)
                   UpperCAmelCase_      ,      UpperCAmelCase_  :	Any				      =		AutoModelForCausalLM.from_pretrained(
                       lowercase     ,output_loading_info=lowercase     ,from_tf=lowercase)
                   self.assertIsNotNone(lowercase)
                   self.assertIsInstance(lowercase     ,lowercase)



       @slow
       def  A_   (     self):

             """simple docstring"""





             for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   UpperCAmelCase_  :	Optional[Any]				      =		AutoConfig.from_pretrained(lowercase)
                   self.assertIsNotNone(lowercase)
                   self.assertIsInstance(lowercase     ,lowercase)

                   UpperCAmelCase_  :	Any				      =		TFAutoModelWithLMHead.from_pretrained(lowercase     ,from_pt=lowercase)
                   self.assertIsNotNone(lowercase)
                   self.assertIsInstance(lowercase     ,lowercase)

                   UpperCAmelCase_  :	str				      =		AutoModelWithLMHead.from_pretrained(lowercase     ,from_tf=lowercase)
                   self.assertIsNotNone(lowercase)
                   self.assertIsInstance(lowercase     ,lowercase)



       @slow
       def  A_   (     self):

             """simple docstring"""





             for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   UpperCAmelCase_  :	Dict				      =		AutoConfig.from_pretrained(lowercase)
                   self.assertIsNotNone(lowercase)
                   self.assertIsInstance(lowercase     ,lowercase)

                   UpperCAmelCase_  :	Optional[Any]				      =		TFAutoModelForMaskedLM.from_pretrained(lowercase     ,from_pt=lowercase)
                   UpperCAmelCase_      ,      UpperCAmelCase_  :	str				      =		TFAutoModelForMaskedLM.from_pretrained(
                       lowercase     ,output_loading_info=lowercase     ,from_pt=lowercase)
                   self.assertIsNotNone(lowercase)
                   self.assertIsInstance(lowercase     ,lowercase)

                   UpperCAmelCase_  :	List[str]				      =		AutoModelForMaskedLM.from_pretrained(lowercase     ,from_tf=lowercase)
                   UpperCAmelCase_      ,      UpperCAmelCase_  :	str				      =		AutoModelForMaskedLM.from_pretrained(
                       lowercase     ,output_loading_info=lowercase     ,from_tf=lowercase)
                   self.assertIsNotNone(lowercase)
                   self.assertIsInstance(lowercase     ,lowercase)



       @slow
       def  A_   (     self):

             """simple docstring"""





             for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   UpperCAmelCase_  :	str				      =		AutoConfig.from_pretrained(lowercase)
                   self.assertIsNotNone(lowercase)
                   self.assertIsInstance(lowercase     ,lowercase)

                   UpperCAmelCase_  :	Dict				      =		TFAutoModelForSeqaSeqLM.from_pretrained(lowercase     ,from_pt=lowercase)
                   UpperCAmelCase_      ,      UpperCAmelCase_  :	Optional[Any]				      =		TFAutoModelForSeqaSeqLM.from_pretrained(
                       lowercase     ,output_loading_info=lowercase     ,from_pt=lowercase)
                   self.assertIsNotNone(lowercase)
                   self.assertIsInstance(lowercase     ,lowercase)

                   UpperCAmelCase_  :	Tuple				      =		AutoModelForSeqaSeqLM.from_pretrained(lowercase     ,from_tf=lowercase)
                   UpperCAmelCase_      ,      UpperCAmelCase_  :	Union[str, Any]				      =		AutoModelForSeqaSeqLM.from_pretrained(
                       lowercase     ,output_loading_info=lowercase     ,from_tf=lowercase)
                   self.assertIsNotNone(lowercase)
                   self.assertIsInstance(lowercase     ,lowercase)



       @slow
       def  A_   (     self):

             """simple docstring"""





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

                   UpperCAmelCase_  :	Union[str, Any]				      =		TFAutoModelForSequenceClassification.from_pretrained(lowercase     ,from_pt=lowercase)
                   self.assertIsNotNone(lowercase)
                   self.assertIsInstance(lowercase     ,lowercase)

                   UpperCAmelCase_  :	List[str]				      =		AutoModelForSequenceClassification.from_pretrained(lowercase     ,from_tf=lowercase)
                   self.assertIsNotNone(lowercase)
                   self.assertIsInstance(lowercase     ,lowercase)



       @slow
       def  A_   (     self):

             """simple docstring"""





             for model_name in ["bert-base-uncased"]:
                   UpperCAmelCase_  :	str				      =		AutoConfig.from_pretrained(lowercase)
                   self.assertIsNotNone(lowercase)
                   self.assertIsInstance(lowercase     ,lowercase)

                   UpperCAmelCase_  :	List[str]				      =		TFAutoModelForQuestionAnswering.from_pretrained(lowercase     ,from_pt=lowercase)
                   self.assertIsNotNone(lowercase)
                   self.assertIsInstance(lowercase     ,lowercase)

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



       def  A_   (     self):

             """simple docstring"""





             UpperCAmelCase_  :	Optional[int]				      =		TFAutoModelWithLMHead.from_pretrained(lowercase     ,from_pt=lowercase)
             self.assertIsInstance(lowercase     ,lowercase)
             self.assertEqual(model.num_parameters()     ,14410)
             self.assertEqual(model.num_parameters(only_trainable=lowercase)     ,14410)

             UpperCAmelCase_  :	List[Any]				      =		AutoModelWithLMHead.from_pretrained(lowercase     ,from_tf=lowercase)
             self.assertIsInstance(lowercase     ,lowercase)
             self.assertEqual(model.num_parameters()     ,14410)
             self.assertEqual(model.num_parameters(only_trainable=lowercase)     ,14410)



       def  A_   (     self):

             """simple docstring"""





             UpperCAmelCase_  :	Dict				      =		TFAutoModelWithLMHead.from_pretrained(lowercase     ,from_pt=lowercase)
             self.assertIsInstance(lowercase     ,lowercase)
             self.assertEqual(model.num_parameters()     ,14410)
             self.assertEqual(model.num_parameters(only_trainable=lowercase)     ,14410)

             UpperCAmelCase_  :	List[Any]				      =		AutoModelWithLMHead.from_pretrained(lowercase     ,from_tf=lowercase)
             self.assertIsInstance(lowercase     ,lowercase)
             self.assertEqual(model.num_parameters()     ,14410)
             self.assertEqual(model.num_parameters(only_trainable=lowercase)     ,14410)





import operator







def    _snake_case (       __snake_case					,  __snake_case = False					,  __snake_case = None    )     ->     list:






      '''simple docstring'''







      UpperCAmelCase_  :	Optional[int]				      =		operator.lt if reverse else operator.gt
      UpperCAmelCase_  :	int				      =		solution or []

      if not arr:
            return solution

      UpperCAmelCase_  :	Union[str, Any]				      =		[arr.pop(0    )]
      for i, item in enumerate(__snake_case    ):
            if _operator(__snake_case					,  sublist[-1]    ):
                  sublist.append(__snake_case    )
                  arr.pop(__snake_case    )

    #  merging sublist into solution list
      if not solution:
            solution.extend(__snake_case    )
      else:
            while sublist:
                  UpperCAmelCase_  :	Optional[int]				      =		sublist.pop(0    )
                  for i, xx in enumerate(__snake_case    ):
                        if not _operator(__snake_case					,  __snake_case    ):
                              solution.insert(__snake_case					,  __snake_case    )
                              break
                  else:
                        solution.append(__snake_case    )

      strand_sort(__snake_case					,  __snake_case					,  __snake_case    )
      return solution


if __name__ == "__main__":
   assert strand_sort([4, 3, 5, 1, 2]) == [1, 2, 3, 4, 5]
   assert strand_sort([4, 3, 5, 1, 2], reverse=True) == [5, 4, 3, 2, 1]
