
    h&                    `    S SK Jr  S SKr S SKrSrSSKJrJr  SS	S jjr	g! \ a    Sr Nf = f)
    )annotationsNT   )$GloballyAllowedTypesOpTypeImplFilterOperatorTypeUsageManagerFc                R  ^^^ [         R                  R                  U 5      (       d  [        SU  S35      eT=(       a    [        m0 nSmT(       a
  [        5       OSnSnSmUUU4S jn[        U 5       nU Vs/ s H  owR                  5       PM     sn GH  nU" U5      (       a  M  S UR                  S5       5       u  pnU
R                  S5       Vs/ s H  n[        U5      PM     nnS	U;   Ga8  S
n[        5       nSn[        U5      nUU:  Ga  UR                  SU5      nUR                  S	U5      nUS:X  a  UnSUs=:  a  U:  a  O  OXU R                  5       nUR                  U5        US-   nSnUS:  a6  UU:  a0  UU   S	:X  a  US-  nOUU   S:X  a  US-  nUS-  nUS:  a  UU:  a  M0  US:w  a  [        SUUS -   5      eU(       a  UUU nUR                  U	UU5        US-   nO0US:w  a  UOUnUR                  XU R                  5       5        US-   nUU:  a  GM  O/UR                  S5       Vs1 s H  nUR                  5       iM     nnU H7  nX;  a  UU0X)'   M  UX)   ;  a	  XU	   U'   M!  X)   U   R!                  U5        M9     GM     SSS5        [        U5      S:X  a	  T(       a  SnSnT(       a?  U(       d  SnTb  Ub  [        S5      eTb  [#        T5      nUU4$ Ub  UR%                  5       nUU4$ s  snf s  snf s  snf ! , (       d  f       N= f)a  
Parse the configuration file and return the required operators dictionary and an
OpTypeImplFilterInterface instance.

Configuration file lines can do the following:
1. specify required operators
2. specify globally allowed types for all operators
3. specify what it means for no required operators to be specified

1. Specifying required operators

The basic format for specifying required operators is `domain;opset1,opset2;op1,op2...`
e.g. `ai.onnx;11;Add,Cast,Clip,... for a single opset
     `ai.onnx;11,12;Add,Cast,Clip,... for multiple opsets

     note: Configuration information is accrued as the file is parsed. If an operator requires support from multiple
     opsets that can be done with one entry for each opset, or one entry with multiple opsets in it.

If the configuration file is generated from ORT format models it may optionally contain JSON for per-operator
type reduction. The required types are generally listed per input and/or output of the operator.
The type information is in a map, with 'inputs' and 'outputs' keys. The value for 'inputs' or 'outputs' is a map
between the index number of the input/output and the required list of types.

For example, both the input and output types are relevant to ai.onnx:Cast.
Type information for input 0 and output 0 could look like this:
    `{"inputs": {"0": ["float", "int32_t"]}, "outputs": {"0": ["float", "int64_t"]}}`

which is added directly after the operator name in the configuration file.
e.g.
    `ai.onnx;12;Add,Cast{"inputs": {"0": ["float", "int32_t"]}, "outputs": {"0": ["float", "int64_t"]}},Concat`

If for example the types of inputs 0 and 1 were important, the entry may look like this (e.g. ai.onnx:Gather):
    `{"inputs": {"0": ["float", "int32_t"], "1": ["int32_t"]}}`

Finally some operators do non-standard things and store their type information under a 'custom' key.
ai.onnx.OneHot is an example of this, where the three input types are combined into a triple.
    `{"custom": [["float", "int64_t", "int64_t"], ["int64_t", "std::string", "int64_t"]]}`

2. Specifying globally allowed types for all operators

The format for specifying globally allowed types for all operators is:
    `!globally_allowed_types;T0,T1,...`

Ti should be a C++ scalar type supported by ONNX and ORT.
At most one globally allowed types specification is allowed.

Specifying per-operator type information and specifying globally allowed types are mutually exclusive - it is an
error to specify both.

3. Specify what it means for no required operators to be specified

By default, if no required operators are specified, NO operators are required.

With the following line, if no required operators are specified, ALL operators are required:
    `!no_ops_specified_means_all_ops_are_required`

:param config_file: Configuration file to parse
:param enable_type_reduction: Set to True to use the type information in the config.
                              If False the type information will be ignored.
                              If the flatbuffers module is unavailable type information will be ignored as the
                              type-based filtering has a dependency on the ORT flatbuffers schema.
:return: required_ops: Dictionary of domain:opset:[ops] for required operators. If None, all operators are
                       required.
         op_type_impl_filter: OpTypeImplFilterInterface instance if type reduction is enabled, the flatbuffers
                              module is available, and type reduction information is present. None otherwise.
zConfiguration file z does not existFNc                8  > U (       a  U R                  S5      (       a  gU R                  S5      (       aW  T(       aO  Tb  [        S5      eU R                  S5      S   R                  S5       Vs1 s H  oR                  5       iM     snmgU S:X  a  Smgg	s  snf )
N#Tz!globally_allowed_types;z.Globally allowed types were already specified.;r   ,z,!no_ops_specified_means_all_ops_are_requiredF)
startswithRuntimeErrorsplitstrip)linesegmentenable_type_reductionglobally_allowed_types+no_ops_specified_means_all_ops_are_requireds     g/var/www/fran/franai/venv/lib/python3.13/site-packages/onnxruntime/tools/reduced_build_config_parser.pyprocess_non_op_line)parse_config.<locals>.process_non_op_linea   s    ts++??566$)5&'WXXIMTWYZI[IaIabeIf)gIfg--/If)g&AA:>7 *hs   0Bc              3  @   #    U  H  oR                  5       v   M     g 7f)N)r   ).0r   s     r   	<genexpr>parse_config.<locals>.<genexpr>y   s     /_Gs   r
   r   {Tr   r   }z#Mismatched { and } in type string: zYSpecifying globally allowed types and per-op type reduction info together is unsupported.)ospathisfile
ValueErrorhave_flatbuffersr   openr   r   intsetlenfindaddr   restore_from_config_entryupdater   make_op_type_impl_filter)config_filer   required_opsop_type_usage_managerhas_op_type_reduction_infor   config	orig_liner   domain	opset_stroperators_strsopsets	operatorscurend
next_commanext_open_braceoperatorinum_open_bracestype_strend_stropopsetop_type_impl_filterr   r   s    `                         @@r   parse_configrE      s   H 77>>+&&.{m?KLL 2F6FL27/:O46UY!&!& 
k	f8>?9__&?D"4((/_tzzZ]/_,F}&/ooc&:;&:c!f&:F; m#-1*  E	-(Ci!.!3!3C!=J&3&8&8c&BO!R'%(
 ?7Z7#0_#E#K#K#M!h/ ,a/*+-1a#g,Q/36 /1 4!.q!1S!8 /1 4FA .1a#g +a/"./TWdeteuWv/v"ww0'4_Q'GH1KKFT\^fg!e 1;b0@*c!m&@&F&F&HI%kQ CiV 3@2E2Ec2JK2JBRXXZ2J	K-,19+=L(,"662;(/ (/66yA  { @ 
L <A"M)$(!!-2G2Sk  "-"FG]"^ ,,, #."7"P"P"R,,,m @
 <l Ly 
	sF   4L9L	ALL+C	L6A2L+L?LAL	L
L&)F)r-   strr   bool)

__future__r   r   flatbuffersr#   ort_format_modelr   r   ImportErrorrE        r   <module>rN      s;    # 	`
z-	  s   " --