+
    9i3                        ^ RI t ^ RIt^ RIt^ RIt^ RIHt  RR ltR tR tR t	R t
RR ltR	 tR
 tR t]R8X  d   ]! 4       t]! R]4       ^ RIHt ]! ]P(                  4       ]P*                  '       g#   ]P,                  '       g   Q R4       h]! ]4      tM]P*                  t^ RIHt ]! ]]4      t] F  t]! ]4       K  	  R# R# )    N)TensorProtoc           	      `   \         P                  ! 4       pVP                  R RR\        RR7       VP                  RRR\        RR7       VP                  RR	R\        ^R
R7       VP                  RRR\        ^ RR7       VP                  RR\        ^RR7       VP                  RR\        ^RR7       VP                  RR\        RRR7       VP                  RR\
        RRR7       VP                  RR\        R9RR7       VP                  RR\        RRR7       VP                  RR\        RRR7       VP                  R R\        RR!R7       VP                  R"RR#. R:OR$R%7       VP                  R&R'RR(R)R*7       VP                  RR+7       VP                  R,R\        R-R.R7       VP                  R/RR(R0R*7       VP                  RR17       VP                  R2RR(R3R*7       VP                  RR47       VP                  R5R6RR(R77       VP                  RR87       VP                  V 4      # );z-iz--inputFz2Set the input file for reading the profile results)requiredtypehelpz-mz--modelzIonnx model path to run profiling. Required when --input is not specified.z-bz--batch_sizezbatch size of input)r   r   defaultr   z-sz--sequence_lengthzsequence length of inputz--past_sequence_lengthzpast sequence length for gpt2z--global_lengthz&number of global tokens for longformerz	--samplesi  z\number of samples to test. Set it large enough to reduce the variance of performance result.z--thresholdg{Gz?zfThreshold of run time ratio among all nodes. Nodes with larger ratio will show in top expensive nodes.z--thread_numznumber of threads to usez--input_ids_nameNz"input name for input IDs, for bertz--segment_ids_namez$input name for segment IDs, for bertz--input_mask_namez'input name for attention mask, for bertz--dummy_inputsr   zEType of model inputs. The default will create dummy inputs with ones.)r   r   choicesr   z-gz	--use_gpu
store_truezuse GPU)r   actionr   )use_gpuz
--providercudazExecution provider to usez--basic_optimizationz_Enable only basic graph optimizations. By default, all optimizations are enabled in OnnxRuntime)basic_optimizationz--kernel_time_onlyz.Only include the kernel time and no fence time)kernel_time_onlyz-vz	--verbose)r   r   )verbose)bertgpt2
longformerr   )argparseArgumentParseradd_argumentstrintfloatset_defaults
parse_args)argvparsers   & _/var/www/html/photoedit/myenv/lib/python3.14/site-packages/onnxruntime/transformers/profiler.pyparse_argumentsr       s   $$&F
A   X   "   '    ,   5   k   u   '   1   3   6   9T   kE,U^_
&
(   n	   51
=	   /
kE,O
&T""    c           	          ^ RI Hp V! V VVV'       * VRR7      pV F  pVP                  RV4      p	K  	  VP                  4       p
V
# )r   )create_onnxruntime_sessionT)enable_all_optimizationnum_threadsenable_profilingN)benchmark_helperr#   runend_profiling)onnx_model_pathr   providerr   
thread_num
all_inputsr#   sessioninputs_profile_files   &&&&&&     r   run_profiler2      sV    ;($6 6G KKf%  ((*Lr!   c                     \        V P                  R 4      4      \        8X  d   \        W P                  R 4      4      # R# )valueN)r   
WhichOneofr   getattr)dims   &r   get_dim_from_type_protor8      s2    489P4QUX4X73w/0b^bbr!   c                 ~    V P                   P                  P                   Uu. uF  p\        V4      NK  	  up# u upi N)tensor_typeshaper7   r8   )
type_protods   & r   get_shape_from_type_protor?      s4    0:0F0F0L0L0P0PQ0P1#A&0PQQQs   :c                \   / pV P                  4        EFv  p\        VP                  4      p. p\        V4       F.  w  r\	        V	\
        4      '       g   K  VP                  V4       K0  	  \        V4      ^8  d    R# \        V4      ^ 8  d   WV^ ,          &   \        V4      ^8  d   W&V^,          &   VP                  P                  P                  p
V
\        P                  \        P                  \        P                  39   g   Q hV
\        P                  8X  d   \        P                  M4V
\        P                  8X  d   \        P                   M\        P"                  p\        P$                  ! WkR7      pWVP&                  &   EKy  	  \)        V4       Uu. uF  qNK  	  ppV# u upi )zCreate dummy inputs for ONNX model.

Args:
    onnx_model (OnnxModel): ONNX model
    batch_size (int): batch size
    sequence_length (int): sequence length
    samples (int): number of samples

Returns:
    List[Dict]: list of inputs
Ndtype)'get_graph_inputs_excluding_initializersr?   r   	enumerate
isinstancer   appendlenr;   	elem_typer   FLOATINT32INT64numpyfloat32int64int32onesnamerange)
onnx_model
batch_sizesequence_lengthsamplesdummy_inputsgraph_inputr<   symbol_dimsir7   rH   	data_typedatar0   r-   s   &&&&           r   create_dummy_inputsr]      s[    L!IIK)+*:*:;&FA#s##""1% '
 {a{a$.+a.!{a$3+a.!$$00::	[..0A0A;CTCTUUUU K--- MM!*k.?.?!?%++U[[ 	
 zz%1)-[%%&/ L2 ).g71,J7 8s   
F)c                P    ^ RI HpHp V! WWV4      w  rpV! VVV^{RV	V
VRR7	      pV# )a  Create dummy inputs for BERT model.

Args:
    onnx_model (OnnxModel): ONNX model
    batch_size (int): batch size
    sequence_length (int): sequence length
    samples (int): number of samples
    input_ids_name (str, optional): Name of graph input for input IDs. Defaults to None.
    segment_ids_name (str, optional): Name of graph input for segment IDs. Defaults to None.
    input_mask_name (str, optional): Name of graph input for attention mask. Defaults to None.

Returns:
    List[Dict]: list of inputs
)find_bert_inputsgenerate_test_dataF)
test_casesseedr   	input_idssegment_ids
input_maskrandom_mask_length)bert_test_datar_   r`   )rS   rT   rU   rV   input_ids_namesegment_ids_nameinput_mask_namer_   r`   rc   rd   re   r-   s   &&&&&&&      r   create_bert_inputsrk      sG    . D)9*Vf)x&IJ# 
J r!   c           	         RVRVRVRW#,           /p/ pV P                  4        EF8  p\        VP                  4      p\        V4       F;  w  r\	        V
\
        4      '       g   K  W9  d   \        RV
 24      hWZ,          W&   K=  	  VP                  P                  P                  pV\        P                  \        P                  \        P                  39   g   Q hV\        P                  8X  d   \        P                  M4V\        P                  8X  d   \        P                  M\        P                   p\        P"                  ! WR7      pWVP$                  &   EK;  	  \'        V4       Uu. uF  qNK  	  ppV# u upi )a  Create dummy inputs for GPT-2 model.

Args:
    onnx_model (OnnxModel): ONNX model
    batch_size (int): batch size
    sequence_length (int): sequence length
    past_sequence_length (int): past sequence length
    samples (int): number of samples

Raises:
    RuntimeError: symbolic is not supported. Use the tool convert_to_onnx.py to export ONNX model instead.

Returns:
    List[Dict]: list of inputs
rT   seq_lenpast_seq_lentotal_seq_lensymbol is not supported: rA   )rC   r?   r   rD   rE   r   RuntimeErrorr;   rH   r   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   )rS   rT   rU   past_sequence_lengthrV   symbolsrW   rX   r<   rZ   r7   rH   r[   r\   r0   r-   s   &&&&&           r   create_gpt2_inputsrt     sI   $ 	j?,?	G L!IIK)+*:*:;&FA#s##%&)B3%'HII&|EH '  $$00::	[..0A0A;CTCTUUUU K--- MM!*k.?.?!?%++U[[ 	
 zz%1)-[%%&# L& ).g71,J7 8s   -
E;c                P   RVRV/p/ pV P                  4        EFj  p\        VP                  4      p\        V4       F;  w  r\	        V
\
        4      '       g   K  W9  d   \        RV
 24      hWZ,          W&   K=  	  VP                  P                  P                  pV\        P                  \        P                  \        P                  39   g   Q hV\        P                  8X  d   \        P                  M4V\        P                  8X  d   \        P                  M\        P                   pRVP"                  9   d"   \        P$                  ! WR7      p^VRRV13&   M\        P&                  ! WR7      pWVP"                  &   EKm  	  \)        V4       Uu. uF  qNK  	  ppV# u upi )a  Create dummy inputs for Longformer model.

Args:
    onnx_model (OnnxModel): ONNX model
    batch_size (int): batch size
    sequence_length (int): sequence length
    global_length (int): number of global tokens
    samples (int): number of samples

Raises:
    RuntimeError: symbolic is not supported. Use the tool convert_longformer_to_onnx.py to export ONNX model instead.

Returns:
    List[Dict]: list of inputs
rT   rU   rp   globalrA   :NNNN)rC   r?   r   rD   rE   r   rq   r;   rH   r   rI   rJ   rK   rL   rM   rN   rO   rQ   zerosrP   rR   )rS   rT   rU   global_lengthrV   rs   rW   rX   r<   rZ   r7   rH   r[   r\   r0   r-   s   &&&&&           r   create_longformer_inputsry   ;  sf     Z):OLGL!IIK)+*:*:;&FA#s##%&)B3%'HII&|EH '  $$00::	[..0A0A;CTCTUUUU K--- MM!*k.?.?!?%++U[[ 	 {''';;u6D&'DN]N"#::e5D)-[%%&- L0 ).g71,J7 8s   
F#c           	         V P                   ^ 8  d   V P                   M\        P                  ! RR7      pR\        P                  9  d   \        V4      \        P                  R&   ^ RIHp ^ RIH	p V! V! V P                  4      4      pRpV P                  R8X  dO   \        VV P                  V P                  V P                  V P                   V P"                  V P$                  4      pMV P                  R8X  d9   \'        VV P                  V P                  V P(                  V P                  4      pMtV P                  R	8X  d9   \+        VV P                  V P                  V P,                  V P                  4      pM+\/        W@P                  V P                  V P                  4      p\1        V P                  V P2                  V P4                  V P6                  V P                   V4      pV# )
r   F)logicalOMP_NUM_THREADS)load)	OnnxModelNr   r   r   )r,   psutil	cpu_countosenvironr   onnxr}   rS   r~   modelrW   rk   rT   rU   rV   rh   ri   rj   rt   rr   ry   rx   r]   r2   r   r+   r   )argsr%   r}   r~   rS   r-   r1   s   &      r   r(   r(   j  s   %)__q%8$//f>N>NW\>]K 

*(+K(8

$%$4

+,JJF"'OO  LL!!  

 
		f	$'OO  %%LL

 
		l	*-OO  LL

 )__dFZFZ\`\h\hi


L r!   __main__	Arguments)setup_loggerzMrequires either --model to run profiling or --input to read profiling results)process_resultsr:   )NNN)r   r   rL   r   r   r   r    r2   r8   r?   r]   rk   rt   ry   r(   __name__	argumentsprintr'   r   r   inputr   r1   profile_result_processorr   resultsline r!   r   <module>r      s     	   I#X&cR'T&R-`,^3l z!I	+y!-""#???o oo9~ 8lI6Gd # r!   