

"""simple docstring"""




from dataclasses import dataclass, field
from typing import Tuple

from ..utils import cached_property, is_tf_available, logging, requires_backends
from .benchmark_args_utils import BenchmarkArguments


if is_tf_available():
      import tensorflow as tf


__UpperCAmelCase			=					logging.get_logger(__name__)







@dataclass
class   __lowercase      (     lowercase_       ):
  snake_case_												=							[
      "no_inference",
      "no_cuda",
      "no_tpu",
      "no_speed",
      "no_memory",
      "no_env_print",
      "no_multi_process",
  ]

  def __init__(	self		:      List[str]       ,**A		:      Any     ):






   '''simple docstring'''





   for deprecated_arg in self.deprecated_args:
    if deprecated_arg in kwargs:
     UpperCAmelCase__       :	Optional[int]        =       deprecated_arg[3:]
     UpperCAmelCase__       :	Any        =       not kwargs.pop(a__     )
     logger.warning(
         f"{deprecated_arg} is depreciated. Please use --no-{positive_arg} or"
         f" {positive_arg}={kwargs[positive_arg]}"     )
   UpperCAmelCase__       :	List[Any]        =       kwargs.pop("""tpu_name"""       ,self.tpu_name     )
   UpperCAmelCase__       :	Dict        =       kwargs.pop("""device_idx"""       ,self.device_idx     )
   UpperCAmelCase__       :	Dict        =       kwargs.pop("""eager_mode"""       ,self.eager_mode     )
   UpperCAmelCase__       :	Union[str, Any]        =       kwargs.pop("""use_xla"""       ,self.use_xla     )
   super().__init__(**a__     )

  snake_case_												=							field(
      default=lowercase_						,      metadata={"""help""": """Name of TPU"""}						,      )
  snake_case_												=							field(
      default=0						,      metadata={"""help""": """CPU / GPU device index. Defaults to 0."""}						,      )
  snake_case_												=							field(default=lowercase_						,      metadata={"""help""": """Benchmark models in eager model."""}       )
  snake_case_												=							field(
      default=lowercase_						,      metadata={
          """help""": """Benchmark models using XLA JIT compilation. Note that `eager_model` has to be set to `False`."""
      }						,      )

  @cached_property
  def  __lowercase							(	self		:      List[Any]     ):






   '''simple docstring'''
   requires_backends(self       ,["""tf"""]     )
   UpperCAmelCase__       :	int        =       None
   if self.tpu:
    try:
     if self.tpu_name:
      UpperCAmelCase__       :	Tuple        =       tf.distribute.cluster_resolver.TPUClusterResolver(self.tpu_name     )
     else:
      UpperCAmelCase__       :	Any        =       tf.distribute.cluster_resolver.TPUClusterResolver()
    except ValueError:
     UpperCAmelCase__       :	Any        =       None
   return tpu

  @cached_property
  def  __lowercase							(	self		:      Tuple     ):






   '''simple docstring'''
   requires_backends(self       ,["""tf"""]     )
   if self.is_tpu:
    tf.config.experimental_connect_to_cluster(self._setup_tpu     )
    tf.tpu.experimental.initialize_tpu_system(self._setup_tpu     )

    UpperCAmelCase__       :	Tuple        =       tf.distribute.TPUStrategy(self._setup_tpu     )
   else:
    # currently no multi gpu is allowed
    if self.is_gpu:
     # TODO: Currently only single GPU is supported
     tf.config.set_visible_devices(self.gpu_list[self.device_idx]       ,"""GPU"""     )
     UpperCAmelCase__       :	List[Any]        =       tf.distribute.OneDeviceStrategy(device=f"/gpu:{self.device_idx}"     )
    else:
     tf.config.set_visible_devices([]       ,"""GPU"""     )  # disable GPU
     UpperCAmelCase__       :	Any        =       tf.distribute.OneDeviceStrategy(device=f"/cpu:{self.device_idx}"     )

   return strategy

  @property
  def  __lowercase							(	self		:      str     ):






   '''simple docstring'''
   requires_backends(self       ,["""tf"""]     )
   return self._setup_tpu is not None

  @property
  def  __lowercase							(	self		:      Dict     ):






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

  @property
  def  __lowercase							(	self		:      Union[str, Any]     ):






   '''simple docstring'''
   requires_backends(self       ,["""tf"""]     )
   return tf.config.list_physical_devices("""GPU"""     )

  @property
  def  __lowercase							(	self		:      List[Any]     ):






   '''simple docstring'''
   requires_backends(self       ,["""tf"""]     )
   if self.cuda:
    return len(self.gpu_list     )
   return 0




  @property
  def  __lowercase							(	self		:      int     ):






   '''simple docstring'''
   return self.n_gpu > 0













from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


lowerCamelCase__       		=  logging.get_logger(__name__)

lowerCamelCase__       		=  {
    """microsoft/focalnet-tiny""": """https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json""",
}




class       snake_case__ (				lowercase_						,     lowercase_):

       '''simple docstring'''
       lowerCamelCase				:					List[Any]								=			"focalnet"



       def __init__(				self      ,    a__=2_24      ,    a__=4      ,    a__=3      ,    a__=96      ,    a__=False      ,    a__=[1_92, 3_84, 7_68, 7_68]      ,    a__=[2, 2, 6, 2]      ,    a__=[2, 2, 2, 2]      ,    a__=[3, 3, 3, 3]      ,    a__="gelu"      ,    a__=4.0      ,    a__=0.0      ,    a__=0.1      ,    a__=False      ,    a__=1e-4      ,    a__=False      ,    a__=False      ,    a__=False      ,    a__=0.02      ,    a__=1e-5      ,    a__=32      ,    a__=None      ,    a__=None      ,    **a__      ,    )			->   Tuple:






            '''simple docstring'''





            super().__init__(**a__     )

            __snake_case      :Optional[Any] 							=    image_size
            __snake_case      :Dict 							=    patch_size
            __snake_case      :Tuple 							=    num_channels
            __snake_case      :List[str] 							=    embed_dim
            __snake_case      :Any 							=    use_conv_embed
            __snake_case      :List[Any] 							=    hidden_sizes
            __snake_case      :str 							=    depths
            __snake_case      :List[Any] 							=    focal_levels
            __snake_case      :int 							=    focal_windows
            __snake_case      :Any 							=    hidden_act
            __snake_case      :List[str] 							=    mlp_ratio
            __snake_case      :str 							=    hidden_dropout_prob
            __snake_case      :List[str] 							=    drop_path_rate
            __snake_case      :int 							=    use_layerscale
            __snake_case      :int 							=    layerscale_value
            __snake_case      :Tuple 							=    use_post_layernorm
            __snake_case      :Dict 							=    use_post_layernorm_in_modulation
            __snake_case      :Union[str, Any] 							=    normalize_modulator
            __snake_case      :List[str] 							=    initializer_range
            __snake_case      :Optional[Any] 							=    layer_norm_eps
            __snake_case      :Tuple 							=    encoder_stride
            __snake_case      :List[str] 							=    ["""stem"""] + [F'''stage{idx}''' for idx in range(1      ,    len(self.depths     ) + 1     )]
            __snake_case							,			__snake_case      :str 							=    get_aligned_output_features_output_indices(
                out_features=a__      ,    out_indices=a__      ,    stage_names=self.stage_names     )


