
     TiS                         S r SSKJr  SSKrSSKrSSKJs  Jr	  S\R                  S\\R                     SS4S jrS\R                  S	\\R                     S\R                  4S
 jrg)zPA utility function to replace custom operations in a model with their expansions    )SequenceNirmodelirfunctionsreturnc                     U R                   n[        U5      S:w  a  [        S5      eU H  nX2UR                  5       '   M     [        R
                  " 5       " U 5        [        R                  " 5       " U 5        g)a"  A utility function to replace custom operations in a model with their expansions:

The model is updated in-place.

Args:
    irmodel: An ONNX model possibly containing calls to custom operations.
    irfunctions: A sequence of functions defining the expansions for the custom operations.


r   z.Input model cannot have model-local functions.N)	functionslen
ValueError
identifiercommon_passes
InlinePassRemoveUnusedOpsetsPass)r   r   model_functionsfuncs       W/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/onnxscript/utils/replace.pyreplace_functions_inplacer      se     ''O
?q IJJ-1)*  w'((*73    modelr   c                     [         R                  " U 5      nU Vs/ s H  n[         R                  " U5      PM     nn[        X$5        [         R                  " U5      $ s  snf )a]  A utility function to replace custom operations in a model with their expansions:
Args:
    model: An ONNX ModelProto possibly containing calls to custom operations.
    functions: A sequence of FunctionProto defining the expansions for the custom operations.

Returns:
    An updated ModelProto with custom operations replaced by their expansions.
)ir
from_protor   to_proto)r   r   r   r   r   s        r   replace_functionsr   #   sK     mmE"G3<=942==&9K=g3;;w >s    A)__doc__typingr   onnxonnx_irr   onnx_ir.passes.commonpassescommonr   ModelFunctionr   
ModelProtoFunctionProtor    r   r   <module>r&      sr    W    - -4rxx 4hr{{>S 4X\ 4. ?? '/0B0B'C 	__ r   