


'''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


__snake_case							      =     logging.get_logger(__name__)
@dataclass
class    lowercase	(							A__					):

		"""simple docstring"""

		_a     =				[
		    'no_inference',
		    'no_cuda',
		    'no_tpu',
		    'no_speed',
		    'no_memory',
		    'no_env_print',
		    'no_multi_process',
		]




		def __init__(		self    ,   **UpperCamelCase_							):

							'''simple docstring'''


							for deprecated_arg in self.deprecated_args:
												if deprecated_arg in kwargs:
																	UpperCamelCase__   :int												= deprecated_arg[3:]
																	UpperCamelCase__   :int												= not kwargs.pop(UpperCamelCase_							)
																	logger.warning(
																	    F'''{deprecated_arg} is depreciated. Please use --no-{positive_arg} or'''
																	    F''' {positive_arg}={kwargs[positive_arg]}'''							)
							UpperCamelCase__   :int												= kwargs.pop('''tpu_name'''    ,   self.tpu_name							)
							UpperCamelCase__   :List[str]												= kwargs.pop('''device_idx'''    ,   self.device_idx							)
							UpperCamelCase__   :List[str]												= kwargs.pop('''eager_mode'''    ,   self.eager_mode							)
							UpperCamelCase__   :Dict												= kwargs.pop('''use_xla'''    ,   self.use_xla							)
							super().__init__(**UpperCamelCase_							)

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




		@cached_property
		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							requires_backends(self    ,   ['''tf''']							)
							UpperCamelCase__   :List[str]												= None
							if self.tpu:
												try:
																	if self.tpu_name:
																						UpperCamelCase__   :Optional[int]												= tf.distribute.cluster_resolver.TPUClusterResolver(self.tpu_name							)
																	else:
																						UpperCamelCase__   :Optional[Any]												= tf.distribute.cluster_resolver.TPUClusterResolver()
												except ValueError:
																	UpperCamelCase__   :Dict												= None
							return tpu




		@cached_property
		def     lowerCAmelCase__				(		self							):

							'''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__   :Any												= 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__   :Optional[Any]												= tf.distribute.OneDeviceStrategy(device=F'''/gpu:{self.device_idx}'''							)
												else:
																	tf.config.set_visible_devices([]    ,   '''GPU'''							)  # disable GPU
																	UpperCamelCase__   :List[str]												= tf.distribute.OneDeviceStrategy(device=F'''/cpu:{self.device_idx}'''							)

							return strategy




		@property
		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


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




		@property
		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


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




		@property
		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


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




		@property
		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


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




		@property
		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							return self.n_gpu > 0






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


UpperCAmelCase	:	Dict		     =       logging.get_logger(__name__)

UpperCAmelCase	:	Tuple		     =       {
    """caidas/swin2sr-classicalsr-x2-64""": (
        """https://huggingface.co/caidas/swin2sr-classicalsr-x2-64/resolve/main/config.json"""
    ),
}







class 				__lowerCAmelCase       (    UpperCamelCase__):
      _lowercase				:					Any						=			"""swin2sr"""

      _lowercase				:					Tuple						=			{
          """hidden_size""": """embed_dim""",
          """num_attention_heads""": """num_heads""",
          """num_hidden_layers""": """num_layers""",
      }







      def __init__(    self		,      lowerCAmelCase__=6_4		,      lowerCAmelCase__=1		,      lowerCAmelCase__=3		,      lowerCAmelCase__=1_8_0		,      lowerCAmelCase__=[6, 6, 6, 6, 6, 6]		,      lowerCAmelCase__=[6, 6, 6, 6, 6, 6]		,      lowerCAmelCase__=8		,      lowerCAmelCase__=2.0		,      lowerCAmelCase__=True		,      lowerCAmelCase__=0.0		,      lowerCAmelCase__=0.0		,      lowerCAmelCase__=0.1		,      lowerCAmelCase__="gelu"		,      lowerCAmelCase__=False		,      lowerCAmelCase__=0.02		,      lowerCAmelCase__=1E-5		,      lowerCAmelCase__=2		,      lowerCAmelCase__=1.0		,      lowerCAmelCase__="1conv"		,      lowerCAmelCase__="pixelshuffle"		,      **lowerCAmelCase__		,      )   ->						int:



        '''simple docstring'''




        super().__init__(**lowerCAmelCase__							)

        a__	:					Optional[Any]										=image_size
        a__	:					Dict										=patch_size
        a__	:					Tuple										=num_channels
        a__	:					Union[str, Any]										=embed_dim
        a__	:					Optional[Any]										=depths
        a__	:					List[str]										=len(lowerCAmelCase__							)
        a__	:					Any										=num_heads
        a__	:					Any										=window_size
        a__	:					str										=mlp_ratio
        a__	:					List[str]										=qkv_bias
        a__	:					Dict										=hidden_dropout_prob
        a__	:					List[str]										=attention_probs_dropout_prob
        a__	:					Dict										=drop_path_rate
        a__	:					Optional[Any]										=hidden_act
        a__	:					Union[str, Any]										=use_absolute_embeddings
        a__	:					Optional[Any]										=layer_norm_eps
        a__	:					List[Any]										=initializer_range
        a__	:					int										=upscale
        a__	:					Optional[int]										=img_range
        a__	:					Any										=resi_connection
        a__	:					Optional[Any]										=upsampler






