
    ёiP                    Z   S SK Jr  S SKrS SKrS SKJrJr  S SKJ	r	  S SK
JrJrJrJrJr  SSKJrJrJrJr  SSKJr  SS	KJr  SS
KJr  0 \R6                  R8                  \	R:                  _\R6                  R<                  \	R>                  _\R6                  R@                  \	RB                  _\R6                  RD                  \	RF                  _\R6                  RH                  \	RH                  _\R6                  RJ                  \	RJ                  _\R6                  RL                  \	RL                  _\R6                  RN                  \	RN                  _\R6                  RP                  \	RP                  _\R6                  RR                  \	RR                  _\R6                  RT                  \	RT                  _\R6                  RV                  \	RV                  _\R6                  RX                  \	RZ                  _\R6                  R\                  \	R^                  _\R6                  R`                  \	Rb                  _\R6                  Rd                  \	Rf                  _r4\4Rk                  5        V Vs0 s H  u  pX_M	     snn r60 \Rn                  " S5      \	R:                  _\Rn                  " S5      \	R>                  _\Rn                  " S5      \	RB                  _\Rn                  " S5      \	RH                  _\Rn                  " S5      \	RJ                  _\Rn                  " S5      \	RL                  _\Rn                  " S5      \	RN                  _\Rn                  " S5      \	RF                  _\Rn                  " S5      \	RP                  _\Rn                  " S5      \	RR                  _\Rn                  " S5      \	RT                  _\Rn                  " S5      \	RV                  _\Rp                  \	RB                  _\Rr                  \	R:                  _\Rt                  \	R>                  _\Rv                  \	RH                  _\Rx                  \	RJ                  _\Rz                  \	RL                  \R|                  \	RN                  \R~                  \	RF                  \R                  \	RP                  \R                  \	RR                  \R                  \	RT                  \R                  \	RV                  S\	RZ                  S\	R^                  0	ErD0 \	RN                  S_\	RB                  S_\	RF                  S_\	R:                  S_\	R>                  S_\	RR                  S_\	RJ                  S_\	RH                  S_\	RL                  S_\	RP                  S_\	R                  S_\	R                  S_\	R                  S_\	RT                  S_\	RV                  S_\	RZ                  S_\	R^                  S_rH0 S\	R:                  _S\	R>                  _S\	RB                  _S\	RH                  _S\	RJ                  _S\	RL                  _S\	RN                  _S\	RN                  _S\	RF                  _S\	RP                  _S\	RR                  _S\	RT                  _S\	RV                  _S\	RF                  _S\	RZ                  _S\	R^                  _rIS,S jrJ\" 5       qK\" [        R                  5       5        \" 5       qMS rNS rOS-S  jrPS! rQ\S-S" j5       rR " S# S$5      rS S-S% jrTS-S& jrUS' rVS( rWS) rX\S* 5       rYS-S+ jrZgs  snn f ).    )annotationsN)PlaceVarDesc)DataType)Programget_current_insertion_pointreset_insertion_point_to_startset_insertion_point set_insertion_point_to_block_end   )data	parameterset_parameterset_persistable_value)unique_nameset_static_op_arg_pre_cast_hook)signature_safe_contextmanagerfloat32float64float16int32int16int64bool_uint16uint8int8	complex64
complex128float8_e4m3fnfloat8_e5m2booluint32uint64bfloat16c                    [        U [        5      (       a1  U R                  5       R                  5       nU[        ;   a	  [        U   $ [
        R                  " U 5      nU[        ;   a	  [        U   $ [        SU 35      e)z
Convert the data type in numpy to the data type in Paddle.

Args:
    np_dtype (np.dtype|str): The data type in numpy or valid data type
        string.

Returns:
    DataType : The data type in Paddle.

zNot supported numpy dtype )	
isinstancestrlowerstripstr_to_paddle_typenpdtypenp_type_to_paddle_type
ValueError)np_dtypekeyr.   s      O/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/pir/core.pyconvert_np_dtype_to_dtype_r4   ~   so     (C  nn$$&$$%c**HHXE&&%e,,5eW=>>    c                     [         $ )ap  
Get default/global startup program.

The :code:`paddle.nn` function will append the initialization operators into startup program.
The :code:`startup_program` will initialize the parameters by the OPs.

This method will return the default or the current startup program. Users can use
:ref:`api_paddle_ir_core_program_guard`  to switch :ref:`api_paddle_ir_Program` .

Returns:
    Program: current default startup program.

Returns type:

Examples:
    .. code-block:: python

        >>> import paddle

        >>> paddle.enable_static()
        >>> x = paddle.static.data(name="x", shape=[-1, 784], dtype='float32')
        >>> out = paddle.static.nn.fc(name="fc", x=x, size=10, activation="relu")
        >>> print("main program is: {}".format(paddle.static.default_main_program()))
        >>> print("start up program is: {}".format(paddle.static.default_startup_program()))
_startup_program_ r5   r3   default_startup_programr:      s
    4 r5   c                     [         $ )a  
This API can be used to get ``default main program`` which store the
descriptions of Ops and tensors.

For example ``z = paddle.add(x, y)`` will create a new ``add``
Op and a new ``z`` tensor, and they will be recorded in ``default main program`` .

The ``default main program`` is the default value for ``Program`` parameter in
a lot of APIs. For example, the :code:`Executor.run()` will execute the
:code:`default_main_program` when the program is not specified.

If you want to switch the ``default main program``, you can use :ref:`api_paddle_ir_core_program_guard` .

Returns:
    Program: A ``Program`` which holding the descriptions of OPs and tensors in the network.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> paddle.enable_static()
        >>> # Sample Network:
        >>> x = paddle.static.data(name='x', shape=[100, 100], dtype='float32')
        >>> y = paddle.static.data(name='y', shape=[100, 100], dtype='float32')
        >>> out = paddle.add(x, y)

        >>> # print the number of blocks in the program, 1 in this case
        >>> print(paddle.static.default_main_program().num_blocks) # 1
        >>> # print the default_main_program
        >>> print(paddle.static.default_main_program())
)_main_program_r9   r5   r3   default_main_programr=      s    B r5   c                    [         n[        5       nU q X:X  a  Uc  UnUc   [        [         R                  5       5        X#4$ [	        U5        X#4$ )z
Switch the main program to a new program.

Args:
    program(Program): The new main program

Returns:
    Program: The previous main program
)r<   r   r   global_blockr
   )programinsertion_pointprev_programprev_insertion_points       r3   switch_main_programrD      s\     "L68N?#:.()D)D)FG -- 	O,--r5   c                    [         nU q U$ )z
Switch the startup program to a new program
Args:
    program(Program): The new startup program

Returns:
    Program: The previous startup program
r7   )r@   rB   s     r3   switch_startup_programrF      s     %Lr5   c              #    #    SSK Jn  U" U S[        S5        [        U 5      u  pUb  U" US[        S5        [	        U5      n Sv   [        X5        Ub  [	        U5        gg! [        X5        Ub  [	        U5        f f = f7f)a  
:api_attr: Static Graph

Change the global main program and startup program with ``with`` statement.
Layer functions in the Python ``with`` block will append operators and
Tensors to the new main programs.

Args:
    main_program(Program): New main program inside ``with`` statement.
    startup_program(Program, optional): New startup program inside ``with``
        statement. :code:`None` means not changing startup program,
        default_startup_program is still used.
        Default: None.

Examples:
    .. code-block:: python
        :name: code-example-1

        >>> import paddle

        >>> paddle.enable_static()
        >>> main_program = paddle.static.Program()
        >>> startup_program = paddle.static.Program()
        >>> with paddle.static.program_guard(main_program, startup_program):
        ...     data = paddle.static.data(name='image', shape=[None, 784, 784], dtype='float32')
        ...     hidden = paddle.static.nn.fc(x=data, size=10, activation='relu')

Notes: The temporary :code:`Program` can be used if the user does not need
to construct either of startup program or main program.

Examples:
    .. code-block:: python
        :name: code-example-2

        >>> import paddle

        >>> paddle.enable_static()
        >>> main_program = paddle.static.Program()
        >>> # does not care about startup program. Just pass a temporary value.
        >>> with paddle.static.program_guard(main_program, paddle.static.Program()):
        ...     data = paddle.static.data(name='image', shape=[None, 784, 784], dtype='float32')
r   )
check_typemain_programzpaddle.static.program_guardNstartup_program)base.data_feederrH   r   rD   rF   )rI   rJ   rH   rC   s       r3   program_guardrL     s     X .ng/L *=\)J&L")		
 1A4L?&"?3 ' 	L?&"?3 's   A BA" B"A>>Bc                      \ rS rSrS rSrg)ParameterMetaiG  c                    Xl         X l        g N)shaper.   )selfrQ   r.   s      r3   __init__ParameterMeta.__init__H  s    

r5   )r.   rQ   N)__name__
__module____qualname____firstlineno__rS   __static_attributes__r9   r5   r3   rN   rN   G  s    r5   rN   c                  ^^ ST;  a  [        S5      eU b   [        U [        5      (       d  [        U 5      n UnU(       d  [        R
                  " S5      n[        5       n[        5       n[        TU 5      nSnST;   a  TS   (       a  ST;   a  TS   (       a  SnUU4S jn	[        U5         TS   n
U
" XuR                  5       5      nSUl        U(       a  U	" U5        [        X5        S S S 5        UR                  U5        [        [        5       5         [        5         [        U5      nSUl        U(       a  U	" U5        S S S 5        TR!                  S	S5      Wl        UR"                  (       + Ul        TR!                  S
SS05      Ul        TR!                  SS 5      Ul        TR!                  SS 5      Ul        TR!                  SS5      Ul        SUl        SUl        U$ ! , (       d  f       GN= f! , (       d  f       N= f)NinitializerRinitializer is None, if you want to create parameter, please pass its initializer.r   F
placementsprocess_meshTc                  > SS K nSS KJn  T	S   nUR                  R                  R                  T	S   [        T
5      5      u  pEUR                  R                  R                  R                  X4U5      nUR                  R                  R                  R                  U R                  5       U5      nU R                  U5        UR                  R                  R                  R                  U/ U/5      nXR                  5       l        g )Nr   r^   r]   )paddlepaddle.distributeddistributedauto_parallelplacement_type
to_dim_maplenbase	libpaddlepircreate_tensor_dist_attributecvt_to_dist_typetypeset_typecreate_op_dist_attributeget_defining_op	dist_attr)valuer`   distr^   dim_mappartial_statusrp   	dist_typeop_dist_attrkwargsrQ   s            r3   to_dist!create_parameter.<locals>.to_distj  s    )n-"&"4"4"C"C"N"N< #e*#
 KK))--JJ>
	 KK))-->>JJL)
	 	y!{{,,00II"yk
 -9)r5   	trainableoptimize_attrlearning_rateg      ?regularizerdo_model_average	need_clip)r0   r(   r   r4   r   generater:   r=   rN   rL   r?   persistabler   set_parameters_fromr	   r   getrz   stop_gradientr{   r}   r~   r   is_distributedis_parameter)r.   rQ   namerw   
value_namerJ   rI   parameter_metais_distrx   r[   init_resultparams    ` `         r3   create_parameterr   M  s    F"`
 	
 %**.u5EJ ))+6
-/O')L"5%0NG< f$>"9( 
	']+!88:
 #'K k. 
( $$_5	+-	.&(*% EN 
/ jjd3EO#oo-E **_6LME

=$7E#ZZ(:DAEjjd3EO EEL9 
(	' 
/	.s   ,=G$,G6$
G36
Hc                  ^ ST;  a  [        S5      eU b   [        U [        5      (       d  [        U 5      n UnU(       d  [        R
                  " S5      nST;   =(       a    TS   nU4S jn[        5       n[        5       n[        U5         TS   n	[        X5      n
U	" XR                  5       5      nSUl        U(       a  U" U5        [        X5        SSS5        [        [        5       5         [        5         [        XAU [        5       5      nSUl        U(       a  U" U5        SSS5        U$ ! , (       d  f       Na= f! , (       d  f       W$ = f)z
Create Value that is persistable in startup program and main program. The Value is initialized in startup program and
used in main program.

Returns:
    Value: The created Value from main program
r[   r\   Npersistable_valuerp   c                  > SS K nTS   nUR                  R                  R                  R	                  U R                  5       U5      nU R                  U5        UR                  R                  R                  R                  UR                  / U/5      nU R                  5       nXEl
        UR                  S5      (       a  UR                  SU R                  5        g g )Nr   rp   rQ   )r`   rg   rh   ri   rk   rl   rm   rn   r^   ro   rp   has_attrset_int_array_attr_local_shape)rq   r`   rp   ru   rv   	define_oprw   s         r3   rx   )create_persistable_value.<locals>.to_dist  s    ;'	KK))-->>JJL)
	 	y!{{,,00II""B
 ))+	*g&&((%2D2DE 'r5   T)r0   r(   r   r4   r   r   r:   r=   rL   rN   r?   r   r   r	   r   r   )r.   rQ   r   rw   r   r   rx   rJ   rI   r[   r   r   persist_values      `         r3   create_persistable_valuer     s3    F"`
 	
 %**.u5EJ ))*=>
V#;{(;GF  ./O')L		']+&u4!88:
 #'K k6 
( 
+-	.&(Zuw?$(!M" 
/ # 
(	' 
/	. s   AD..6D?.
D<?
Ec                    [        U 5         [        UR                  UR                  UR                  [        5       5      nSUl        SSS5        U$ ! , (       d  f       W$ = f)zX
Get a persistable value from a target program by using value that is in other program.
TN)rL   r   r   rQ   r.   r   r   )target_program
value_infotarget_values      r3   _get_persistable_valuer     sY     
~	&OOZ--z/?/?
 $( 	 
'
  
'	&
 s   <A
A!c                d   U R                  [        5       5        [        U 5         [        UR                  5      nSUl        UR                  Ul        SSS5        [        US5      (       a  UR                  Wl        [        US5      (       a  UR                  Wl	        W$ ! , (       d  f       NT= f)zT
Get a parameter from a target program by using parameter that is in other program.
TNr}   r   )
r   r:   rL   r   r   r   r   hasattrr}   r   )r   
param_infotarget_params      r3   _get_parameterr     s     &&'>'@A	~	& 1#' %/%=%=" 
'
 z=))#-#9#9 z;''!+!5!5 
'	&s   .B!!
B/c                    SSK nSSKJn  [        XR                  5      (       aN  UR                  UR                  R                  R                  5       U 5      nSnX@R                  ;   a  SUl
        U$ U $ )z
Convert Tensor into Value.
r   N)_global_parameter_recorder__non_persistableF)r`   'paddle.jit.dy2static.parameter_recorderr   r(   Tensorr   ri   corer=   r   r   )tensorr`   r   rq   NON_PERSISTABLE_VAR_NAME_SUFFIXs        r3   _convert_into_valuer     si      &--((*..JJOO002F
 +>' +kk9 %EMr5   c              #  b   #    [        U 5      n Sv   [        U5        g! [        U5        f = f7f)z9
Set a hook function to cast the arguments of static op.
Nr   )hookoriginal_callbacks     r3   static_op_arg_cast_guardr     s-      8=;'(9:'(9:s   / /,/c           	        [        U[        5      (       d  [        S[        U5       S35      eSU;   a  SOSnU(       a>  0 nUR	                  5        H'  u  pVUS:X  a  M  XQS   ;   a  US   U   nXdU'   M#  XdU'   M)     OUnUR	                  5        H  u  pV[        U[
        R                  R                  R                  5      (       a  M:  [        U[        R                  5      (       a  [
        R                  " U5      XE'   Ms  [        SU S[        U5       S35      e   Uc  [
        R                  R                  5       nU R                  XB5        g)	a!  
Set parameters and persistable buffers in state_dict to program.
An exception will throw if shape or dtype of the parameters is not match.

.. note::
    This function MUST called after run start_up_program

Args:
    state_dict(dict): the dict store parameters and persistable buffers.
        The key is the name of the parameter or the name of the buffer.
        The value is the tensor of this variable in the given scope.
    scope(Scope, optional) : If scope is None, state_dict will be set to global scope
        obtained through 'paddle.static.global_scope()'. Otherwise, value will be set to scope.
        Default: None

Returns:
    None

Examples:
    .. code-block:: python

        >>> import paddle
        >>> import paddle.static as static

        >>> paddle.enable_static()

        >>> x = static.data(name="x", shape=[10, 10], dtype='float32')
        >>> y = static.nn.fc(x, 10)
        >>> z = static.nn.fc(y, 10)

        >>> place = paddle.CPUPlace()
        >>> exe = static.Executor(place)
        >>> exe.run(static.default_startup_program())
        >>> prog = static.default_main_program()

        >>> path = "./temp/model.pdparams"
        >>> paddle.save(prog.state_dict(), path)
        >>> state_dict_load = paddle.load(path)
        >>> prog.set_state_dict(state_dict_load)
z2Type of `state_dict` should be dict, but received .zStructuredToParameterName@@TFzThe type of `z*` should be Tensor, ndarray, but received N)r(   dict	TypeErrorrl   itemsr`   rg   rh   DenseTensorr-   ndarray	to_tensorstaticglobal_scopeset_state_dict)r@   
state_dictscope	conditionclear_state_dictr   rq   s          r3   r   r     sJ   R j$''@jAQ@RRST
 	
 6CI%++-KD44"?@@!"?@F).&).& . &'--/eV[[22>>??rzz**%+%5%5e%<"v%OPTUZP[}\]^  0 }**,+3r5   )returnr   rP   )[
__future__r   numpyr-   r`   paddle.base.corer   r   paddle.base.libpaddler   paddle.base.libpaddle.pirr   r   r	   r
   r   _pir_opsr   r   r   r   rg   r   	base.corer   base.wrapped_decoratorr   VarTypeFP32FLOAT32FP64FLOAT64FP16FLOAT16BF16BFLOAT16INT32INT16INT64BOOLUINT8INT8	COMPLEX64
COMPLEX128
FP8_E4M3FNFLOAT8_E4M3FNFP8_E5M2FLOAT8_E5M2STRINGPSTRINGRAW	ALL_DTYPEvartype_to_datatyper   datatype_to_vartyper.   r   r   r   r   r   r   r   r   r   r   r   r    r/   UINT16UINT32UINT64_PADDLE_PIR_DTYPE_2_NUMPY_DTYPEr,   r4   r<   r?   r8   r:   r=   rD   rF   rL   rN   r   r   r   r   r   r   r   )kvs   00r3   <module>r      s   #   + *  M L  7 BOO(**OO(** OO(** OO(++	
 OO8>> OO8>> OO8>> OO(-- OO8>> OO(-- OOx11 OO 3 3 OO 6 6 OOh22 OOH,,  OO++! & )<(A(A(CD(Cqt(CD HHY))HHY)) HHY)) HHWx~~	
 HHWx~~ HHWx~~ HHWx}} HHX)) HHWx~~ HHVhmm HH[8-- HH\H// JJ   JJ   JJ    HHhnn!" HHhnn#$ HHhnnHHhmmIIx  HHhnnGGX]]LL($$MM8&&X++8''5 :#MM6#i# x# i	#
 i# MM6# NNG# NNG# NNG# NNG# OOX# OOX# OOX# # #  O!#" -## *xx x X^^	
 X^^ X^^ HMM X]] h X^^ HMM ## (%% !! X++  8''! (?2   !<!<!> ?I :!H.. >4 >4B  
M`9x	"0 	; 	;G4K Es   .\'