
    ujc
                         d dl Z d dlmZmZ d dlmZmZ d dlmZ d dl	m
Z
mZ d dlmZ d dlmZ dd	lmZ  e            Z G d
 de          ZdS )    N)ABCabstractmethod)DictUnion)Model)Config
ConfigDict)	ModelFile)
get_logger   )build_exporterc                   d    e Zd ZdZd	dZedeeef         fd            Z	e
d
defd            ZdS )ExporterzNExporter base class to output model to onnx, torch_script, graphdef, etc.
    Nc                     || _         d S N)model)selfr   s     i/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/modelscope/exporters/base.py__init__zExporter.__init__   s    


    r   c                    t          |t                    rt          j        |          }t	          |d          sJ |j        }t          j        t          j	        
                    |t          j                            }|j        }t	          |d          r|j        }|j        }t	          |d          rt	          |d          s|j        |_        t%          d|j        i          }t	          |d          r|                    |j                   ||d<   	 t+          |||          }n.# t,          $ r!}	t-          d|j         d| d	          |	d
}	~	ww xY w|S )aX  Build the Exporter instance.

        Args:
            model: A Model instance or a model id or a model dir, the configuration.json file besides to which
            will be used to create the exporter instance.
            kwargs: Extra kwargs used to create the Exporter instance.

        Returns:
            The Exporter instance
        	model_dir	group_key
model_typetypeexportr   zThe exporting of model 'z' with task: 'z' is not supported currently.N)
isinstancestrr   from_pretrainedhasattrr   r   	from_fileospathjoinr
   CONFIGURATIONtaskr   r   r   r   r	   updater   r   KeyError)
clsr   kwargsr   cfg	task_name	model_cfg
export_cfgexporteres
             r   
from_modelzExporter.from_model   s|    eS!! 	1)%00Euk*****O	GLLI$;<<> >H	5+&& 	(II	9l++ 	2GIv4N4N 	2&1IN 899
3!! 	*cj)))#
7	7%j)VDDHH 	7 	7 	7/IN / /I / / /0 0567	7 s   D( (
E2EE   
output_dirc                     dS )a'  Export the model as onnx format files.

        In some cases,  several files may be generated,
        So please return a dict which contains the generated name with the file path.

        Args:
            opset: The version of the ONNX operator set to use.
            output_dir: The output dir.
            kwargs: In this default implementation,
                kwargs will be carried to generate_dummy_inputs as extra arguments (like input shape).

        Returns:
            A dict contains the model name with the model file path.
        N )r   r3   opsetr*   s       r   export_onnxzExporter.export_onnx;   s	      	r   r   )r2   )__name__
__module____qualname____doc__r   classmethodr   r   r   r1   r   r7   r5   r   r   r   r      s             "uUCZ0 " " " ["H  c    ^  r   r   )r"   abcr   r   typingr   r   modelscope.modelsr   modelscope.utils.configr   r	   modelscope.utils.constantr
   modelscope.utils.loggerr   builderr   loggerr   r5   r   r   <module>rE      s    				 # # # # # # # #         # # # # # # 6 6 6 6 6 6 6 6 / / / / / / . . . . . . # # # # # #	< < < < <s < < < < <r   