o
    Neø  ã                   @   sÄ   d dl mZmZmZ d dl mZmZ d dl mZ d dlm Z  ddlZddl	Z
ddlmZ eZeZejZeZeZeZdd	„ Zd
d„ Zdeƒ fdedededededededefdd„Zee_ee_dS )é   )ÚAnalysisConfigÚPaddleDTypeÚPaddlePlace)ÚPaddleInferPredictorÚPaddleInferTensor)Úconvert_to_mixed_precision_bind)Úcoreé    N)ÚSetc                 C   sF   t |tjƒst |tƒrt|ƒdkrt |d tƒr|  |¡ dS tdƒ‚)zA
    Support input type check based on tensor.copy_from_cpu.
    r	   zHIn copy_from_cpu, we only support numpy ndarray and list[str] data type.N)Ú
isinstanceÚnpZndarrayÚlistÚlenÚstrZcopy_from_cpu_bindÚ	TypeError©ÚselfÚdata© r   úND:\Projects\ConvertPro\env\Lib\site-packages\paddle/fluid/inference/wrapper.pyÚtensor_copy_from_cpu    s   "ÿÿr   c                 C   s"   t |tjƒr|  |¡ dS tdƒ‚)zG
    Support input type check based on tensor.share_external_data.
    z<In share_external_data, we only support LoDTensor data type.N)r   r   Z	LoDTensorZshare_external_data_bindr   r   r   r   r   Útensor_share_external_data-   s
   ÿr   TÚ
model_fileÚparams_fileÚmixed_model_fileÚmixed_params_fileÚmixed_precisionÚbackendÚkeep_io_typesÚ
black_listc           
   	   C   s^   t j |¡}t j |¡}	t j |¡st  |¡ t j |	¡s"t  |	¡ t| |||||||ƒ dS )al  
    Convert a fp32 model to mixed precision model.

    Args:
        model_file: fp32 model file, e.g. inference.pdmodel.
        params_file: fp32 params file, e.g. inference.pdiparams.
        mixed_model_file: The storage path of the converted mixed-precision model.
        mixed_params_file: The storage path of the converted mixed-precision params.
        mixed_precision: The precision, e.g. PrecisionType.Half.
        backend: The backend, e.g. PlaceType.GPU.
        keep_io_types: Whether the model input and output dtype remains unchanged.
        black_list: Operators that do not convert precision.
    N)ÚosÚpathÚdirnameÚexistsÚmakedirsr   )
r   r   r   r   r   r   r   r   Zmixed_model_dirnameZmixed_params_dirnamer   r   r   Úconvert_to_mixed_precision8   s   

þr%   )r   r   r   r   r   r   r   Ú r    Únumpyr   Útypingr
   ZDataTypeZ	PlaceTypeZ	PrecisionZPrecisionTypeZConfigZTensorZ	Predictorr   r   Úsetr   Úboolr%   Zcopy_from_cpuZshare_external_datar   r   r   r   Ú<module>   sD   ùÿþýüûú
ù 
