





from dataclasses import dataclass, field
from typing import Tuple

from ..utils import cached_property, is_torch_available, is_torch_tpu_available, logging, requires_backends
from .benchmark_args_utils import BenchmarkArguments


if is_torch_available():
    import torch

if is_torch_tpu_available(check_device=False):
    import torch_xla.core.xla_model as xm


lowercase      :       List[str]									=  logging.get_logger(__name__)





@dataclass
class  A__    (							__UpperCAmelCase	):




   """simple docstring"""



   __A   :				Optional[Any]         =  [
       '''no_inference''',
       '''no_cuda''',
       '''no_tpu''',
       '''no_speed''',
       '''no_memory''',
       '''no_env_print''',
       '''no_multi_process''',
   ]

   def __init__(					self					,  **lowercase)			->						Tuple:







          '''simple docstring'''

          for deprecated_arg in self.deprecated_args:
                 if deprecated_arg in kwargs:
                        a__						:	Union[str, Any] =				deprecated_arg[3:]
                        setattr(self					,  lowercase					,  not kwargs.pop(lowercase))
                        logger.warning(
                            F'{deprecated_arg} is depreciated. Please use --no_{positive_arg} or'
                            F' {positive_arg}={kwargs[positive_arg]}')

          a__						:	Union[str, Any] =				kwargs.pop('torchscript'					,  self.torchscript)
          a__						:	Tuple =				kwargs.pop('torch_xla_tpu_print_metrics'					,  self.torch_xla_tpu_print_metrics)
          a__						:	Tuple =				kwargs.pop('fp16_opt_level'					,  self.fpaa_opt_level)
          super().__init__(**lowercase)

   __A   :				bool         =  field(default=__UpperCAmelCase ,  metadata={'''help''': '''Trace the models using torchscript'''}	)
   __A   :				bool         =  field(default=__UpperCAmelCase ,  metadata={'''help''': '''Print Xla/PyTorch tpu metrics'''}	)
   __A   :				str         =  field(
       default='''O1''' ,  metadata={
           '''help''': (
               '''For fp16: Apex AMP optimization level selected in [\'O0\', \'O1\', \'O2\', and \'O3\']. '''
               '''See details at https://nvidia.github.io/apex/amp.html'''
           )
       } ,  )

   @cached_property
   def 							__lowercase		(					self)			->						Tuple["torch.device", int]:







          '''simple docstring'''

          requires_backends(self					,  ['torch'])
          logger.info('PyTorch: setting up devices')
          if not self.cuda:
                 a__						:	List[str] =				torch.device('cpu')
                 a__						:	Optional[Any] =				0
          elif is_torch_tpu_available():
                 a__						:	List[str] =				xm.xla_device()
                 a__						:	Union[str, Any] =				0
          else:
                 a__						:	List[Any] =				torch.device('cuda' if torch.cuda.is_available() else 'cpu')
                 a__						:	Optional[int] =				torch.cuda.device_count()
          return device, n_gpu

   @property
   def 							__lowercase		(					self)			->						List[str]:







          '''simple docstring'''

          return is_torch_tpu_available() and self.tpu

   @property
   def 							__lowercase		(					self)			->						int:







          '''simple docstring'''

          requires_backends(self					,  ['torch'])
          # TODO(PVP): currently only single GPU is supported
          return torch.cuda.current_device()

   @property
   def 							__lowercase		(					self)			->						"torch.device":







          '''simple docstring'''

          requires_backends(self					,  ['torch'])
          return self._setup_devices[0]

   @property
   def 							__lowercase		(					self)			->						Dict:







          '''simple docstring'''

          requires_backends(self					,  ['torch'])
          return self._setup_devices[1]

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







          '''simple docstring'''

          return self.n_gpu > 0










"""simple docstring"""



from ...configuration_utils import PretrainedConfig
from ...utils import logging


__A		:       Dict  				=		logging.get_logger(__name__)

__A		:       Union[str, Any]  				=		{
    '''facebook/vit-mae-base''': '''https://huggingface.co/facebook/vit-mae-base/resolve/main/config.json''',
    # See all ViT MAE models at https://huggingface.co/models?filter=vit-mae
}





class 					_UpperCAmelCase       ( _A							):
					SCREAMING_SNAKE_CASE_		:				Union[str, Any]							    =   "vit_mae"




					def __init__(				self     :						Dict    ,						A     :						List[str]=7_68    ,						A     :						Any=12    ,						A     :						Union[str, Any]=12    ,						A     :						Tuple=30_72    ,						A     :						Any="gelu"    ,						A     :						Tuple=0.0    ,						A     :						List[str]=0.0    ,						A     :						Tuple=0.02    ,						A     :						Tuple=1e-12    ,						A     :						int=2_24    ,						A     :						Dict=16    ,						A     :						int=3    ,						A     :						Tuple=True    ,						A     :						Tuple=16    ,						A     :						Optional[Any]=5_12    ,						A     :						Union[str, Any]=8    ,						A     :						List[Any]=20_48    ,						A     :						Dict=0.75    ,						A     :						Any=False    ,						**A     :						Optional[int]    ,						)  ->  Union[str, Any]:
							super().__init__(**A   )

							lowercase_ : List[Any]							       =   hidden_size
							lowercase_ : str							       =   num_hidden_layers
							lowercase_ : List[Any]							       =   num_attention_heads
							lowercase_ : Any							       =   intermediate_size
							lowercase_ : Optional[int]							       =   hidden_act
							lowercase_ : List[Any]							       =   hidden_dropout_prob
							lowercase_ : int							       =   attention_probs_dropout_prob
							lowercase_ : int							       =   initializer_range
							lowercase_ : Dict							       =   layer_norm_eps
							lowercase_ : Optional[Any]							       =   image_size
							lowercase_ : str							       =   patch_size
							lowercase_ : Dict							       =   num_channels
							lowercase_ : Any							       =   qkv_bias
							lowercase_ : Union[str, Any]							       =   decoder_num_attention_heads
							lowercase_ : Optional[Any]							       =   decoder_hidden_size
							lowercase_ : List[str]							       =   decoder_num_hidden_layers
							lowercase_ : List[Any]							       =   decoder_intermediate_size
							lowercase_ : Optional[Any]							       =   mask_ratio
							lowercase_ : Optional[Any]							       =   norm_pix_loss



