

import importlib
import os
import sys


# This is required to make the module import works (when the python process is running from the root of the repo)
sys.path.append('''.''')


def 					A__	(       SCREAMING_SNAKE_CASE_		)   ->     str:
		lowerCamelCase   : int								=test_file.split(os.path.sep		)
		if components[0:2] != ["tests", "models"]:
				raise ValueError(
				    '''`test_file` should start with `tests/models/` (with `/` being the OS specific path separator). Got '''
				    F"{test_file} instead."		)
		lowerCamelCase   : str								=components[-1]
		if not test_fn.endswith('''py'''		):
				raise ValueError(F"`test_file` should be a python file. Got {test_fn} instead."		)
		if not test_fn.startswith('''test_modeling_'''		):
				raise ValueError(
				    F"`test_file` should point to a file name of the form `test_modeling_*.py`. Got {test_fn} instead."		)

		lowerCamelCase   : str								=components[:-1] + [test_fn.replace('''.py'''							,       ''''''		)]
		lowerCamelCase   : str								='''.'''.join(SCREAMING_SNAKE_CASE_		)

		return test_module_path


def 					A__	(       SCREAMING_SNAKE_CASE_		)   ->     Union[str, Any]:
		lowerCamelCase   : Dict								=get_module_path(SCREAMING_SNAKE_CASE_		)
		lowerCamelCase   : str								=importlib.import_module(SCREAMING_SNAKE_CASE_		)

		return test_module


def 					A__	(       SCREAMING_SNAKE_CASE_		)   ->     Union[str, Any]:
		lowerCamelCase   : str								=[]
		lowerCamelCase   : Optional[Any]								=get_test_module(SCREAMING_SNAKE_CASE_		)
		for attr in dir(SCREAMING_SNAKE_CASE_		):
				if attr.endswith('''ModelTester'''		):
						tester_classes.append(getattr(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_		)		)

    # sort with class names
		return sorted(SCREAMING_SNAKE_CASE_							,       key=lambda SCREAMING_SNAKE_CASE_		: x.__name__		)


def 					A__	(       SCREAMING_SNAKE_CASE_		)   ->     Any:
		lowerCamelCase   : Optional[Any]								=[]
		lowerCamelCase   : List[Any]								=get_test_module(SCREAMING_SNAKE_CASE_		)
		for attr in dir(SCREAMING_SNAKE_CASE_		):
				lowerCamelCase   : List[Any]								=getattr(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_		)
				# (TF/Flax)ModelTesterMixin is also an attribute in specific model test module. Let's exclude them by checking
				# `all_model_classes` is not empty (which also excludes other special classes).
				lowerCamelCase   : str								=getattr(SCREAMING_SNAKE_CASE_							,       '''all_model_classes'''							,       []		)
				if len(SCREAMING_SNAKE_CASE_		) > 0:
						test_classes.append(SCREAMING_SNAKE_CASE_		)

    # sort with class names
		return sorted(SCREAMING_SNAKE_CASE_							,       key=lambda SCREAMING_SNAKE_CASE_		: x.__name__		)


def 					A__	(       SCREAMING_SNAKE_CASE_		)   ->     Tuple:
		lowerCamelCase   : Optional[int]								=get_test_classes(SCREAMING_SNAKE_CASE_		)
		lowerCamelCase   : Optional[Any]								=set()
		for test_class in test_classes:
				model_classes.update(test_class.all_model_classes		)

		# sort with class names
		return sorted(SCREAMING_SNAKE_CASE_							,       key=lambda SCREAMING_SNAKE_CASE_		: x.__name__		)


def 					A__	(       SCREAMING_SNAKE_CASE_		)   ->     str:
		lowerCamelCase   : List[str]								=test_class()
		if hasattr(SCREAMING_SNAKE_CASE_							,       '''setUp'''		):
				test.setUp()

		lowerCamelCase   : str								=None
		if hasattr(SCREAMING_SNAKE_CASE_							,       '''model_tester'''		):
				# `(TF/Flax)ModelTesterMixin` has this attribute default to `None`. Let's skip this case.
				if test.model_tester is not None:
						lowerCamelCase   : List[str]								=test.model_tester.__class__

		return model_tester


def 					A__	(       SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_		)   ->     List[Any]:
		lowerCamelCase   : Tuple								=get_test_classes(SCREAMING_SNAKE_CASE_		)

		lowerCamelCase   : Dict								=[]
		for test_class in test_classes:
				if model_class in test_class.all_model_classes:
						target_test_classes.append(SCREAMING_SNAKE_CASE_		)

    # sort with class names
		return sorted(SCREAMING_SNAKE_CASE_							,       key=lambda SCREAMING_SNAKE_CASE_		: x.__name__		)


def 					A__	(       SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_		)   ->     str:
		lowerCamelCase   : Tuple								=get_test_classes_for_model(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_		)

		lowerCamelCase   : str								=[]
		for test_class in test_classes:
				lowerCamelCase   : Union[str, Any]								=get_model_tester_from_test_class(SCREAMING_SNAKE_CASE_		)
				if tester_class is not None:
						tester_classes.append(SCREAMING_SNAKE_CASE_		)

    # sort with class names
		return sorted(SCREAMING_SNAKE_CASE_							,       key=lambda SCREAMING_SNAKE_CASE_		: x.__name__		)


def 					A__	(       SCREAMING_SNAKE_CASE_		)   ->     Tuple:
		lowerCamelCase   : str								=get_test_classes(SCREAMING_SNAKE_CASE_		)
		lowerCamelCase   : Any								={test_class: get_model_tester_from_test_class(SCREAMING_SNAKE_CASE_		) for test_class in test_classes}
		return test_tester_mapping


def 					A__	(       SCREAMING_SNAKE_CASE_		)   ->     Dict:
		lowerCamelCase   : Optional[int]								=get_model_classes(SCREAMING_SNAKE_CASE_		)
		lowerCamelCase   : Union[str, Any]								={
		    model_class: get_test_classes_for_model(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_		) for model_class in model_classes
		}
		return model_test_mapping


def 					A__	(       SCREAMING_SNAKE_CASE_		)   ->     Tuple:
		lowerCamelCase   : Tuple								=get_model_classes(SCREAMING_SNAKE_CASE_		)
		lowerCamelCase   : Dict								={
		    model_class: get_tester_classes_for_model(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_		) for model_class in model_classes
		}
		return model_to_tester_mapping



def 					A__	(       SCREAMING_SNAKE_CASE_		)   ->     Dict:
		if isinstance(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_		):
				return o
		elif isinstance(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_		):
				return o.__name__
		elif isinstance(SCREAMING_SNAKE_CASE_							,       (list, tuple)		):
				return [to_json(SCREAMING_SNAKE_CASE_		) for x in o]
		elif isinstance(SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_		):
				return {to_json(SCREAMING_SNAKE_CASE_		): to_json(SCREAMING_SNAKE_CASE_		) for k, v in o.items()}
		else:
				return o








# coding=utf-8
# Copyright 2020 The HuggingFace Inc. team.
#
# 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.

# this script dumps information about the environment

import os
import sys

import transformers


snake_case_							=			'''3'''

print('''Python version:''', sys.version)
print('''transformers version:''', transformers.__version__)

try:
				import torch

				print('''Torch version:''', torch.__version__)
				print('''Cuda available:''', torch.cuda.is_available())
				print('''Cuda version:''', torch.version.cuda)
				print('''CuDNN version:''', torch.backends.cudnn.version())
				print('''Number of GPUs available:''', torch.cuda.device_count())
				print('''NCCL version:''', torch.cuda.nccl.version())
except ImportError:
				print('''Torch version:''', None)

try:
				import deepspeed

				print('''DeepSpeed version:''', deepspeed.__version__)
except ImportError:
				print('''DeepSpeed version:''', None)

try:
				import tensorflow as tf

				print('''TensorFlow version:''', tf.__version__)
				print('''TF GPUs available:''', bool(tf.config.list_physical_devices('''GPU''')))
				print('''Number of TF GPUs available:''', len(tf.config.list_physical_devices('''GPU''')))
except ImportError:
				print('''TensorFlow version:''', None)

