






"""simple docstring"""







from collections import OrderedDict
from typing import Mapping

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


_lowerCAmelCase            =	logging.get_logger(__name__)

_lowerCAmelCase            =	{
    'xlm-mlm-en-2048': 'https://huggingface.co/xlm-mlm-en-2048/resolve/main/config.json',
    'xlm-mlm-ende-1024': 'https://huggingface.co/xlm-mlm-ende-1024/resolve/main/config.json',
    'xlm-mlm-enfr-1024': 'https://huggingface.co/xlm-mlm-enfr-1024/resolve/main/config.json',
    'xlm-mlm-enro-1024': 'https://huggingface.co/xlm-mlm-enro-1024/resolve/main/config.json',
    'xlm-mlm-tlm-xnli15-1024': 'https://huggingface.co/xlm-mlm-tlm-xnli15-1024/resolve/main/config.json',
    'xlm-mlm-xnli15-1024': 'https://huggingface.co/xlm-mlm-xnli15-1024/resolve/main/config.json',
    'xlm-clm-enfr-1024': 'https://huggingface.co/xlm-clm-enfr-1024/resolve/main/config.json',
    'xlm-clm-ende-1024': 'https://huggingface.co/xlm-clm-ende-1024/resolve/main/config.json',
    'xlm-mlm-17-1280': 'https://huggingface.co/xlm-mlm-17-1280/resolve/main/config.json',
    'xlm-mlm-100-1280': 'https://huggingface.co/xlm-mlm-100-1280/resolve/main/config.json',
}


class      UpperCamelCase		(__snake_case     ):
						_SCREAMING_SNAKE_CASE  : List[str]												=		"""xlm"""
						_SCREAMING_SNAKE_CASE  : str												=		{
						    """hidden_size""": """emb_dim""",
						    """num_attention_heads""": """n_heads""",
						    """num_hidden_layers""": """n_layers""",
						    """n_words""": """vocab_size""",  # For backward compatibility
						}






						def __init__(		self  :Any			, __magic_name__  :List[str]=30_145			, __magic_name__  :Optional[int]=2_048			, __magic_name__  :str=12			, __magic_name__  :int=16			, __magic_name__  :List[str]=0.1			, __magic_name__  :List[str]=0.1			, __magic_name__  :Any=True			, __magic_name__  :str=False			, __magic_name__  :str=False			, __magic_name__  :List[Any]=False			, __magic_name__  :Any=1			, __magic_name__  :List[Any]=True			, __magic_name__  :Optional[Any]=512			, __magic_name__  :Union[str, Any]=2_048**-0.5			, __magic_name__  :int=1E-12			, __magic_name__  :Union[str, Any]=0.02			, __magic_name__  :Optional[Any]=0			, __magic_name__  :List[Any]=1			, __magic_name__  :Any=2			, __magic_name__  :Optional[Any]=3			, __magic_name__  :List[Any]=5			, __magic_name__  :Union[str, Any]=True			, __magic_name__  :Optional[Any]="first"			, __magic_name__  :Union[str, Any]=True			, __magic_name__  :Any=None			, __magic_name__  :Dict=True			, __magic_name__  :Union[str, Any]=0.1			, __magic_name__  :Optional[Any]=5			, __magic_name__  :Tuple=5			, __magic_name__  :List[Any]=0			, __magic_name__  :Union[str, Any]=0			, __magic_name__  :List[Any]=2			, __magic_name__  :Tuple=0			, **__magic_name__  :str			, )      ->Dict:
										lowercase    :      str       = vocab_size
										lowercase    :      Dict       = emb_dim
										lowercase    :      int       = n_layers
										lowercase    :      Union[str, Any]       = n_heads
										lowercase    :      str       = dropout
										lowercase    :      str       = attention_dropout
										lowercase    :      int       = gelu_activation
										lowercase    :      int       = sinusoidal_embeddings
										lowercase    :      Optional[Any]       = causal
										lowercase    :      Optional[int]       = asm
										lowercase    :      int       = n_langs
										lowercase    :      Union[str, Any]       = use_lang_emb
										lowercase    :      List[str]       = layer_norm_eps
										lowercase    :      Optional[int]       = bos_index
										lowercase    :      Any       = eos_index
										lowercase    :      Tuple       = pad_index
										lowercase    :      List[str]       = unk_index
										lowercase    :      Union[str, Any]       = mask_index
										lowercase    :      Optional[Any]       = is_encoder
										lowercase    :      str       = max_position_embeddings
										lowercase    :      Dict       = embed_init_std
										lowercase    :      Optional[Any]       = init_std
										lowercase    :      List[Any]       = summary_type
										lowercase    :      Optional[int]       = summary_use_proj
										lowercase    :      Optional[Any]       = summary_activation
										lowercase    :      Optional[Any]       = summary_proj_to_labels
										lowercase    :      Dict       = summary_first_dropout
										lowercase    :      Any       = start_n_top
										lowercase    :      int       = end_n_top
										lowercase    :      List[Any]       = mask_token_id
										lowercase    :      Any       = lang_id

										if "n_words" in kwargs:
														lowercase    :      Union[str, Any]       = kwargs["""n_words"""]

										super().__init__(pad_token_id=__magic_name__			, bos_token_id=__magic_name__			, **__magic_name__				)


class      UpperCamelCase		(__snake_case     ):






						@property
						def      __snake_case      (		self  :Optional[int]				)      ->Mapping[str, Mapping[int, str]]:
										if self.task == "multiple-choice":
														lowercase    :      Union[str, Any]       = {0: """batch""", 1: """choice""", 2: """sequence"""}
										else:
														lowercase    :      Optional[int]       = {0: """batch""", 1: """sequence"""}
										return OrderedDict(
										    [
										        ("""input_ids""", dynamic_axis),
										        ("""attention_mask""", dynamic_axis),
										        ("""token_type_ids""", dynamic_axis),
										    ]				)








"""simple docstring"""







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


_lowerCAmelCase            =	logging.get_logger(__name__)


@dataclass
class      UpperCamelCase		(__snake_case     ):
						_SCREAMING_SNAKE_CASE  : str												=		[
						    """no_inference""",
						    """no_cuda""",
						    """no_tpu""",
						    """no_speed""",
						    """no_memory""",
						    """no_env_print""",
						    """no_multi_process""",
						]






						def __init__(		self  :Union[str, Any]			, **__magic_name__  :int				)      ->Any:
										for deprecated_arg in self.deprecated_args:
														if deprecated_arg in kwargs:
																		lowercase    :      int       = deprecated_arg[3:]
																		setattr(self			, __magic_name__			, not kwargs.pop(__magic_name__				)				)
																		logger.warning(
																		    f"""{deprecated_arg} is depreciated. Please use --no_{positive_arg} or"""
																		    f""" {positive_arg}={kwargs[positive_arg]}"""				)

										lowercase    :      List[str]       = kwargs.pop("""torchscript"""			, self.torchscript				)
										lowercase    :      Any       = kwargs.pop("""torch_xla_tpu_print_metrics"""			, self.torch_xla_tpu_print_metrics				)
										lowercase    :      Union[str, Any]       = kwargs.pop("""fp16_opt_level"""			, self.fpaa_opt_level				)
										super().__init__(**__magic_name__				)

						_SCREAMING_SNAKE_CASE  : bool												=		field(default=__snake_case						,						metadata={"""help""": """Trace the models using torchscript"""}     )
						_SCREAMING_SNAKE_CASE  : bool												=		field(default=__snake_case						,						metadata={"""help""": """Print Xla/PyTorch tpu metrics"""}     )
						_SCREAMING_SNAKE_CASE  : 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      __snake_case      (		self  :Optional[int]				)      ->Tuple["torch.device", int]:
										requires_backends(self			, ["""torch"""]				)
										logger.info("""PyTorch: setting up devices"""				)
										if not self.cuda:
														lowercase    :      Optional[Any]       = torch.device("""cpu"""				)
														lowercase    :      int       = 0
										elif is_torch_tpu_available():
														lowercase    :      Any       = xm.xla_device()
														lowercase    :      List[str]       = 0
										else:
														lowercase    :      int       = torch.device("""cuda""" if torch.cuda.is_available() else """cpu"""				)
														lowercase    :      Any       = torch.cuda.device_count()
										return device, n_gpu






						@property
						def      __snake_case      (		self  :Optional[int]				)      ->Union[str, Any]:
										return is_torch_tpu_available() and self.tpu






						@property
						def      __snake_case      (		self  :Optional[int]				)      ->int:
										requires_backends(self			, ["""torch"""]				)
										# TODO(PVP): currently only single GPU is supported
										return torch.cuda.current_device()






						@property
						def      __snake_case      (		self  :Optional[int]				)      ->"torch.device":
										requires_backends(self			, ["""torch"""]				)
										return self._setup_devices[0]






						@property
						def      __snake_case      (		self  :Optional[Any]				)      ->str:
										requires_backends(self			, ["""torch"""]				)
										return self._setup_devices[1]






						@property
						def      __snake_case      (		self  :int				)      ->List[str]:
										return self.n_gpu > 0
