
     Tic                        S SK Jr  S SKrS SKJr  S SKrS SKJs  J	r
  S SKJr  S SKJr  \R                  " \5      r S
SS\R$                  \R&                  S SS.                 SS	 jjjrg)    )annotationsN)Callable)rewriter)_constant_foldingTc                    g )N )nodes    ^/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/onnxscript/optimizer/_optimizer.py<lambda>r      s        )onnx_shape_inferencestop_if_no_changeinput_size_limitoutput_size_limitshould_foldinlinec          	        [         R                  R                  [        R                  " UUUUS9[
        R                  " [
        R                  5      [        R                  " 5       [        R                  " 5       [        R                  " 5       /UUS9[        R                  " 5       [        R                  " SSS9[        R                  " 5       [        R                  " 5       [        R                  " 5       [        R                   " 5       [        R"                  " 5       /nU(       a  [        R$                  " 5       /UQn[         R                  R&                  " U6 n	U	R(                  (       d   eU	" U 5      n
U
R*                  U L d   eg)a  Optimizes a model.

Args:
    model: The model to be optimized.
    num_iterations: Number of times the optimization loop is repeated.
    onnx_shape_inference: Applies node-level shape-inference as part of optimization
    stop_if_no_change: Stop the optimization loop if no change is detected in an iteration.
    input_size_limit: Will not apply constant folding to ops with any input of size
        greater than this. Does not apply to special ops like Shape() and Size().
    output_size_limit: Will not rewrite any foldable-op into a Constant op if the size
        of the output tensor is greater than this.
    should_fold: An optional function that takes a node and returns True if
        the node should be considered for folding.
        The function should return True/False value to indicate if this particular
        node should be folded, or None to use the default folding rules.
    inline: If True, inlines all functions in the model.
)shape_inferencer   r   r   )steps
early_stopTr   )lift_all_constants
size_limitN)irpassesPassManagerr   FoldConstantsPassr   RewritePass_DEFAULT_REWRITE_RULEScommon_passesRemoveUnusedNodesPassRemoveUnusedFunctionsPassRemoveUnusedOpsetsPassLiftConstantsToInitializersPass'LiftSubgraphInitializersToMainGraphPassDeduplicateInitializersPass"CommonSubexpressionEliminationPassOutputFixPassNameFixPass
InlinePass
Sequentialin_placemodel)r,   num_iterationsr   r   r   r   r   r   r   optimizer_passresults              r
   optimize_irr0      s8   : 			!33$8%5&7 +	 $$X%D%DE335779446 !( 	 	
  	++-55Z[\==?11388:##%!!#/F2 **,6v6YY))62N""""E"F<<5   r   )   )r,   zir.Modelr-   intr   boolr   r3   r   r2   r   r2   r   z Callable[[ir.Node], bool | None]r   r3   returnNone)
__future__r   loggingtypingr   onnx_irr   onnx_ir.passes.commonr   commonr   
onnxscriptr   onnxscript.optimizerr   	getLogger__name__logger&DEFAULT_CONSTANT_FOLD_INPUT_SIZE_LIMIT'DEFAULT_CONSTANT_FOLD_OUTPUT_SIZE_LIMITr0   r   r   r
   <module>rC      s    #    - -  2			8	$
 ;! "&"-TT.VV4E;!;!;! 	;!
 ;! ;! ;! 2;! ;! 
;!r   