





import unittest

import numpy as np

from transformers import ElectraConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
							from transformers.models.electra.modeling_flax_electra import (
							    FlaxElectraForCausalLM,
							    FlaxElectraForMaskedLM,
							    FlaxElectraForMultipleChoice,
							    FlaxElectraForPreTraining,
							    FlaxElectraForQuestionAnswering,
							    FlaxElectraForSequenceClassification,
							    FlaxElectraForTokenClassification,
							    FlaxElectraModel,
							)

class    __A  (    unittest.TestCase     ):


				def __init__(		self ,			UpperCAmelCase_ ,			UpperCAmelCase_=13 ,			UpperCAmelCase_=7 ,			UpperCAmelCase_=True ,			UpperCAmelCase_=True ,			UpperCAmelCase_=True ,			UpperCAmelCase_=True ,			UpperCAmelCase_=99 ,			UpperCAmelCase_=24 ,			UpperCAmelCase_=32 ,			UpperCAmelCase_=5 ,			UpperCAmelCase_=4 ,			UpperCAmelCase_=37 ,			UpperCAmelCase_="gelu" ,			UpperCAmelCase_=0.1 ,			UpperCAmelCase_=0.1 ,			UpperCAmelCase_=512 ,			UpperCAmelCase_=16 ,			UpperCAmelCase_=2 ,			UpperCAmelCase_=0.0_2 ,			UpperCAmelCase_=4 ,			):
								lowerCamelCase									=parent
								lowerCamelCase									=batch_size
								lowerCamelCase									=seq_length
								lowerCamelCase									=is_training
								lowerCamelCase									=use_attention_mask
								lowerCamelCase									=use_token_type_ids
								lowerCamelCase									=use_labels
								lowerCamelCase									=vocab_size
								lowerCamelCase									=hidden_size
								lowerCamelCase									=embedding_size
								lowerCamelCase									=num_hidden_layers
								lowerCamelCase									=num_attention_heads
								lowerCamelCase									=intermediate_size
								lowerCamelCase									=hidden_act
								lowerCamelCase									=hidden_dropout_prob
								lowerCamelCase									=attention_probs_dropout_prob
								lowerCamelCase									=max_position_embeddings
								lowerCamelCase									=type_vocab_size
								lowerCamelCase									=type_sequence_label_size
								lowerCamelCase									=initializer_range
								lowerCamelCase									=num_choices


				def _snake_case							(		self				):
								lowerCamelCase									=ids_tensor([self.batch_size, self.seq_length] ,			self.vocab_size				)

								lowerCamelCase									=None
								if self.use_attention_mask:
												lowerCamelCase									=random_attention_mask([self.batch_size, self.seq_length]				)

								lowerCamelCase									=None
								if self.use_token_type_ids:
												lowerCamelCase									=ids_tensor([self.batch_size, self.seq_length] ,			self.type_vocab_size				)

								lowerCamelCase									=ElectraConfig(
								    vocab_size=self.vocab_size ,			hidden_size=self.hidden_size ,			embedding_size=self.embedding_size ,			num_hidden_layers=self.num_hidden_layers ,			num_attention_heads=self.num_attention_heads ,			intermediate_size=self.intermediate_size ,			hidden_act=self.hidden_act ,			hidden_dropout_prob=self.hidden_dropout_prob ,			attention_probs_dropout_prob=self.attention_probs_dropout_prob ,			max_position_embeddings=self.max_position_embeddings ,			type_vocab_size=self.type_vocab_size ,			initializer_range=self.initializer_range ,			)

								return config, input_ids, token_type_ids, attention_mask


				def _snake_case							(		self				):
								lowerCamelCase									=self.prepare_config_and_inputs()
								lowerCamelCase			,	lowerCamelCase			,	lowerCamelCase			,	lowerCamelCase									=config_and_inputs
								lowerCamelCase									={"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": attention_mask}
								return config, inputs_dict




@require_flax
class    __A  (    a     ,       unittest.TestCase     ):
				__A  =					True

				__A  =					(
				    (
				        FlaxElectraModel,
				        FlaxElectraForCausalLM,
				        FlaxElectraForMaskedLM,
				        FlaxElectraForPreTraining,
				        FlaxElectraForTokenClassification,
				        FlaxElectraForQuestionAnswering,
				        FlaxElectraForMultipleChoice,
				        FlaxElectraForSequenceClassification,
				    )
				    if is_flax_available()
				    else ()
				)


				def _snake_case							(		self				):
								lowerCamelCase									=FlaxElectraModelTester(self				)


				@slow
				def _snake_case							(		self				):
								for model_class_name in self.all_model_classes:
												if model_class_name == FlaxElectraForMaskedLM:
																lowerCamelCase									=model_class_name.from_pretrained("""google/electra-small-generator"""				)
												else:
																lowerCamelCase									=model_class_name.from_pretrained("""google/electra-small-discriminator"""				)
												lowerCamelCase									=model(np.ones((1, 1)				)				)
												self.assertIsNotNone(UpperCAmelCase_				)












import argparse
import os


UpperCAmelCase__    :      Any       					={
    '''pytorch''': {
        '''1.13''': {
            '''torch''': '''1.13.1''',
            '''torchvision''': '''0.14.1''',
            '''torchaudio''': '''0.13.1''',
            '''python''': 3.9,
            '''cuda''': '''cu116''',
            '''install''': (
                '''python3 -m pip install --no-cache-dir -U torch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1'''
                ''' --extra-index-url https://download.pytorch.org/whl/cu116'''
            ),
            '''base_image''': '''nvidia/cuda:11.6.2-cudnn8-devel-ubuntu20.04''',
        },
        '''1.12''': {
            '''torch''': '''1.12.1''',
            '''torchvision''': '''0.13.1''',
            '''torchaudio''': '''0.12.1''',
            '''python''': 3.9,
            '''cuda''': '''cu113''',
            '''install''': (
                '''python3 -m pip install --no-cache-dir -U torch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1'''
                ''' --extra-index-url https://download.pytorch.org/whl/cu113'''
            ),
            '''base_image''': '''nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04''',
        },
        '''1.11''': {
            '''torch''': '''1.11.0''',
            '''torchvision''': '''0.12.0''',
            '''torchaudio''': '''0.11.0''',
            '''python''': 3.9,
            '''cuda''': '''cu113''',
            '''install''': (
                '''python3 -m pip install --no-cache-dir -U torch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0'''
                ''' --extra-index-url https://download.pytorch.org/whl/cu113'''
            ),
            '''base_image''': '''nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04''',
        },
        '''1.10''': {
            '''torch''': '''1.10.2''',
            '''torchvision''': '''0.11.3''',
            '''torchaudio''': '''0.10.2''',
            '''python''': 3.9,
            '''cuda''': '''cu113''',
            '''install''': (
                '''python3 -m pip install --no-cache-dir -U torch==1.10.2 torchvision==0.11.3 torchaudio==0.10.2'''
                ''' --extra-index-url https://download.pytorch.org/whl/cu113'''
            ),
            '''base_image''': '''nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04''',
        },
        # torchaudio < 0.10 has no CUDA-enabled binary distributions
        '''1.9''': {
            '''torch''': '''1.9.1''',
            '''torchvision''': '''0.10.1''',
            '''torchaudio''': '''0.9.1''',
            '''python''': 3.9,
            '''cuda''': '''cu111''',
            '''install''': (
                '''python3 -m pip install --no-cache-dir -U torch==1.9.1 torchvision==0.10.1 torchaudio==0.9.1'''
                ''' --extra-index-url https://download.pytorch.org/whl/cu111'''
            ),
            '''base_image''': '''nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04''',
        },
    },
    '''tensorflow''': {
        '''2.11''': {
            '''tensorflow''': '''2.11.1''',
            '''install''': '''python3 -m pip install --no-cache-dir -U tensorflow==2.11.1''',
            '''base_image''': '''nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04''',
        },
        '''2.10''': {
            '''tensorflow''': '''2.10.1''',
            '''install''': '''python3 -m pip install --no-cache-dir -U tensorflow==2.10.1''',
            '''base_image''': '''nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04''',
        },
        '''2.9''': {
            '''tensorflow''': '''2.9.3''',
            '''install''': '''python3 -m pip install --no-cache-dir -U tensorflow==2.9.3''',
            '''base_image''': '''nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04''',
        },
        '''2.8''': {
            '''tensorflow''': '''2.8.2''',
            '''install''': '''python3 -m pip install --no-cache-dir -U tensorflow==2.8.2''',
            '''base_image''': '''nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04''',
        },
        '''2.7''': {
            '''tensorflow''': '''2.7.3''',
            '''install''': '''python3 -m pip install --no-cache-dir -U tensorflow==2.7.3''',
            '''base_image''': '''nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04''',
        },
        '''2.6''': {
            '''tensorflow''': '''2.6.5''',
            '''install''': '''python3 -m pip install --no-cache-dir -U tensorflow==2.6.5''',
            '''base_image''': '''nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04''',
        },
        '''2.5''': {
            '''tensorflow''': '''2.5.3''',
            '''install''': '''python3 -m pip install --no-cache-dir -U tensorflow==2.5.3''',
            '''base_image''': '''nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04''',
        },
    },
}


if __name__ == "__main__":
							UpperCAmelCase__    :      Tuple       					=argparse.ArgumentParser('''Choose the framework and version to install''')
							parser.add_argument(
							    '''--framework''', help='''The framework to install. Should be `torch` or `tensorflow`''', type=str, required=True
							)
							parser.add_argument('''--version''', help='''The version of the framework to install.''', type=str, required=True)
							UpperCAmelCase__    :      List[str]       					=parser.parse_args()

							UpperCAmelCase__    :      Dict       					=past_versions_testing[args.framework][args.version]

							os.system(F"echo \"export INSTALL_CMD=\'{info['install']}\'\" >> ~/.profile")
							print(F"echo \"export INSTALL_CMD=\'{info['install']}\'\" >> ~/.profile")

							UpperCAmelCase__    :      List[Any]       					=''''''
							if args.framework == "pytorch":
														UpperCAmelCase__    :      Optional[int]       					=info['''cuda''']
							os.system(F"echo \"export CUDA='{cuda}'\" >> ~/.profile")
							print(F"echo \"export CUDA='{cuda}'\" >> ~/.profile")





