


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


snake_case__      =						logging.get_logger(__name__)

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

snake_case__      =						{
    '''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''',
    }
}

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


snake_case__      =						{
    '''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_ (       __lowerCAmelCase):
						lowerCamelCase_         =     VOCAB_FILES_NAMES
						lowerCamelCase_         =     PRETRAINED_VOCAB_FILES_MAP
						lowerCamelCase_         =     PRETRAINED_INIT_CONFIGURATION
						lowerCamelCase_         =     PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						lowerCamelCase_         =     ConvBertTokenizer




						def __init__(	self						:   Optional[Any]   ,     __A						:   str=None   ,     __A						:   List[Any]=None   ,     __A						:   str=True   ,     __A						:   Union[str, Any]="[UNK]"   ,     __A						:   Dict="[SEP]"   ,     __A						:   Union[str, Any]="[PAD]"   ,     __A						:   List[str]="[CLS]"   ,     __A						:   Tuple="[MASK]"   ,     __A						:   Union[str, Any]=True   ,     __A						:   Dict=None   ,     **__A						:   Tuple   ,     )      ->Dict:






									"""simple docstring"""






									super().__init__(
									    lowerCAmelCase_   ,     tokenizer_file=lowerCAmelCase_   ,     do_lower_case=lowerCAmelCase_   ,     unk_token=lowerCAmelCase_   ,     sep_token=lowerCAmelCase_   ,     pad_token=lowerCAmelCase_   ,     cls_token=lowerCAmelCase_   ,     mask_token=lowerCAmelCase_   ,     tokenize_chinese_chars=lowerCAmelCase_   ,     strip_accents=lowerCAmelCase_   ,     **lowerCAmelCase_   ,     )

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

									a__ :Optional[Any]						  =    do_lower_case




						def  _snake_case					(	self						:   Tuple   ,     __A						:   Optional[int]   ,     __A						:   Dict=None						)      ->List[Any]:






									"""simple docstring"""






									a__ :Optional[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  _snake_case					(	self						:   Optional[Any]   ,     __A						:   str   ,     __A						:   Tuple = None						)      ->List[int]:






									"""simple docstring"""






									a__ :List[str]						  =    [self.sep_token_id]
									a__ :Optional[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  _snake_case					(	self						:   Tuple   ,     __A						:   str   ,     __A						:   Dict = None						)      ->Tuple[str]:






									"""simple docstring"""






									a__ :List[str]						  =    self._tokenizer.model.save(lowerCAmelCase_   ,     name=lowerCAmelCase_						)
									return tuple(lowerCAmelCase_						)






import os
import time

import numpy as np
import onnxruntime as ort


snake_case__			 =						'''1'''
snake_case__			 =						'''0'''
snake_case__			 =						'''1'''

snake_case__			 =						ort.SessionOptions()
snake_case__			 =						ort.GraphOptimizationLevel.ORT_DISABLE_ALL
print('''Create inference session...''')
snake_case__			 =						['''TensorrtExecutionProvider''', '''CUDAExecutionProvider''']
snake_case__			 =						ort.InferenceSession('''model.onnx''', sess_options=sess_opt, providers=execution_provider)
snake_case__			 =						ort.RunOptions()

snake_case__			 =						128
snake_case__			 =						1
snake_case__			 =						np.ones((batch, sequence), dtype=np.intaa)
snake_case__			 =						np.ones((batch, sequence), dtype=np.intaa)
snake_case__			 =						np.ones((batch, sequence), dtype=np.intaa)

print('''Warm up phase...''')
sess.run(
    None,
    {
        sess.get_inputs()[0].name: input_ids,
        sess.get_inputs()[1].name: attention_mask,
        sess.get_inputs()[2].name: token_type_ids,
    },
    run_options=run_opt,
)

print('''Start inference...''')
snake_case__			 =						time.time()
snake_case__			 =						2000
snake_case__			 =						{}
for iter in range(max_iters):
		snake_case__			 =						sess.run(
		    None,
		    {
		        sess.get_inputs()[0].name: input_ids,
		        sess.get_inputs()[1].name: attention_mask,
		        sess.get_inputs()[2].name: token_type_ids,
		    },
		    run_options=run_opt,
		)
print('''Average Inference Time = {:.3f} ms'''.format((time.time() - start_time) * 1000 / max_iters))


