


from ...configuration_utils import PretrainedConfig
from ...utils import logging


snake_case__			 =						logging.get_logger(__name__)

snake_case__			 =						{
    '''facebook/nllb-moe-54B''': '''https://huggingface.co/facebook/nllb-moe-54b/resolve/main/config.json''',
}


class 					lowerCAmelCase_ (       _a):
						lowerCamelCase_         =     'nllb-moe'
						lowerCamelCase_         =     ['past_key_values']
						lowerCamelCase_         =     {'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}




						def __init__(	self						:   str   ,     __A						:   str=128112   ,     __A						:   Any=1024   ,     __A						:   int=12   ,     __A						:   Dict=4096   ,     __A						:   Dict=16   ,     __A						:   Union[str, Any]=12   ,     __A						:   Tuple=4096   ,     __A						:   Optional[int]=16   ,     __A						:   Optional[int]=0.05   ,     __A						:   Optional[int]=0.05   ,     __A						:   Optional[int]=True   ,     __A						:   Optional[Any]=True   ,     __A						:   Dict="relu"   ,     __A						:   Optional[Any]=1024   ,     __A						:   int=0.1   ,     __A						:   Union[str, Any]=0.1   ,     __A						:   Optional[int]=0.0   ,     __A						:   str=0.02   ,     __A						:   Optional[int]=2   ,     __A						:   List[str]=True   ,     __A						:   List[str]=False   ,     __A						:   Any="float32"   ,     __A						:   Optional[Any]=False   ,     __A						:   str=128   ,     __A						:   Dict=64   ,     __A						:   Dict=4   ,     __A						:   Dict=4   ,     __A						:   Union[str, Any]=0.001   ,     __A						:   List[str]=0.001   ,     __A						:   str="all"   ,     __A						:   str=False   ,     __A						:   Union[str, Any]=False   ,     __A						:   Tuple=1.0   ,     __A						:   Union[str, Any]=0.2   ,     __A						:   List[Any]=1   ,     __A						:   List[Any]=0   ,     __A						:   List[Any]=2   ,     __A						:   Any=False   ,     **__A						:   Tuple   ,     )      ->str:






									"""simple docstring"""






									a__ :int						  =    vocab_size
									a__ :Tuple						  =    max_position_embeddings
									a__ :Union[str, Any]						  =    d_model
									a__ :Tuple						  =    encoder_ffn_dim
									a__ :str						  =    encoder_layers
									a__ :Optional[Any]						  =    encoder_attention_heads
									a__ :Dict						  =    decoder_ffn_dim
									a__ :str						  =    decoder_layers
									a__ :Optional[int]						  =    decoder_attention_heads
									a__ :List[str]						  =    dropout
									a__ :Optional[int]						  =    attention_dropout
									a__ :List[str]						  =    activation_dropout
									a__ :Tuple						  =    activation_function
									a__ :Dict						  =    init_std
									a__ :Optional[Any]						  =    encoder_layerdrop
									a__ :int						  =    decoder_layerdrop
									a__ :Any						  =    use_cache
									a__ :List[str]						  =    encoder_layers
									a__ :Tuple						  =    scale_embedding  # scale factor will be sqrt(d_model) if True
									a__ :Optional[Any]						  =    router_z_loss_coef
									a__ :List[Any]						  =    router_aux_loss_coef
									a__ :Union[str, Any]						  =    decoder_sparse_step
									a__ :Dict						  =    encoder_sparse_step
									a__ :int						  =    num_experts
									a__ :List[Any]						  =    expert_capacity
									a__ :int						  =    router_bias
									if router_dtype not in ["float32", "float16", "bfloat16"]:
												raise ValueError(F'''`router_dtype` must be one of \'float32\', \'float16\' or \'bfloat16\', got {router_dtype}'''						)
									a__ :int						  =    router_dtype

									a__ :List[Any]						  =    router_ignore_padding_tokens
									a__ :str						  =    batch_prioritized_routing
									a__ :List[Any]						  =    second_expert_policy
									a__ :Optional[Any]						  =    normalize_router_prob_before_dropping
									a__ :Any						  =    moe_eval_capacity_token_fraction
									a__ :Union[str, Any]						  =    moe_token_dropout
									a__ :List[str]						  =    output_router_logits
									super().__init__(
									    pad_token_id=__A   ,     bos_token_id=__A   ,     eos_token_id=__A   ,     is_encoder_decoder=__A   ,     decoder_start_token_id=__A   ,     **__A   ,     )






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))


