"""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__  :  str						     =	logging.get_logger(__name__)
@dataclass
class 				snake_case       ( __UpperCAmelCase				):




					"""simple docstring"""

					snake_case__				    = [
					    "no_inference",
					    "no_cuda",
					    "no_tpu",
					    "no_speed",
					    "no_memory",
					    "no_env_print",
					    "no_multi_process",
					]







					def __init__(				self   :	Union[str, Any]    ,**lowerCamelCase__   :	Optional[Any]			):
									for deprecated_arg in self.deprecated_args:
													if deprecated_arg in kwargs:
																	UpperCAmelCase__             =							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]}'''			)

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

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







					@property
					def 		__lowerCAmelCase						(				self   :	Tuple			):
									return is_torch_tpu_available() and self.tpu







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







					@property
					def 		__lowerCAmelCase						(				self   :	Dict			):
									requires_backends(self    ,['torch']			)
									return self._setup_devices[0]







					@property
					def 		__lowerCAmelCase						(				self   :	int			):
									requires_backends(self    ,['torch']			)
									return self._setup_devices[1]







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











import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_convbert import ConvBertTokenizer


__UpperCAmelCase								=						logging.get_logger(__name__)

__UpperCAmelCase								=						{'vocab_file': 'vocab.txt'}

__UpperCAmelCase								=						{
    'vocab_file': {
        'YituTech/conv-bert-base': 'https://huggingface.co/YituTech/conv-bert-base/resolve/main/vocab.txt',
        'YituTech/conv-bert-medium-small': (
            'https://huggingface.co/YituTech/conv-bert-medium-small/resolve/main/vocab.txt'
        ),
        'YituTech/conv-bert-small': 'https://huggingface.co/YituTech/conv-bert-small/resolve/main/vocab.txt',
    }
}

__UpperCAmelCase								=						{
    'YituTech/conv-bert-base': 512,
    'YituTech/conv-bert-medium-small': 512,
    'YituTech/conv-bert-small': 512,
}


__UpperCAmelCase								=						{
    'YituTech/conv-bert-base': {'do_lower_case': True},
    'YituTech/conv-bert-medium-small': {'do_lower_case': True},
    'YituTech/conv-bert-small': {'do_lower_case': True},
}



class   lowerCamelCase      (_snake_case			):







		'''simple docstring'''



		_snake_case    :    Optional[int]       						=  VOCAB_FILES_NAMES
		_snake_case    :    int       						=  PRETRAINED_VOCAB_FILES_MAP
		_snake_case    :    Dict       						=  PRETRAINED_INIT_CONFIGURATION
		_snake_case    :    List[str]       						=  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
		_snake_case    :    Any       						=  ConvBertTokenizer



		def __init__(							self				,		_UpperCamelCase=None				,		_UpperCamelCase=None				,		_UpperCamelCase=True				,		_UpperCamelCase="[UNK]"				,		_UpperCamelCase="[SEP]"				,		_UpperCamelCase="[PAD]"				,		_UpperCamelCase="[CLS]"				,		_UpperCamelCase="[MASK]"				,		_UpperCamelCase=True				,		_UpperCamelCase=None				,		**_UpperCamelCase				,		)	->							Dict:
							super().__init__(
							    _UpperCamelCase				,		tokenizer_file=_UpperCamelCase				,		do_lower_case=_UpperCamelCase				,		unk_token=_UpperCamelCase				,		sep_token=_UpperCamelCase				,		pad_token=_UpperCamelCase				,		cls_token=_UpperCamelCase				,		mask_token=_UpperCamelCase				,		tokenize_chinese_chars=_UpperCamelCase				,		strip_accents=_UpperCamelCase				,		**_UpperCamelCase				,		)

							UpperCAmelCase_    :      Optional[int]            =						json.loads(self.backend_tokenizer.normalizer.__getstate__()   )
							if (
							    normalizer_state.get('lowercase'				,		_UpperCamelCase   ) != do_lower_case
							    or normalizer_state.get('strip_accents'				,		_UpperCamelCase   ) != strip_accents
							    or normalizer_state.get('handle_chinese_chars'				,		_UpperCamelCase   ) != tokenize_chinese_chars
							):
												UpperCAmelCase_    :      Any            =						getattr(_UpperCamelCase				,		normalizer_state.pop('type'   )   )
												UpperCAmelCase_    :      str            =						do_lower_case
												UpperCAmelCase_    :      List[Any]            =						strip_accents
												UpperCAmelCase_    :      str            =						tokenize_chinese_chars
												UpperCAmelCase_    :      Tuple            =						normalizer_class(**_UpperCamelCase   )

							UpperCAmelCase_    :      Any            =						do_lower_case



		def 					__UpperCAmelCase			(							self				,		_UpperCamelCase				,		_UpperCamelCase=None   )	->							List[str]:
							UpperCAmelCase_    :      int            =						[self.cls_token_id] + token_ids_a + [self.sep_token_id]

							if token_ids_a:
												output += token_ids_a + [self.sep_token_id]

							return output



		def 					__UpperCAmelCase			(							self				,		_UpperCamelCase				,		_UpperCamelCase = None   )	->							List[int]:
							UpperCAmelCase_    :      Union[str, Any]            =						[self.sep_token_id]
							UpperCAmelCase_    :      int            =						[self.cls_token_id]
							if token_ids_a is None:
												return len(cls + token_ids_a + sep   ) * [0]
							return len(cls + token_ids_a + sep   ) * [0] + len(token_ids_a + sep   ) * [1]



		def 					__UpperCAmelCase			(							self				,		_UpperCamelCase				,		_UpperCamelCase = None   )	->							Tuple[str]:
							UpperCAmelCase_    :      Any            =						self._tokenizer.model.save(_UpperCamelCase				,		name=_UpperCamelCase   )
							return tuple(_UpperCamelCase   )






