
    Αi2                        S SK Jr  S SKJrJrJrJr  S SKrS SK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	KJr  / r " S
 S5      r " S S\5      rg)    )annotations)TYPE_CHECKINGAnyClassVaroverloadN)
check_type)WeightDecayRegularizer)Sequence)Tensor)ParamAttrLike)Initializerc                  0   \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'   S\S'   S\S'          S               SS jjrSS jrSS jrSS jr	\
\SS j5       5       r\
\SS j5       5       r\
\S S j5       5       r\S 5       rS!S"S jjrSrg)#	ParamAttr!   a	  

Note:
    ``gradient_clip`` of ``ParamAttr`` HAS BEEN DEPRECATED since 2.0.
    Please use ``need_clip`` in ``ParamAttr`` to specify the clip scope.
    There are three clipping strategies: :ref:`api_paddle_nn_ClipGradByGlobalNorm` ,
    :ref:`api_paddle_nn_ClipGradByNorm` , :ref:`api_paddle_nn_ClipGradByValue` .

Create a object to represent the attribute of parameter. The attributes are:
name, initializer, learning rate, regularizer, trainable, gradient clip,
and model average.

Parameters:
    name (str, optional): The parameter's name. Default None, meaning that the name
            would be created automatically.
    initializer (Initializer, optional): The method to initial this parameter. Default
            None, meaning that the weight parameter is initialized by Xavier initializer,
            and the bias parameter is initialized by 0.
    learning_rate (float, optional): The parameter's learning rate. The learning rate when
            optimize is the global learning rates times the parameter's learning rate times
            the factor of learning rate scheduler. Default 1.0.
    regularizer (WeightDecayRegularizer, optional): Regularization strategy. There are two method:
            :ref:`api_paddle_regularizer_L1Decay` , :ref:`api_paddle_regularizer_L2Decay` . If
            regularizer is also set in ``optimizer`` (such as :ref:`api_paddle_optimizer_SGD` ),
            that regularizer setting in optimizer will be ignored. Default None, meaning there is
            no regularization.
    trainable (bool, optional): Whether this parameter is trainable. Default True.
    do_model_average (bool, optional): Whether this parameter should do model average
            when model average is enabled. Only used in ExponentialMovingAverage. Default True.
    need_clip (bool, optional): Whether the parameter gradient need to be clipped in optimizer. Default is True.

Returns:
    ParamAttr Object.

Examples:

    .. code-block:: python

        >>> import paddle

        >>> weight_attr = paddle.ParamAttr(
        ...     name="weight",
        ...     learning_rate=0.5,
        ...     regularizer=paddle.regularizer.L2Decay(1.0),
        ...     trainable=True,
        ... )
        >>> print(weight_attr.name)
        weight
        >>> paddle.nn.Linear(3, 4, weight_attr=weight_attr)

str | NonenameInitializer | Noneinitializerfloatlearning_rateWeightDecayRegularizer | Noneregularizerbool	trainabledo_model_average	need_clipNc                   [        US[        [        S 5      4S5        [        US[        [        4S5        [        US[
        S5        [        US[
        S5        [        US[
        S5        [        US[        R                  R                  R                  [        S 5      4S5        [        US[        [        S 5      4S5        Xl        U R                  S	:X  a  [        S
5      eX l        X0l        X@l        XPl        X`l        Xpl        g )Nr   r   r   r   r   r   r   r    z&name of ParamAttr can not be empty str)r   strtyper   intr   paddlennr   r   r	   r   
ValueErrorr   r   r   r   r   )selfr   r   r   r   r   r   r   s           V/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/base/param_attr.py__init__ParamAttr.__init__]   s     	4#tDz!2K@=/E3<M9k4=#%7{K9k4=YY""..T
;		
 	#T$Z0		
 	99?EFF&*&" 0"    c                d    Uc  U R                   c  [        S5      egU R                   b  gXl         g)z
Set the default initializer, the initializer should be Constant,
Uniform, Normal, Xavier, MSRA.

Args:
    initializer(Initializer): the initializer to set.

Returns:
    None
Nz ParamAttr.initializer is not set)r   r$   )r%   r   s     r&   _set_default_initializer"ParamAttr._set_default_initializer   s:     ' !CDD'&r)   c                r    U R                  [        R                  R                  R	                  5       5        g)za
Set the default initializer for the parameter with Xavier.

Args:
    None.

Returns:
    None.
N)r+   r"   r#   r   XavierUniformr%   s    r&   _set_default_param_initializer(ParamAttr._set_default_param_initializer   s%     	%%fii&;&;&I&I&KLr)   c                t    U R                  [        R                  R                  R	                  S5      5        g)zc
Set the default initializer for the bias with Constant(0.0).

Args:
    None.

Returns:
    None.
g        N)r+   r"   r#   r   Constantr/   s    r&   _set_default_bias_initializer'ParamAttr._set_default_bias_initializer   s'     	%%fii&;&;&D&DS&IJr)   c                    g N args    r&   _to_attrParamAttr._to_attr   s    *-r)   c                    g r7   r8   r9   s    r&   r;   r<      s    36r)   c                    g r7   r8   r9   s    r&   r;   r<      s    CFr)   c                Z   U c
  [        5       $ [        U [        [        45      (       a&  U  Vs/ s H  n[         R	                  U5      PM     sn$ [        U [         5      (       a  U $ [        U [
        5      (       a	  [        U S9$ [        U [        R                  R                  R                  5      (       a	  [        U S9$ [        U [        5      (       a	  [        U S9$ [        U [        5      (       a  U (       a  [         R	                  S5      $ S$ [        [        U 5       S35      es  snf )aO  
Create ParamAttr[s].

Args:
    arg: Arguments to initialize ParamAttr[s]. arg's type can be
        str, Initializer, float, WeightDecayRegularizer, BaseGradientClipAttr,
        bool, ParamAttr, or a list of above type.

Returns:
    ParamAttr[s]: ParamAttr[s] initialized with arg.

Raises:
    arg can not initialize a ParamAttr.
N)r   )r   )r   Fz cast to ParamAttr)r   
isinstancelisttupler;   r   r"   r#   r   r   r	   r   	TypeErrorr    )r:   as     r&   r;   r<      s      ;;dE]++3673aI&&q)377Y''JS!!#&&VYY22>>??--344--T""/29%%d+==tCyk);<== 8s   D(c                    U R                   SU R                  0U R                  U R                  U R                  U R
                  S.nU(       a  U R                  US'   U$ )z
Returns the attributes of this parameter.

Args:
    with_initializer(bool): Whether to add initializer attr.

Returns:
    Parameter attributes(map): The attributes of this parameter.
r   )r   optimize_attrr   r   r   r   r   )r   r   r   r   r   r   r   )r%   with_initializerkwargss      r&   
_to_kwargsParamAttr._to_kwargs   sZ     II-t/A/AB++ $ 5 5
 $($4$4F=!r)   )r   r   r   r   r   r   r   )NN      ?NTTT)r   r   r   r   r   r   r   r   r   r   r   r   r   r   returnNone)r   r   rL   rM   )rL   rM   )r:   rM   rL   r   )r:   r   rL   r   )r:   zSequence[ParamAttrLike]rL   zlist[ParamAttr])F)rG   r   rL   zdict[str, Any])__name__
__module____qualname____firstlineno____doc____annotations__r'   r+   r0   r4   r   staticmethodr;   rI   __static_attributes__r8   r)   r&   r   r   !   s   1f ##..OO  *."59!%%#%# (%# 	%#
 3%# %# %# %# 
%#N'*
M
K -  -6  6F  F> >@ r)   r   c                     ^  \ rS rSr% Sr/ rS\S'   S\S'           S	                 S
U 4S jjjrSrU =r	$ )WeightNormParamAttr   a  

Note:
    Please use 'paddle.nn.utils.weight_norm' in dygraph mode.

Note:
    ``gradient_clip`` of ``ParamAttr`` HAS BEEN DEPRECATED since 2.0.
    Please use ``need_clip`` in ``ParamAttr`` to specify the clip scope.
    There are three clipping strategies: :ref:`api_paddle_nn_ClipGradByGlobalNorm` ,
    :ref:`api_paddle_nn_ClipGradByNorm` , :ref:`api_paddle_nn_ClipGradByValue` .

Parameter of weight Norm. Weight Norm is a reparameterization of the weight vectors
in a neural network that decouples the magnitude of those weight vectors from
their direction. Weight Norm has been implemented as discussed in this
paper: `Weight Normalization: A Simple Reparameterization to Accelerate
Training of Deep Neural Networks
<https://arxiv.org/pdf/1602.07868.pdf>`_.

Args:
    dim(int, optional): Dimension over which to compute the norm. Dim is a non-negative
        number which is less than the rank of weight Tensor. For Example, dim can
        be chosen from 0, 1, 2, 3 for convolution whose weight shape is [cout, cin, kh, kw]
        and rank is 4. Default None, meaning that all elements will be normalized.
    name(str, optional): The parameter's name. Default None, meaning that the name would
        be created automatically. Please refer to :ref:`api_guide_Name` for more details.
    initializer(Initializer, optional): The method to initialize this parameter, such as
        ``initializer = paddle.nn.initializer.Constant(1.0)``. Default None,
        meaning that the weight parameter is initialized by Xavier initializer, and
        the bias parameter is initialized by 0.
    learning_rate(float32, optional): The parameter's learning rate when
        optimizer is :math:`global\_lr * parameter\_lr * scheduler\_factor`.
        Default 1.0.
    regularizer (WeightDecayRegularizer, optional): Regularization strategy. There are
        two method: :ref:`api_paddle_regularizer_L1Decay` ,
        :ref:`api_paddle_regularizer_L2Decay`.
        If regularizer is also set in ``optimizer``
        (such as :ref:`api_paddle_optimizer_SGD` ), that regularizer setting in
        optimizer will be ignored. Default None, meaning there is no regularization.
    trainable(bool, optional): Whether this parameter is trainable. Default True.
    do_model_average(bool, optional): Whether this parameter should do model average.
        Default False.
    need_clip (bool, optional): Whether the parameter gradient need to be clipped in optimizer. Default is True.

Examples:

    .. code-block:: python

        >>> import paddle

        >>> paddle.enable_static()

        >>> data = paddle.static.data(name="data", shape=[3, 32, 32], dtype="float32")

        >>> fc = paddle.static.nn.fc(
        ...     x=data,
        ...     size=1000,
        ...     weight_attr=paddle.static.WeightNormParamAttr(
        ...         dim=None,
        ...         name='weight_norm_param',
        ...         initializer=paddle.nn.initializer.Constant(1.0),
        ...         learning_rate=1.0,
        ...         regularizer=paddle.regularizer.L2Decay(0.1),
        ...         trainable=True,
        ...         do_model_average=False,
        ...         need_clip=True,
        ...     ),
        ... )
zClassVar[list[Tensor]]params_with_weight_norm
int | Nonedimc	           
     8   > [         T	U ]  UUUUUUUS9  Xl        g )N)r   r   r   r   r   r   r   )superr'   r[   )
r%   r[   r   r   r   r   r   r   r   	__class__s
            r&   r'   WeightNormParamAttr.__init__C  s3     	#'#- 	 	
 r)   )r[   )NNNrK   NTFT)r[   rZ   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rL   rM   )
rN   rO   rP   rQ   rR   rY   rS   r'   rU   __classcell__)r^   s   @r&   rW   rW      s    CR 7938	O *."59!&  (	
  3    
 r)   rW   )
__future__r   typingr   r   r   r   r"   paddle.base.data_feederr   paddle.regularizerr	   collections.abcr
   r   paddle._typingr   paddle.nn.initializerr   __all__r   rW   r8   r)   r&   <module>ri      sJ    # 9 9  . 5(,1 Q Qhb) br)   