




import warnings
from dataclasses import dataclass, field
from typing import Optional, Tuple

from .training_args import TrainingArguments
from .utils import cached_property, is_tf_available, logging, requires_backends


a__		    =    logging.get_logger(__name__)

if is_tf_available():
 import tensorflow as tf


@dataclass
class       SCREAMING_SNAKE_CASE_							(					_UpperCamelCase      ):



 """simple docstring"""


 __magic_name__      :					List[Any]			  =		'tf'
 __magic_name__      :					Optional[str]			  =		field(
     default=_UpperCamelCase  ,     metadata={'help': 'Name of TPU'}  ,     )

 __magic_name__      :					Optional[str]			  =		field(
     default=_UpperCamelCase  ,     metadata={'help': 'Zone of TPU'}  ,     )

 __magic_name__      :					Optional[str]			  =		field(
     default=_UpperCamelCase  ,     metadata={'help': 'Name of Cloud TPU-enabled project'}  ,     )

 __magic_name__      :					float			  =		field(
     default=1.0  ,     metadata={'help': 'Power for the Polynomial decay LR scheduler.'}  ,     )

 __magic_name__      :					bool			  =		field(default=_UpperCamelCase  ,     metadata={'help': 'Whether to activate the XLA compilation or not'}      )






 @cached_property
 def 				lowerCamelCase__    (				self		:	int  )  ->					Tuple["tf.distribute.Strategy", int]:







      """simple docstring"""







      requires_backends(self				,    ["""tf"""]  )
      logger.info("""Tensorflow: setting up strategy"""  )

      __UpperCamelCase				:  Tuple								=			tf.config.list_physical_devices("""GPU"""  )

      # Set to float16 at first
      if self.fpaa:
           tf.keras.mixed_precision.set_global_policy("""mixed_float16"""  )

      if self.no_cuda:
           __UpperCamelCase				:  int								=			tf.distribute.OneDeviceStrategy(device="""/cpu:0"""  )
      else:
           try:
                if self.tpu_name:
                     __UpperCamelCase				:  Optional[Any]								=			tf.distribute.cluster_resolver.TPUClusterResolver(
                         self.tpu_name				,    zone=self.tpu_zone				,    project=self.gcp_project  )
                else:
                     __UpperCamelCase				:  List[Any]								=			tf.distribute.cluster_resolver.TPUClusterResolver()
           except ValueError:
                if self.tpu_name:
                     raise RuntimeError(F'''Couldn\'t connect to TPU {self.tpu_name}!'''  )
                else:
                     __UpperCamelCase				:  Tuple								=			None

           if tpu:
                # Set to bfloat16 in case of TPU
                if self.fpaa:
                     tf.keras.mixed_precision.set_global_policy("""mixed_bfloat16"""  )

                tf.config.experimental_connect_to_cluster(lowerCAmelCase  )
                tf.tpu.experimental.initialize_tpu_system(lowerCAmelCase  )

                __UpperCamelCase				:  List[str]								=			tf.distribute.TPUStrategy(lowerCAmelCase  )

           elif len(lowerCAmelCase  ) == 0:
                __UpperCamelCase				:  List[str]								=			tf.distribute.OneDeviceStrategy(device="""/cpu:0"""  )
           elif len(lowerCAmelCase  ) == 1:
                __UpperCamelCase				:  Optional[int]								=			tf.distribute.OneDeviceStrategy(device="""/gpu:0"""  )
           elif len(lowerCAmelCase  ) > 1:
                # If you only want to use a specific subset of GPUs use `CUDA_VISIBLE_DEVICES=0`
                __UpperCamelCase				:  Tuple								=			tf.distribute.MirroredStrategy()
           else:
                raise ValueError("""Cannot find the proper strategy, please check your environment properties."""  )

      return strategy






 @property
 def 				lowerCamelCase__    (				self		:	Optional[Any]  )  ->					"tf.distribute.Strategy":







      """simple docstring"""







      requires_backends(self				,    ["""tf"""]  )
      return self._setup_strategy






 @property
 def 				lowerCamelCase__    (				self		:	Optional[Any]  )  ->					int:







      """simple docstring"""







      requires_backends(self				,    ["""tf"""]  )
      return self._setup_strategy.num_replicas_in_sync






 @property
 def 				lowerCamelCase__    (				self		:	Optional[int]  )  ->					str:







      """simple docstring"""







      return False  # TF Logging is handled by Keras not the Trainer






 @property
 def 				lowerCamelCase__    (				self		:	str  )  ->					int:







      """simple docstring"""







      if self.per_gpu_train_batch_size:
           logger.warning(
               """Using deprecated `--per_gpu_train_batch_size` argument which will be removed in a future """
               """version. Using `--per_device_train_batch_size` is preferred."""  )
      __UpperCamelCase				:  List[str]								=			self.per_gpu_train_batch_size or self.per_device_train_batch_size
      return per_device_batch_size * self.n_replicas






 @property
 def 				lowerCamelCase__    (				self		:	Optional[int]  )  ->					int:







      """simple docstring"""







      if self.per_gpu_eval_batch_size:
           logger.warning(
               """Using deprecated `--per_gpu_eval_batch_size` argument which will be removed in a future """
               """version. Using `--per_device_eval_batch_size` is preferred."""  )
      __UpperCamelCase				:  Optional[int]								=			self.per_gpu_eval_batch_size or self.per_device_eval_batch_size
      return per_device_batch_size * self.n_replicas






 @property
 def 				lowerCamelCase__    (				self		:	Dict  )  ->					int:







      """simple docstring"""







      requires_backends(self				,    ["""tf"""]  )
      warnings.warn(
          """The n_gpu argument is deprecated and will be removed in a future version, use n_replicas instead."""				,    lowerCAmelCase				,    )
      return self._setup_strategy.num_replicas_in_sync












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


a__		    =    logging.get_logger(__name__)

a__		    =    {
    '''apple/mobilevit-small''': '''https://huggingface.co/apple/mobilevit-small/resolve/main/config.json''',
    '''apple/mobilevit-x-small''': '''https://huggingface.co/apple/mobilevit-x-small/resolve/main/config.json''',
    '''apple/mobilevit-xx-small''': '''https://huggingface.co/apple/mobilevit-xx-small/resolve/main/config.json''',
    '''apple/deeplabv3-mobilevit-small''': (
        '''https://huggingface.co/apple/deeplabv3-mobilevit-small/resolve/main/config.json'''
    ),
    '''apple/deeplabv3-mobilevit-x-small''': (
        '''https://huggingface.co/apple/deeplabv3-mobilevit-x-small/resolve/main/config.json'''
    ),
    '''apple/deeplabv3-mobilevit-xx-small''': (
        '''https://huggingface.co/apple/deeplabv3-mobilevit-xx-small/resolve/main/config.json'''
    ),
    # See all MobileViT models at https://huggingface.co/models?filter=mobilevit
}


class       SCREAMING_SNAKE_CASE_							(					_UpperCamelCase      ):



	"""simple docstring"""


	__magic_name__      :					Any			  =		'mobilevit'






	def __init__(				self		:	int				,    lowerCAmelCase		:	Dict=3				,    lowerCAmelCase		:	Dict=256				,    lowerCAmelCase		:	Any=2				,    lowerCAmelCase		:	Any=[144, 192, 240]				,    lowerCAmelCase		:	int=[16, 32, 64, 96, 128, 160, 640]				,    lowerCAmelCase		:	List[Any]=4				,    lowerCAmelCase		:	Tuple=2.0				,    lowerCAmelCase		:	Tuple=4.0				,    lowerCAmelCase		:	List[str]="silu"				,    lowerCAmelCase		:	Tuple=3				,    lowerCAmelCase		:	Tuple=32				,    lowerCAmelCase		:	Any=0.1				,    lowerCAmelCase		:	List[str]=0.0				,    lowerCAmelCase		:	Union[str, Any]=0.1				,    lowerCAmelCase		:	List[str]=0.02				,    lowerCAmelCase		:	Optional[Any]=1E-5				,    lowerCAmelCase		:	Union[str, Any]=True				,    lowerCAmelCase		:	List[str]=256				,    lowerCAmelCase		:	List[Any]=[6, 12, 18]				,    lowerCAmelCase		:	Tuple=0.1				,    lowerCAmelCase		:	List[str]=255				,    **lowerCAmelCase		:	Union[str, Any]				,    )  ->					Optional[Any]:







						"""simple docstring"""







						super().__init__(**lowerCAmelCase  )

						__UpperCamelCase				:  Tuple								=			num_channels
						__UpperCamelCase				:  Union[str, Any]								=			image_size
						__UpperCamelCase				:  List[Any]								=			patch_size
						__UpperCamelCase				:  Optional[int]								=			hidden_sizes
						__UpperCamelCase				:  Union[str, Any]								=			neck_hidden_sizes
						__UpperCamelCase				:  List[str]								=			num_attention_heads
						__UpperCamelCase				:  Union[str, Any]								=			mlp_ratio
						__UpperCamelCase				:  Tuple								=			expand_ratio
						__UpperCamelCase				:  Optional[Any]								=			hidden_act
						__UpperCamelCase				:  int								=			conv_kernel_size
						__UpperCamelCase				:  Any								=			output_stride
						__UpperCamelCase				:  int								=			hidden_dropout_prob
						__UpperCamelCase				:  Union[str, Any]								=			attention_probs_dropout_prob
						__UpperCamelCase				:  Dict								=			classifier_dropout_prob
						__UpperCamelCase				:  Any								=			initializer_range
						__UpperCamelCase				:  List[str]								=			layer_norm_eps
						__UpperCamelCase				:  Union[str, Any]								=			qkv_bias

						# decode head attributes for semantic segmentation
						__UpperCamelCase				:  Any								=			aspp_out_channels
						__UpperCamelCase				:  Union[str, Any]								=			atrous_rates
						__UpperCamelCase				:  Union[str, Any]								=			aspp_dropout_prob
						__UpperCamelCase				:  List[str]								=			semantic_loss_ignore_index






class       SCREAMING_SNAKE_CASE_							(					_UpperCamelCase      ):



	"""simple docstring"""


	__magic_name__      :					Optional[Any]			  =		version.parse('1.11'      )






	@property
	def 				lowerCamelCase__    (				self		:	Any  )  ->					Mapping[str, Mapping[int, str]]:







						"""simple docstring"""







						return OrderedDict([("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""})]  )






	@property
	def 				lowerCamelCase__    (				self		:	List[Any]  )  ->					Mapping[str, Mapping[int, str]]:







						"""simple docstring"""







						if self.task == "image-classification":
											return OrderedDict([("""logits""", {0: """batch"""})]  )
						else:
											return OrderedDict([("""last_hidden_state""", {0: """batch"""}), ("""pooler_output""", {0: """batch"""})]  )






	@property
	def 				lowerCamelCase__    (				self		:	Optional[int]  )  ->					float:







						"""simple docstring"""







						return 1E-4






