


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


A	:		Any    =       logging.get_logger(__name__)



@dataclass
class 							A   (	SCREAMING_SNAKE_CASE__							):
					'''simple docstring'''






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

					def __init__(self   :						List[Any]				, **_UpperCAmelCase   :						Optional[int]		)						->       Union[str, Any]:




							"""simple docstring"""


							for deprecated_arg in self.deprecated_args:
									if deprecated_arg in kwargs:
											lowercase__					      =		deprecated_arg[3:]
											setattr(self				, A__				, not kwargs.pop(A__		)		)
											logger.warning(
											    f'''{deprecated_arg} is depreciated. Please use --no_{positive_arg} or'''
											    f''' {positive_arg}={kwargs[positive_arg]}'''		)

							lowercase__					      =		kwargs.pop("""torchscript"""				, self.torchscript		)
							lowercase__					      =		kwargs.pop("""torch_xla_tpu_print_metrics"""				, self.torch_xla_tpu_print_metrics		)
							lowercase__					      =		kwargs.pop("""fp16_opt_level"""				, self.fpaa_opt_level		)
							super().__init__(**A__		)

					A__      =			field(default=SCREAMING_SNAKE_CASE__			,  metadata={'''help''': '''Trace the models using torchscript'''}							)
					A__      =			field(default=SCREAMING_SNAKE_CASE__			,  metadata={'''help''': '''Print Xla/PyTorch tpu metrics'''}							)
					A__      =			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   lowerCamelCase__					(self   :						Any		)						->       str:




							"""simple docstring"""


							requires_backends(self				, ["""torch"""]		)
							logger.info("""PyTorch: setting up devices"""		)
							if not self.cuda:
									lowercase__					      =		torch.device("""cpu"""		)
									lowercase__					      =		0
							elif is_torch_tpu_available():
									lowercase__					      =		xm.xla_device()
									lowercase__					      =		0
							else:
									lowercase__					      =		torch.device("""cuda""" if torch.cuda.is_available() else """cpu"""		)
									lowercase__					      =		torch.cuda.device_count()
							return device, n_gpu

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




							"""simple docstring"""


							return is_torch_tpu_available() and self.tpu

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




							"""simple docstring"""


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

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




							"""simple docstring"""


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

					@property
					def   lowerCamelCase__					(self   :						Union[str, Any]		)						->       Dict:




							"""simple docstring"""


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


					@property
					def   lowerCamelCase__					(self   :						List[Any]		)						->       Tuple:




							"""simple docstring"""


							return self.n_gpu > 0






from collections import OrderedDict
from typing import Mapping

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


A	:		Optional[Any]    =       logging.get_logger(__name__)

A	:		Tuple    =       {
    'YituTech/conv-bert-base': 'https://huggingface.co/YituTech/conv-bert-base/resolve/main/config.json',
    'YituTech/conv-bert-medium-small': (
        'https://huggingface.co/YituTech/conv-bert-medium-small/resolve/main/config.json'
    ),
    'YituTech/conv-bert-small': 'https://huggingface.co/YituTech/conv-bert-small/resolve/main/config.json',
    # See all ConvBERT models at https://huggingface.co/models?filter=convbert
}



class 							A   (	UpperCAmelCase__							):
					'''simple docstring'''






					A__      =			'''convbert'''

					def __init__(self   :						str				, _UpperCAmelCase   :						Union[str, Any]=3_0522				, _UpperCAmelCase   :						Dict=768				, _UpperCAmelCase   :						Optional[int]=12				, _UpperCAmelCase   :						List[str]=12				, _UpperCAmelCase   :						str=3072				, _UpperCAmelCase   :						Tuple="gelu"				, _UpperCAmelCase   :						Optional[int]=0.1				, _UpperCAmelCase   :						int=0.1				, _UpperCAmelCase   :						str=512				, _UpperCAmelCase   :						Dict=2				, _UpperCAmelCase   :						int=0.02				, _UpperCAmelCase   :						Tuple=1E-1_2				, _UpperCAmelCase   :						Dict=1				, _UpperCAmelCase   :						Optional[Any]=0				, _UpperCAmelCase   :						List[str]=2				, _UpperCAmelCase   :						str=768				, _UpperCAmelCase   :						List[Any]=2				, _UpperCAmelCase   :						Optional[Any]=9				, _UpperCAmelCase   :						List[Any]=1				, _UpperCAmelCase   :						Union[str, Any]=None				, **_UpperCAmelCase   :						List[Any]				, )						->       List[str]:




							"""simple docstring"""


							super().__init__(
							    pad_token_id=_UpperCAmelCase				, bos_token_id=_UpperCAmelCase				, eos_token_id=_UpperCAmelCase				, **_UpperCAmelCase				, )

							lowercase__					      =		vocab_size
							lowercase__					      =		hidden_size
							lowercase__					      =		num_hidden_layers
							lowercase__					      =		num_attention_heads
							lowercase__					      =		intermediate_size
							lowercase__					      =		hidden_act
							lowercase__					      =		hidden_dropout_prob
							lowercase__					      =		attention_probs_dropout_prob
							lowercase__					      =		max_position_embeddings
							lowercase__					      =		type_vocab_size
							lowercase__					      =		initializer_range
							lowercase__					      =		layer_norm_eps
							lowercase__					      =		embedding_size
							lowercase__					      =		head_ratio
							lowercase__					      =		conv_kernel_size
							lowercase__					      =		num_groups
							lowercase__					      =		classifier_dropout






class 							A   (	UpperCAmelCase__							):
					'''simple docstring'''






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




							"""simple docstring"""


							if self.task == "multiple-choice":
									lowercase__					      =		{0: """batch""", 1: """choice""", 2: """sequence"""}
							else:
									lowercase__					      =		{0: """batch""", 1: """sequence"""}
							return OrderedDict(
							    [
							        ("""input_ids""", dynamic_axis),
							        ("""attention_mask""", dynamic_axis),
							        ("""token_type_ids""", dynamic_axis),
							    ]		)

