




"""simple docstring"""






from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowercase__     						=						logging.get_logger(__name__)

lowercase__     						=						{
    """google/mobilenet_v1_1.0_224""": """https://huggingface.co/google/mobilenet_v1_1.0_224/resolve/main/config.json""",
    """google/mobilenet_v1_0.75_192""": """https://huggingface.co/google/mobilenet_v1_0.75_192/resolve/main/config.json""",
    # See all MobileNetV1 models at https://huggingface.co/models?filter=mobilenet_v1
}






class lowerCAmelCase__	(     lowercase						):






			'''simple docstring'''



			lowerCamelCase__      =			"""mobilenet_v1"""
			def __init__(  self  ,      lowercase=3  ,      lowercase=224  ,      lowercase=1.0  ,      lowercase=8  ,      lowercase="relu6"  ,      lowercase=True  ,      lowercase=0.9_99  ,      lowercase=0.02  ,      lowercase=0.0_01  ,      **lowercase  ,      ):
							super().__init__(**lowercase  )

							if depth_multiplier <= 0:
											raise ValueError('depth_multiplier must be greater than zero.'  )

							_lowerCamelCase     :			Optional[int]    =    num_channels
							_lowerCamelCase     :			Any    =    image_size
							_lowerCamelCase     :			str    =    depth_multiplier
							_lowerCamelCase     :			Dict    =    min_depth
							_lowerCamelCase     :			List[str]    =    hidden_act
							_lowerCamelCase     :			Union[str, Any]    =    tf_padding
							_lowerCamelCase     :			str    =    classifier_dropout_prob
							_lowerCamelCase     :			Tuple    =    initializer_range
							_lowerCamelCase     :			int    =    layer_norm_eps






class lowerCAmelCase__	(     lowercase						):






			'''simple docstring'''



			lowerCamelCase__      =			version.parse("""1.11"""						)
			@property
			def 					A_    (  self  ):
							return OrderedDict([('pixel_values', {0: 'batch'})]  )
			@property
			def 					A_    (  self  ):
							if self.task == "image-classification":
											return OrderedDict([('logits', {0: 'batch'})]  )
							else:
											return OrderedDict([('last_hidden_state', {0: 'batch'}), ('pooler_output', {0: 'batch'})]  )






			@property
			def 					A_    (  self  ):
							return 1E-4





"""simple docstring"""






import json
import logging
import os
import sys
from time import time
from unittest.mock import patch

from transformers.testing_utils import TestCasePlus, require_torch_tpu


logging.basicConfig(level=logging.DEBUG)

lowercase__     						=						logging.getLogger()







def      _snake_case			(				lowercase__		):
				_lowerCamelCase     :			List[Any]    =    {}
				_lowerCamelCase     :			List[Any]    =    os.path.join(lowercase__							,    'all_results.json'		)
				if os.path.exists(lowercase__		):
								with open(lowercase__							,    'r'		) as f:
												_lowerCamelCase     :			List[Any]    =    json.load(lowercase__		)
				else:
								raise ValueError(f'''can\'t find {path}'''		)
				return results


lowercase__     						=						logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)






@require_torch_tpu
class lowerCAmelCase__	(     lowercase						):






			'''simple docstring'''



			def 					A_    (  self  ):
							import xla_spawn

							_lowerCamelCase     :			List[Any]    =    self.get_auto_remove_tmp_dir()
							_lowerCamelCase     :			List[Any]    =    F'''
            ./examples/pytorch/text-classification/run_glue.py
            --num_cores=8
            ./examples/pytorch/text-classification/run_glue.py
            --model_name_or_path distilbert-base-uncased
            --output_dir {tmp_dir}
            --overwrite_output_dir
            --train_file ./tests/fixtures/tests_samples/MRPC/train.csv
            --validation_file ./tests/fixtures/tests_samples/MRPC/dev.csv
            --do_train
            --do_eval
            --debug tpu_metrics_debug
            --per_device_train_batch_size=2
            --per_device_eval_batch_size=1
            --learning_rate=1e-4
            --max_steps=10
            --warmup_steps=2
            --seed=42
            --max_seq_length=128
            '''.split()

							with patch.object(lowercase  ,      'argv'  ,      lowercase  ):
											_lowerCamelCase     :			Dict    =    time()
											xla_spawn.main()
											_lowerCamelCase     :			Any    =    time()

											_lowerCamelCase     :			Optional[int]    =    get_results(lowercase  )
											self.assertGreaterEqual(result['eval_accuracy']  ,      0.75  )

											# Assert that the script takes less than 500 seconds to make sure it doesn't hang.
											self.assertLess(end - start  ,      500  )






			def 					A_    (  self  ):
							import xla_spawn

							_lowerCamelCase     :			Tuple    =    '\n            ./tests/test_trainer_tpu.py\n            --num_cores=8\n            ./tests/test_trainer_tpu.py\n            '.split()
							with patch.object(lowercase  ,      'argv'  ,      lowercase  ):
											xla_spawn.main()