


import os
import time

import numpy as np
import onnxruntime as ort


lowerCAmelCase__  :Tuple             =							'''1'''
lowerCAmelCase__  :Any             =							'''0'''
lowerCAmelCase__  :int             =							'''1'''

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

lowerCAmelCase__  :List[Any]             =							1_2_8
lowerCAmelCase__  :Tuple             =							1
lowerCAmelCase__  :Optional[Any]             =							np.ones((batch, sequence), dtype=np.intaa)
lowerCAmelCase__  :Any             =							np.ones((batch, sequence), dtype=np.intaa)
lowerCAmelCase__  :Optional[int]             =							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__  :Optional[Any]             =							time.time()
lowerCAmelCase__  :str             =							2_0_0_0
lowerCAmelCase__  :int             =							{}
for iter in range(max_iters):
		lowerCAmelCase__  :Optional[Any]             =							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) * 1_0_0_0 / max_iters))




from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCAmelCase__  :List[str]             =							{
    '''configuration_x_clip''': [
        '''XCLIP_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''XCLIPConfig''',
        '''XCLIPTextConfig''',
        '''XCLIPVisionConfig''',
    ],
    '''processing_x_clip''': ['''XCLIPProcessor'''],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowerCAmelCase__  :Any             =							[
		    '''XCLIP_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''XCLIPModel''',
		    '''XCLIPPreTrainedModel''',
		    '''XCLIPTextModel''',
		    '''XCLIPVisionModel''',
		]

if TYPE_CHECKING:
		from .configuration_x_clip import (
		    XCLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
		    XCLIPConfig,
		    XCLIPTextConfig,
		    XCLIPVisionConfig,
		)
		from .processing_x_clip import XCLIPProcessor

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_x_clip import (
				    XCLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
				    XCLIPModel,
				    XCLIPPreTrainedModel,
				    XCLIPTextModel,
				    XCLIPVisionModel,
				)

else:
		import sys

		lowerCAmelCase__  :str             =							_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
