o
    ;ήc	                     @   sz   d dl Z d dlZddlmZ ddlmZ ddlmZ edZdej	e j
 d	efd
dZdej	e j
 de j
d	efddZdS )    N   )
get_logger   )OperatorTypeUsageManager)OrtFormatModelProcessorzort_format_model.utilsmodel_filesenable_type_reductionc                 C   sT   i }|rt  nd }| D ]}| std| dtt|||}|  q||fS )NzPath is not a file: '')r   is_file
ValueErrorr   strprocess)r   r   required_opsop_type_usage_manager
model_filemodel_processor r   O/tmp/pip-target-vg8gfxp4/lib/python/onnxruntime/tools/ort_format_model/utils.py&_extract_ops_and_types_from_ort_models   s   
r   output_filec           	   
      s  t | |\}|jjddd t|d`}|d t| D ]}|d| d qt| D ]< t|   D ]1}|  | }|rk|d | |r\ fdd	t|D }nt|}|d
d| q:q0W d   n1 sww   Y  t	
d| dS )aV  
    Create a configuration file with required operators and optionally required types.
    :param model_files: Model files to use to generate the configuration file.
    :param output_file: File to write configuration to.
    :param enable_type_reduction: Include required type information for individual operators in the configuration.
    T)parentsexist_okwz# Generated from model/s:
z# - 
z{};{};c              	      s$   g | ]}d  | |pdqS )z{}{} )formatget_config_entry).0opdomainop_type_processorsr   r   
<listcomp>5   s    z-create_config_from_models.<locals>.<listcomp>z{}
,NzCreated config in %s)r   parentmkdiropenwritesortedkeysr   joinloginfo)	r   r   r   r   outr   opsetopsentriesr   r   r   create_config_from_models   s,   

r1   )pathlibtypingloggerr   operator_type_usage_processorsr   ort_model_processorr   r+   IterablePathboolr   r1   r   r   r   r   <module>   s   
