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			):

      @slow
      def        A__ (		self		):







            """simple docstring"""



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

                  lowercase														=			TFAutoModel.from_pretrained(__lowerCAmelCase	, from_pt=__lowerCAmelCase		)
                  self.assertIsNotNone(__lowerCAmelCase		)
                  self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)

                  lowercase														=			AutoModel.from_pretrained(__lowerCAmelCase	, from_tf=__lowerCAmelCase		)
                  self.assertIsNotNone(__lowerCAmelCase		)
                  self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)

      @slow
      def        A__ (		self		):







            """simple docstring"""



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

                  lowercase														=			TFAutoModelForPreTraining.from_pretrained(__lowerCAmelCase	, from_pt=__lowerCAmelCase		)
                  self.assertIsNotNone(__lowerCAmelCase		)
                  self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)

                  lowercase														=			AutoModelForPreTraining.from_pretrained(__lowerCAmelCase	, from_tf=__lowerCAmelCase		)
                  self.assertIsNotNone(__lowerCAmelCase		)
                  self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)

      @slow
      def        A__ (		self		):







            """simple docstring"""



            for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                  lowercase														=			AutoConfig.from_pretrained(__lowerCAmelCase		)
                  self.assertIsNotNone(__lowerCAmelCase		)
                  self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)

                  lowercase														=			TFAutoModelForCausalLM.from_pretrained(__lowerCAmelCase	, from_pt=__lowerCAmelCase		)
                  lowercase							,							lowercase														=			TFAutoModelForCausalLM.from_pretrained(
                      __lowerCAmelCase	, output_loading_info=__lowerCAmelCase	, from_pt=__lowerCAmelCase		)
                  self.assertIsNotNone(__lowerCAmelCase		)
                  self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)

                  lowercase														=			AutoModelForCausalLM.from_pretrained(__lowerCAmelCase	, from_tf=__lowerCAmelCase		)
                  lowercase							,							lowercase														=			AutoModelForCausalLM.from_pretrained(
                      __lowerCAmelCase	, output_loading_info=__lowerCAmelCase	, from_tf=__lowerCAmelCase		)
                  self.assertIsNotNone(__lowerCAmelCase		)
                  self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)

      @slow
      def        A__ (		self		):







            """simple docstring"""



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

                  lowercase														=			TFAutoModelWithLMHead.from_pretrained(__lowerCAmelCase	, from_pt=__lowerCAmelCase		)
                  self.assertIsNotNone(__lowerCAmelCase		)
                  self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)

                  lowercase														=			AutoModelWithLMHead.from_pretrained(__lowerCAmelCase	, from_tf=__lowerCAmelCase		)
                  self.assertIsNotNone(__lowerCAmelCase		)
                  self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)

      @slow
      def        A__ (		self		):







            """simple docstring"""



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

                  lowercase														=			TFAutoModelForMaskedLM.from_pretrained(__lowerCAmelCase	, from_pt=__lowerCAmelCase		)
                  lowercase							,							lowercase														=			TFAutoModelForMaskedLM.from_pretrained(
                      __lowerCAmelCase	, output_loading_info=__lowerCAmelCase	, from_pt=__lowerCAmelCase		)
                  self.assertIsNotNone(__lowerCAmelCase		)
                  self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)

                  lowercase														=			AutoModelForMaskedLM.from_pretrained(__lowerCAmelCase	, from_tf=__lowerCAmelCase		)
                  lowercase							,							lowercase														=			AutoModelForMaskedLM.from_pretrained(
                      __lowerCAmelCase	, output_loading_info=__lowerCAmelCase	, from_tf=__lowerCAmelCase		)
                  self.assertIsNotNone(__lowerCAmelCase		)
                  self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)

      @slow
      def        A__ (		self		):







            """simple docstring"""



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

                  lowercase														=			TFAutoModelForSeqaSeqLM.from_pretrained(__lowerCAmelCase	, from_pt=__lowerCAmelCase		)
                  lowercase							,							lowercase														=			TFAutoModelForSeqaSeqLM.from_pretrained(
                      __lowerCAmelCase	, output_loading_info=__lowerCAmelCase	, from_pt=__lowerCAmelCase		)
                  self.assertIsNotNone(__lowerCAmelCase		)
                  self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)

                  lowercase														=			AutoModelForSeqaSeqLM.from_pretrained(__lowerCAmelCase	, from_tf=__lowerCAmelCase		)
                  lowercase							,							lowercase														=			AutoModelForSeqaSeqLM.from_pretrained(
                      __lowerCAmelCase	, output_loading_info=__lowerCAmelCase	, from_tf=__lowerCAmelCase		)
                  self.assertIsNotNone(__lowerCAmelCase		)
                  self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)

      @slow
      def        A__ (		self		):







            """simple docstring"""



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

                  lowercase														=			TFAutoModelForSequenceClassification.from_pretrained(__lowerCAmelCase	, from_pt=__lowerCAmelCase		)
                  self.assertIsNotNone(__lowerCAmelCase		)
                  self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)

                  lowercase														=			AutoModelForSequenceClassification.from_pretrained(__lowerCAmelCase	, from_tf=__lowerCAmelCase		)
                  self.assertIsNotNone(__lowerCAmelCase		)
                  self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)

      @slow
      def        A__ (		self		):







            """simple docstring"""



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

                  lowercase														=			TFAutoModelForQuestionAnswering.from_pretrained(__lowerCAmelCase	, from_pt=__lowerCAmelCase		)
                  self.assertIsNotNone(__lowerCAmelCase		)
                  self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)

                  lowercase														=			AutoModelForQuestionAnswering.from_pretrained(__lowerCAmelCase	, from_tf=__lowerCAmelCase		)
                  self.assertIsNotNone(__lowerCAmelCase		)
                  self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)

      def        A__ (		self		):







            """simple docstring"""



            lowercase														=			TFAutoModelWithLMHead.from_pretrained(__lowerCAmelCase	, from_pt=__lowerCAmelCase		)
            self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)
            self.assertEqual(model.num_parameters()	, 1_4410		)
            self.assertEqual(model.num_parameters(only_trainable=__lowerCAmelCase		)	, 1_4410		)

            lowercase														=			AutoModelWithLMHead.from_pretrained(__lowerCAmelCase	, from_tf=__lowerCAmelCase		)
            self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)
            self.assertEqual(model.num_parameters()	, 1_4410		)
            self.assertEqual(model.num_parameters(only_trainable=__lowerCAmelCase		)	, 1_4410		)







      def        A__ (		self		):







            """simple docstring"""



            lowercase														=			TFAutoModelWithLMHead.from_pretrained(__lowerCAmelCase	, from_pt=__lowerCAmelCase		)
            self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)
            self.assertEqual(model.num_parameters()	, 1_4410		)
            self.assertEqual(model.num_parameters(only_trainable=__lowerCAmelCase		)	, 1_4410		)

            lowercase														=			AutoModelWithLMHead.from_pretrained(__lowerCAmelCase	, from_tf=__lowerCAmelCase		)
            self.assertIsInstance(__lowerCAmelCase	, __lowerCAmelCase		)
            self.assertEqual(model.num_parameters()	, 1_4410		)
            self.assertEqual(model.num_parameters(only_trainable=__lowerCAmelCase		)	, 1_4410		)




"""simple docstring"""






# Copyright 2021 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from argparse import ArgumentParser

from accelerate.commands.config import get_config_parser
from accelerate.commands.env import env_command_parser
from accelerate.commands.launch import launch_command_parser
from accelerate.commands.test import test_command_parser
from accelerate.commands.tpu import tpu_command_parser


def     UpperCAmelCase__ (       )				->					Tuple:
      '''simple docstring'''


      lowercase														=			ArgumentParser("""Accelerate CLI tool"""      ,	usage="""accelerate <command> [<args>]"""      ,	allow_abbrev=lowerCAmelCase__	)
      lowercase														=			parser.add_subparsers(help="""accelerate command helpers"""	)

      # Register commands
      get_config_parser(subparsers=lowerCAmelCase__	)
      env_command_parser(subparsers=lowerCAmelCase__	)
      launch_command_parser(subparsers=lowerCAmelCase__	)
      tpu_command_parser(subparsers=lowerCAmelCase__	)
      test_command_parser(subparsers=lowerCAmelCase__	)

      # Let's go
      lowercase														=			parser.parse_args()

      if not hasattr(lowerCAmelCase__      ,	"""func"""	):
            parser.print_help()
            exit(1	)

      # Run
      args.func(lowerCAmelCase__	)


if __name__ == "__main__":
       main()



