



"""simple docstring"""






import os

import numpy
import onnx






def      snake_case__   (		__lowerCamelCase				:    List[str]							,		__lowerCamelCase				:    str	):
			"""simple docstring"""
			lowerCamelCase__		:		Union[str, Any]			=a.name
			lowerCamelCase__		:		Optional[Any]			=b.name

			lowerCamelCase__		:		Any			=""
			lowerCamelCase__		:		str			=""

			lowerCamelCase__		:		str			=a == b

			lowerCamelCase__		:		Optional[int]			=name_a
			lowerCamelCase__		:		int			=name_b

			return res






def      snake_case__   (		__lowerCamelCase				:    Tuple							,		__lowerCamelCase				:    Optional[Any]							,		__lowerCamelCase				:    List[str]	):
			"""simple docstring"""
			for i, input_name in enumerate(node_proto.input	):
						if input_name == name:
									node_proto.input.insert(__lowerCamelCase							,		__lowerCamelCase	)
									node_proto.input.pop(i + 1	)

			if node_proto.op_type == "If":
						_graph_replace_input_with(node_proto.attribute[0].g							,		__lowerCamelCase							,		__lowerCamelCase	)
						_graph_replace_input_with(node_proto.attribute[1].g							,		__lowerCamelCase							,		__lowerCamelCase	)
			if node_proto.op_type == "Loop":
						_graph_replace_input_with(node_proto.attribute[0].g							,		__lowerCamelCase							,		__lowerCamelCase	)






def      snake_case__   (		__lowerCamelCase				:    List[str]							,		__lowerCamelCase				:    Optional[int]							,		__lowerCamelCase				:    List[Any]	):
			"""simple docstring"""
			for n in graph_proto.node:
						_node_replace_input_with(__lowerCamelCase							,		__lowerCamelCase							,		__lowerCamelCase	)






def      snake_case__   (		__lowerCamelCase				:    str							,		__lowerCamelCase				:    str							,		__lowerCamelCase				:    List[Any]	):
			"""simple docstring"""
			lowerCamelCase__		:		Optional[int]			=list(model.graph.initializer	)
			lowerCamelCase__		:		Optional[Any]			=list(model_without_ext.graph.initializer	)
			for i, ref_i in ind_to_replace:
						assert inits_with_data[i].name == inits[i].name
						assert inits_with_data[ref_i].name == inits[ref_i].name
						assert i > ref_i

						lowerCamelCase__		:		Union[str, Any]			=inits[i].name
						lowerCamelCase__		:		Any			=inits[ref_i].name

						model_without_ext.graph.initializer.remove(inits[i]	)

						# for n in model.graph.node:
						_graph_replace_input_with(model_without_ext.graph							,		__lowerCamelCase							,		__lowerCamelCase	)






def      snake_case__   (		__lowerCamelCase				:    List[Any]	):
			"""simple docstring"""
			lowerCamelCase__		:		Union[str, Any]			=os.path.dirname(__lowerCamelCase	)
			lowerCamelCase__		:		Union[str, Any]			=os.path.basename(__lowerCamelCase	)

			lowerCamelCase__		:		Union[str, Any]			=onnx.load(os.path.join(__lowerCamelCase							,		__lowerCamelCase	)	)

			lowerCamelCase__		:		Optional[Any]			=list(model.graph.initializer	)

			lowerCamelCase__		:		Any			=set()
			lowerCamelCase__		:		Optional[Any]			={}
			lowerCamelCase__		:		Tuple			=[]

			lowerCamelCase__		:		str			=0

			for i in range(len(__lowerCamelCase	)	):
						if i in dup_set:
									continue

						for j in range(i + 1							,		len(__lowerCamelCase	)	):
									if j in dup_set:
												continue
									if _is_equal_tensor_proto(inits[i]							,		inits[j]	):
												dup_set.add(__lowerCamelCase	)
												dup_set.add(__lowerCamelCase	)

												lowerCamelCase__		:		List[Any]			=inits[j].data_type
												lowerCamelCase__		:		str			=numpy.prod(inits[j].dims	)
												if dtype == 1:
															mem_size *= 4
												elif dtype == 6:
															mem_size *= 4
												elif dtype == 7 or dtype == 11:
															mem_size *= 8
												else:
															print('''unexpected data type: '''							,		__lowerCamelCase	)
												total_reduced_size += mem_size

												lowerCamelCase__		:		Optional[int]			=inits[i].name
												lowerCamelCase__		:		Optional[int]			=inits[j].name

												if name_i in dup_map:
															dup_map[name_i].append(__lowerCamelCase	)
												else:
															lowerCamelCase__		:		Any			=[name_j]
												ind_to_replace.append((j, i)	)

			print('''total reduced size: '''							,		total_reduced_size / 1024 / 1024 / 1024							,		'''GB'''	)

			lowerCamelCase__		:		Tuple			=sorted(__lowerCamelCase	)
			_remove_dup_initializers_from_model(__lowerCamelCase							,		__lowerCamelCase							,		__lowerCamelCase	)

			lowerCamelCase__		:		int			="optimized_" + model_file_name
			lowerCamelCase__		:		str			=os.path.join(__lowerCamelCase							,		__lowerCamelCase	)
			onnx.save(__lowerCamelCase							,		__lowerCamelCase	)

			return new_model






import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from .tokenization_lxmert import LxmertTokenizer


__lowerCamelCase							=       {"""vocab_file""": """vocab.txt""", """tokenizer_file""": """tokenizer.json"""}

__lowerCamelCase							=       {
    """vocab_file""": {
        """unc-nlp/lxmert-base-uncased""": """https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/vocab.txt""",
    },
    """tokenizer_file""": {
        """unc-nlp/lxmert-base-uncased""": (
            """https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/tokenizer.json"""
        ),
    },
}

__lowerCamelCase							=       {
    """unc-nlp/lxmert-base-uncased""": 5_12,
}

__lowerCamelCase							=       {
    """unc-nlp/lxmert-base-uncased""": {"""do_lower_case""": True},
}






class   UpperCAmelCase		(						A_ ):
   A__					:		Any						     =     VOCAB_FILES_NAMES
   A__					:		Optional[int]						     =     PRETRAINED_VOCAB_FILES_MAP
   A__					:		Tuple						     =     PRETRAINED_INIT_CONFIGURATION
   A__					:		Tuple						     =     PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   A__					:		List[Any]						     =     LxmertTokenizer



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


          '''simple docstring'''


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

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

          snake_case       :   Optional[Any]							=      do_lower_case



   def 				_SCREAMING_SNAKE_CASE   (self		:					Union[str, Any]    ,						snake_case__		:					Optional[Any]    ,						snake_case__		:					Dict=None )		->	Any:


          '''simple docstring'''


          snake_case       :   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 				_SCREAMING_SNAKE_CASE   (self		:					Optional[int]    ,						snake_case__		:					List[int]    ,						snake_case__		:					Optional[List[int]] = None )		->	List[int]:


          '''simple docstring'''


          snake_case       :   Optional[Any]							=      [self.sep_token_id]
          snake_case       :   Optional[Any]							=      [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 				_SCREAMING_SNAKE_CASE   (self		:					Any    ,						snake_case__		:					str    ,						snake_case__		:					Optional[str] = None )		->	Tuple[str]:


          '''simple docstring'''


          snake_case       :   List[Any]							=      self._tokenizer.model.save(snake_case__    ,						name=snake_case__ )
          return tuple(snake_case__ )





