
    ϑi                       S SK Jr  S SKrS SKrS SKJrJrJr  S SKr	S SK
r
S SKJr  S SKJrJrJrJrJrJr  S SKJr  \(       a  S SKJr  S SKJr  S SK
Jr   " S	 S
\5      r\" \\R:                  SS9r\r\r \RB                  r"\r#\r\r$SS jr%SS jr&S r'S\(" 5       4                   SS jjr)\%\l*        \&\l+        \'\l,        g)    )annotationsN)TYPE_CHECKINGAny	TypedDict)core)AnalysisConfigPaddleDTypePaddleInferPredictorPaddleInferTensorPaddlePlaceconvert_to_mixed_precision_bind)
get_logger)Unpack)Tensorc                       \ rS rSr% S\S'   Srg)
_WhiteList)   set[str]
white_list N)__name__
__module____qualname____firstlineno____annotations____static_attributes__r       X/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/inference/wrapper.pyr   r   )   s    r   r   z&%(asctime)s-%(levelname)s: %(message)s)fmtc                    [        U[        R                  5      (       d<  [        U[        5      (       a9  [	        U5      S:  a*  [        US   [
        5      (       a  U R                  U5        g[        S5      e)z9
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npndarraylistlenstr_copy_from_cpu_bind	TypeErrorselfdatas     r   tensor_copy_from_cpur,   9   sZ     $

##43t9q=ZQ5M5M  &V
 	
r   c                X   [        U[        R                  5      (       a  U R                  U5        g[        U[        R
                  5      (       a  U R                  U5        g[        U[        R                  R                  R                  5      (       a  [        S5      e[        S5      e)z?
Support input type check based on tensor.share_external_data.
zThe interface 'share_external_data' can only be used in dynamic graph mode. Maybe you called 'paddle.enable_static()' and you are in static graph mode now. Please use 'copy_from_cpu' instead.z?In share_external_data, we only support Tensor and DenseTensor.N)r!   r   DenseTensor_share_external_data_bindpaddler   '_share_external_data_paddle_tensor_bindbase	frameworkVariabler(   r)   s     r   tensor_share_external_datar5   G   s     $(())&&t,	D&--	(	(44T:	D&++//88	9	92
 	
 M
 	
r   c                (    U R                  XX45        g)z1
Support tensor.share_external_data_by_ptr_name.
N)%_share_external_data_by_ptr_name_bind)r*   r+   shapedtypeplaces        r   &tensor_share_external_data_by_ptr_namer;   [   s     	..tEIr   Tc                   U[         R                  L a/  [        R                  " 5       (       d  [        R                  S5        [        R                  R                  U5      n	[        U5      S:w  a  [        R                  R                  U5      OU	n
[        R                  R                  U
5      (       d  [        R                  " U
5        UR                  S[        5       5      n[        U UUUUUUUU5	        g)a  
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.
        Default is True.
    black_list: Operators that do not convert precision.
    kwargs: Supported keys including 'white_list'.
        - white_list: Operators that do convert precision.
zOYou should use PaddlePaddle compiled with GPU when backend set to PlaceType.GPUr   r   N)	PlaceTypeGPUr   is_compiled_with_cuda_loggererrorospathdirnamer%   existsmakedirsgetsetr   )
model_fileparams_filemixed_model_filemixed_params_filemixed_precisionbackendkeep_io_types
black_listkwargsmixed_model_dirnamemixed_params_dirnamer   s               r   convert_to_mixed_precisionrT   b   s    6 )--(B(B(D(D]	
 ''//*:;  !Q& 	)*  
 77>>.//
()L#%0J#
r   )r+   znpt.NDArray[Any] | list[str]returnNone)r+   r   rU   rV   )rI   r&   rJ   r&   rK   r&   rL   r&   rM   PrecisionTyperN   r=   rO   boolrP   r   rQ   zUnpack[_WhiteList]rU   rV   )-
__future__r   loggingrB   typingr   r   r   numpyr"   r0   paddle.baser   paddle.base.corer   r	   r
   r   r   r   paddle.base.log_helperr   numpy.typingnpttyping_extensionsr   r   r   r   INFOr@   DataTyper=   	PrecisionrW   Config	Predictorr,   r5   r;   rH   rT   copy_from_cpushare_external_datashare_external_data_by_ptr_namer   r   r   <module>rk      s   #  	 0 0     .(Y  gll H 	((		 	

(J 5666 6 	6
 #6 6 6 6 !6 
6r , 7 )O &r   