





'''simple docstring'''


import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding






class       UpperCamelCase__  (		__lowerCAmelCase     ):
	lowerCAmelCase__					:			List[Any]								=						["image_processor", "tokenizer"]
	lowerCAmelCase__					:			Union[str, Any]								=						"CLIPImageProcessor"
	lowerCAmelCase__					:			Optional[Any]								=						("CLIPTokenizer", "CLIPTokenizerFast")







	def __init__(				self			:   Dict , lowerCamelCase			:   List[Any]=None , lowerCamelCase			:   List[str]=None , **lowerCamelCase			:   Dict		):




				'''simple docstring'''
				a__     = None
				if "feature_extractor" in kwargs:
							warnings.warn(
							    "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"
							    " instead." , lowerCamelCase , )
							a__     = kwargs.pop("feature_extractor"		)

				a__     = image_processor if image_processor is not None else feature_extractor
				if image_processor is None:
							raise ValueError("You need to specify an `image_processor`."		)
				if tokenizer is None:
							raise ValueError("You need to specify a `tokenizer`."		)

				super().__init__(lowerCamelCase , lowerCamelCase		)







	def __call__(				self			:   Optional[int] , lowerCamelCase			:   Optional[int]=None , lowerCamelCase			:   str=None , lowerCamelCase			:   Dict=None , **lowerCamelCase			:   str		):




				'''simple docstring'''

				if text is None and images is None:
							raise ValueError("You have to specify either text or images. Both cannot be none."		)

				if text is not None:
							a__     = self.tokenizer(lowerCamelCase , return_tensors=lowerCamelCase , **lowerCamelCase		)

				if images is not None:
							a__     = self.image_processor(lowerCamelCase , return_tensors=lowerCamelCase , **lowerCamelCase		)

				if text is not None and images is not None:
							a__     = image_features.pixel_values
							return encoding
				elif text is not None:
							return encoding
				else:
							return BatchEncoding(data=dict(**lowerCamelCase		) , tensor_type=lowerCamelCase		)







	def 						__a   (				self			:   Dict , *lowerCamelCase			:   str , **lowerCamelCase			:   str		):




				'''simple docstring'''
				return self.tokenizer.batch_decode(*lowerCamelCase , **lowerCamelCase		)







	def 						__a   (				self			:   Tuple , *lowerCamelCase			:   List[Any] , **lowerCamelCase			:   List[str]		):




				'''simple docstring'''
				return self.tokenizer.decode(*lowerCamelCase , **lowerCamelCase		)







	@property
	def 						__a   (				self			:   List[str]		):




				'''simple docstring'''
				a__     = self.tokenizer.model_input_names
				a__     = self.image_processor.model_input_names
				return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names		)		)







	@property
	def 						__a   (				self			:   List[str]		):




				'''simple docstring'''
				warnings.warn(
				    "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead." , lowerCamelCase , )
				return self.image_processor_class







	@property
	def 						__a   (				self			:   Any		):




				'''simple docstring'''
				warnings.warn(
				    "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead." , lowerCamelCase , )
				return self.image_processor










'''simple docstring'''


import os
import time

import numpy as np
import onnxruntime as ort


lowerCAmelCase_   :   Optional[int]       =					"1"
lowerCAmelCase_   :   List[str]       =					"0"
lowerCAmelCase_   :   Tuple       =					"1"

lowerCAmelCase_   :   str       =					ort.SessionOptions()
lowerCAmelCase_   :   Tuple       =					ort.GraphOptimizationLevel.ORT_DISABLE_ALL
print("Create inference session...")
lowerCAmelCase_   :   Any       =					["TensorrtExecutionProvider", "CUDAExecutionProvider"]
lowerCAmelCase_   :   str       =					ort.InferenceSession("model.onnx", sess_options=sess_opt, providers=execution_provider)
lowerCAmelCase_   :   Tuple       =					ort.RunOptions()

lowerCAmelCase_   :   Optional[int]       =					128
lowerCAmelCase_   :   Union[str, Any]       =					1
lowerCAmelCase_   :   List[str]       =					np.ones((batch, sequence), dtype=np.intaa)
lowerCAmelCase_   :   Optional[Any]       =					np.ones((batch, sequence), dtype=np.intaa)
lowerCAmelCase_   :   str       =					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...")
lowerCAmelCase_   :   Tuple       =					time.time()
lowerCAmelCase_   :   int       =					2000
lowerCAmelCase_   :   Optional[Any]       =					{}
for iter in range(max_iters):
		lowerCAmelCase_   :   List[str]       =					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))



