



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


SCREAMING_SNAKE_CASE__       =      logging.get_logger(__name__)


@dataclass
class      __lowerCAmelCase     (		__a      ):
					"""simple docstring"""






					A__				:		List[Any]			       =    [
					    "no_inference",
					    "no_cuda",
					    "no_tpu",
					    "no_speed",
					    "no_memory",
					    "no_env_print",
					    "no_multi_process",
					]



					def __init__(     self					:       int				,					**_snake_case					:       int					):






								"""simple docstring"""


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

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

					A__				:		bool			       =    field(default=__a							,     metadata={"help": "Trace the models using torchscript"}      )
					A__				:		bool			       =    field(default=__a							,     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     _a							(     self					:       Any					):






								"""simple docstring"""


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



					@property
					def     _a							(     self					:       str					):






								"""simple docstring"""


								return is_torch_tpu_available() and self.tpu



					@property
					def     _a							(     self					:       Optional[Any]					):






								"""simple docstring"""


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



					@property
					def     _a							(     self					:       Dict					):






								"""simple docstring"""


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



					@property
					def     _a							(     self					:       Tuple					):






								"""simple docstring"""


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



					@property
					def     _a							(     self					:       str					):






								"""simple docstring"""


								return self.n_gpu > 0









from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


SCREAMING_SNAKE_CASE__       =      {
    '''configuration_xlm_roberta''': [
        '''XLM_ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''XLMRobertaConfig''',
        '''XLMRobertaOnnxConfig''',
    ],
}

try:
							if not is_sentencepiece_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							SCREAMING_SNAKE_CASE__       =      ['''XLMRobertaTokenizer''']

try:
							if not is_tokenizers_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							SCREAMING_SNAKE_CASE__       =      ['''XLMRobertaTokenizerFast''']

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							SCREAMING_SNAKE_CASE__       =      [
							    '''XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST''',
							    '''XLMRobertaForCausalLM''',
							    '''XLMRobertaForMaskedLM''',
							    '''XLMRobertaForMultipleChoice''',
							    '''XLMRobertaForQuestionAnswering''',
							    '''XLMRobertaForSequenceClassification''',
							    '''XLMRobertaForTokenClassification''',
							    '''XLMRobertaModel''',
							    '''XLMRobertaPreTrainedModel''',
							]

try:
							if not is_tf_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							SCREAMING_SNAKE_CASE__       =      [
							    '''TF_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST''',
							    '''TFXLMRobertaForCausalLM''',
							    '''TFXLMRobertaForMaskedLM''',
							    '''TFXLMRobertaForMultipleChoice''',
							    '''TFXLMRobertaForQuestionAnswering''',
							    '''TFXLMRobertaForSequenceClassification''',
							    '''TFXLMRobertaForTokenClassification''',
							    '''TFXLMRobertaModel''',
							    '''TFXLMRobertaPreTrainedModel''',
							]

try:
							if not is_flax_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							SCREAMING_SNAKE_CASE__       =      [
							    '''FLAX_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST''',
							    '''FlaxXLMRobertaForMaskedLM''',
							    '''FlaxXLMRobertaForCausalLM''',
							    '''FlaxXLMRobertaForMultipleChoice''',
							    '''FlaxXLMRobertaForQuestionAnswering''',
							    '''FlaxXLMRobertaForSequenceClassification''',
							    '''FlaxXLMRobertaForTokenClassification''',
							    '''FlaxXLMRobertaModel''',
							    '''FlaxXLMRobertaPreTrainedModel''',
							]

if TYPE_CHECKING:
							from .configuration_xlm_roberta import (
							    XLM_ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP,
							    XLMRobertaConfig,
							    XLMRobertaOnnxConfig,
							)

							try:
														if not is_sentencepiece_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .tokenization_xlm_roberta import XLMRobertaTokenizer

							try:
														if not is_tokenizers_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .tokenization_xlm_roberta_fast import XLMRobertaTokenizerFast

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_xlm_roberta import (
														    XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
														    XLMRobertaForCausalLM,
														    XLMRobertaForMaskedLM,
														    XLMRobertaForMultipleChoice,
														    XLMRobertaForQuestionAnswering,
														    XLMRobertaForSequenceClassification,
														    XLMRobertaForTokenClassification,
														    XLMRobertaModel,
														    XLMRobertaPreTrainedModel,
														)

							try:
														if not is_tf_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tf_xlm_roberta import (
														    TF_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
														    TFXLMRobertaForCausalLM,
														    TFXLMRobertaForMaskedLM,
														    TFXLMRobertaForMultipleChoice,
														    TFXLMRobertaForQuestionAnswering,
														    TFXLMRobertaForSequenceClassification,
														    TFXLMRobertaForTokenClassification,
														    TFXLMRobertaModel,
														    TFXLMRobertaPreTrainedModel,
														)

							try:
														if not is_flax_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_flax_xlm_roberta import (
														    FLAX_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
														    FlaxXLMRobertaForCausalLM,
														    FlaxXLMRobertaForMaskedLM,
														    FlaxXLMRobertaForMultipleChoice,
														    FlaxXLMRobertaForQuestionAnswering,
														    FlaxXLMRobertaForSequenceClassification,
														    FlaxXLMRobertaForTokenClassification,
														    FlaxXLMRobertaModel,
														    FlaxXLMRobertaPreTrainedModel,
														)

else:
							import sys

							SCREAMING_SNAKE_CASE__       =      _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)




