/usr/local/lib64/python3.6/site-packages/torch/nn/__pycache__
NameSizeModeActions
common_types.cpython-36.pyc9900644editdlrm
cpp.cpython-36.pyc34600644editdlrm
functional.cpython-36.pyc1616480644editdlrm
grad.cpython-36.pyc118400644editdlrm
init.cpython-36.pyc175510644editdlrm
parameter.cpython-36.pyc75680644editdlrm
_reduction.cpython-36.pyc12440644editdlrm
__init__.cpython-36.pyc20020644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/nn/__pycache__/init.cpython-36.pyc (17551B)
3 Eg`K@sddlZddlZddlmZddlZddZddZddZd d Zd d Zd>d dZ d?ee e edddZ d@ee e edddZ dBee e e e edddZ ee edddZeeddd Zeedd!d"Zd#d$ZdCd&d'Zd(d)ZdDee ed*d+d,ZdEee ed*d-d.Zd/d0ZdFd3d4ZdGd5d6ZdHd7d8ZdId:d;Zd.norm_cdfzjmean is more than 2 std from [a, b] in nn.init.trunc_normal_. The distribution of values may be incorrect.) stacklevelg@)minmax) warningswarnrrrZerfinv_mul_rrZadd_Zclamp_)rr rrrrlur r r _no_grad_trunc_normal_s   rc Cstj |j|SQRXdS)N)rrZfill_)rvalr r r _no_grad_fill_9s r!c Cstj |jSQRXdS)N)rrzero_)rr r r _no_grad_zero_>s r#cCsdddddddg}||ks"|dkr&d S|d kr2dS|d krDtjdS|dkr|dkrZd}n4t|t rpt|tszt|tr|}ntdj|tjdd |dS|dkrdStdj|dS)aReturn the recommended gain value for the given nonlinearity function. The values are as follows: ================= ==================================================== nonlinearity gain ================= ==================================================== Linear / Identity :math:`1` Conv{1,2,3}D :math:`1` Sigmoid :math:`1` Tanh :math:`\frac{5}{3}` ReLU :math:`\sqrt{2}` Leaky Relu :math:`\sqrt{\frac{2}{1 + \text{negative\_slope}^2}}` SELU :math:`\frac{3}{4}` ================= ==================================================== .. warning:: In order to implement `Self-Normalizing Neural Networks`_ , you should use ``nonlinearity='linear'`` instead of ``nonlinearity='selu'``. This gives the initial weights a variance of ``1 / N``, which is necessary to induce a stable fixed point in the forward pass. In contrast, the default gain for ``SELU`` sacrifices the normalisation effect for more stable gradient flow in rectangular layers. Args: nonlinearity: the non-linear function (`nn.functional` name) param: optional parameter for the non-linear function Examples: >>> gain = nn.init.calculate_gain('leaky_relu', 0.2) # leaky_relu with negative_slope=0.2 .. _Self-Normalizing Neural Networks: https://papers.nips.cc/paper/2017/hash/5d44ee6f2c3f71b73125876103c8f6c4-Abstract.html ZlinearZconv1dZconv2dZconv3dZconv_transpose1dZconv_transpose2dZconv_transpose3dZsigmoidrtanhg@Zrelug@ leaky_reluNg{Gz?z$negative_slope {} not a valid numberrZselug@zUnsupported nonlinearity {}g?g?)rr isinstanceboolintfloat ValueErrorformat) nonlinearityparamZ linear_fnsZnegative_sloper r r calculate_gainCs"!  r0?)rrrreturncCs t|||S)adFills the input Tensor with values drawn from the uniform distribution :math:`\mathcal{U}(a, b)`. Args: tensor: an n-dimensional `torch.Tensor` a: the lower bound of the uniform distribution b: the upper bound of the uniform distribution Examples: >>> w = torch.empty(3, 5) >>> nn.init.uniform_(w) )r )rrrr r r rzs r)rr rr3cCs t|||S)azFills the input Tensor with values drawn from the normal distribution :math:`\mathcal{N}(\text{mean}, \text{std}^2)`. Args: tensor: an n-dimensional `torch.Tensor` mean: the mean of the normal distribution std: the standard deviation of the normal distribution Examples: >>> w = torch.empty(3, 5) >>> nn.init.normal_(w) )r)rr rr r r r s r @)rr rrrr3cCst|||||S)aFills the input Tensor with values drawn from a truncated normal distribution. The values are effectively drawn from the normal distribution :math:`\mathcal{N}(\text{mean}, \text{std}^2)` with values outside :math:`[a, b]` redrawn until they are within the bounds. The method used for generating the random values works best when :math:`a \leq \text{mean} \leq b`. Args: tensor: an n-dimensional `torch.Tensor` mean: the mean of the normal distribution std: the standard deviation of the normal distribution a: the minimum cutoff value b: the maximum cutoff value Examples: >>> w = torch.empty(3, 5) >>> nn.init.trunc_normal_(w) )r)rr rrrr r r trunc_normal_sr5)rr r3cCs t||S)zFills the input Tensor with the value :math:`\text{val}`. Args: tensor: an n-dimensional `torch.Tensor` val: the value to fill the tensor with Examples: >>> w = torch.empty(3, 5) >>> nn.init.constant_(w, 0.3) )r!)rr r r r constant_s r6)rr3cCs t|dS)zFills the input Tensor with the scalar value `1`. Args: tensor: an n-dimensional `torch.Tensor` Examples: >>> w = torch.empty(3, 5) >>> nn.init.ones_(w) g?)r!)rr r r ones_s r7cCst|S)zFills the input Tensor with the scalar value `0`. Args: tensor: an n-dimensional `torch.Tensor` Examples: >>> w = torch.empty(3, 5) >>> nn.init.zeros_(w) )r#)rr r r zeros_s r8c CsB|jdkrtdtjtj|j||jdWdQRX|S)a=Fills the 2-dimensional input `Tensor` with the identity matrix. Preserves the identity of the inputs in `Linear` layers, where as many inputs are preserved as possible. Args: tensor: a 2-dimensional `torch.Tensor` Examples: >>> w = torch.empty(3, 5) >>> nn.init.eye_(w) rz,Only tensors with 2 dimensions are supported)out requires_gradN) ndimensionr,rreyeshaper:)rr r r eye_s   r>rcCs.|j}|d krtd|j}|d|dkr8td|d|}t||d}tj|jxt|D]}xt|D]}|dkrd||||||jddf<q||dkrd||||||jdd|jddf<q|d||||||jdd|jdd|jddf<q|WqnWWd QRX|S) aAFills the {3, 4, 5}-dimensional input `Tensor` with the Dirac delta function. Preserves the identity of the inputs in `Convolutional` layers, where as many input channels are preserved as possible. In case of groups>1, each group of channels preserves identity Args: tensor: a {3, 4, 5}-dimensional `torch.Tensor` groups (optional): number of groups in the conv layer (default: 1) Examples: >>> w = torch.empty(3, 16, 5, 5) >>> nn.init.dirac_(w) >>> w = torch.empty(3, 24, 5, 5) >>> nn.init.dirac_(w, 3) r%r'z5Only tensors with 3, 4, or 5 dimensions are supportedrz!dim 0 must be divisible by groupsrrN)r%r'r?)r;r,sizerrrr"range)rgroups dimensionssizesZout_chans_per_grpZmin_dimgdr r r dirac_s$  ".JrGcCst|j}|dkrtd|jd}|jd}d}|jdkr\x|jddD] }||9}qLW||}||}||fS)NrzNFan in and fan out can not be computed for tensor with fewer than 2 dimensionsrr)Zdimr,r@r=)rrCZnum_input_fmapsZnum_output_fmapsZreceptive_field_sizesfan_infan_outr r r _calculate_fan_in_and_fan_outs    rK)rgainr3cCsBt|\}}|tjdt||}tjd|}t|| |S)aFills the input `Tensor` with values according to the method described in `Understanding the difficulty of training deep feedforward neural networks` - Glorot, X. & Bengio, Y. (2010), using a uniform distribution. The resulting tensor will have values sampled from :math:`\mathcal{U}(-a, a)` where .. math:: a = \text{gain} \times \sqrt{\frac{6}{\text{fan\_in} + \text{fan\_out}}} Also known as Glorot initialization. Args: tensor: an n-dimensional `torch.Tensor` gain: an optional scaling factor Examples: >>> w = torch.empty(3, 5) >>> nn.init.xavier_uniform_(w, gain=nn.init.calculate_gain('relu')) g@g@)rKrrr+r )rrLrIrJrrr r r xavier_uniform_)s rMcCs2t|\}}|tjdt||}t|d|S)aFills the input `Tensor` with values according to the method described in `Understanding the difficulty of training deep feedforward neural networks` - Glorot, X. & Bengio, Y. (2010), using a normal distribution. The resulting tensor will have values sampled from :math:`\mathcal{N}(0, \text{std}^2)` where .. math:: \text{std} = \text{gain} \times \sqrt{\frac{2}{\text{fan\_in} + \text{fan\_out}}} Also known as Glorot initialization. Args: tensor: an n-dimensional `torch.Tensor` gain: an optional scaling factor Examples: >>> w = torch.empty(3, 5) >>> nn.init.xavier_normal_(w) g@g)rKrrr+r)rrLrIrJrr r r xavier_normal_Ds rNcCsD|j}ddg}||kr(tdj||t|\}}|dkr@|S|S)NrIrJz+Mode {} not supported, please use one of {})lowerr,r-rK)rmodeZ valid_modesrIrJr r r _calculate_correct_fan^s  rQrIr&c Csjd|jkrtjd|St||}t||}|tj|}tjd|}tj|j | |SQRXdS)aFills the input `Tensor` with values according to the method described in `Delving deep into rectifiers: Surpassing human-level performance on ImageNet classification` - He, K. et al. (2015), using a uniform distribution. The resulting tensor will have values sampled from :math:`\mathcal{U}(-\text{bound}, \text{bound})` where .. math:: \text{bound} = \text{gain} \times \sqrt{\frac{3}{\text{fan\_mode}}} Also known as He initialization. Args: tensor: an n-dimensional `torch.Tensor` a: the negative slope of the rectifier used after this layer (only used with ``'leaky_relu'``) mode: either ``'fan_in'`` (default) or ``'fan_out'``. Choosing ``'fan_in'`` preserves the magnitude of the variance of the weights in the forward pass. Choosing ``'fan_out'`` preserves the magnitudes in the backwards pass. nonlinearity: the non-linear function (`nn.functional` name), recommended to use only with ``'relu'`` or ``'leaky_relu'`` (default). Examples: >>> w = torch.empty(3, 5) >>> nn.init.kaiming_uniform_(w, mode='fan_in', nonlinearity='relu') rz,Initializing zero-element tensors is a no-opg@N) r=rrrQr0rrrrr)rrrPr.fanrLrboundr r r kaiming_uniform_hs     rTc CsZd|jkrtjd|St||}t||}|tj|}tj|j d|SQRXdS)aFills the input `Tensor` with values according to the method described in `Delving deep into rectifiers: Surpassing human-level performance on ImageNet classification` - He, K. et al. (2015), using a normal distribution. The resulting tensor will have values sampled from :math:`\mathcal{N}(0, \text{std}^2)` where .. math:: \text{std} = \frac{\text{gain}}{\sqrt{\text{fan\_mode}}} Also known as He initialization. Args: tensor: an n-dimensional `torch.Tensor` a: the negative slope of the rectifier used after this layer (only used with ``'leaky_relu'``) mode: either ``'fan_in'`` (default) or ``'fan_out'``. Choosing ``'fan_in'`` preserves the magnitude of the variance of the weights in the forward pass. Choosing ``'fan_out'`` preserves the magnitudes in the backwards pass. nonlinearity: the non-linear function (`nn.functional` name), recommended to use only with ``'relu'`` or ``'leaky_relu'`` (default). Examples: >>> w = torch.empty(3, 5) >>> nn.init.kaiming_normal_(w, mode='fan_out', nonlinearity='relu') rz,Initializing zero-element tensors is a no-opN) r=rrrQr0rrrrr )rrrPr.rRrLrr r r kaiming_normal_s     rUc Cs|jdkrtd|jd}|j|}|j||jdd}||krN|jtjj |\}}tj |d}|j }||9}||kr|jtj |j |j||j|WdQRX|S)a!Fills the input `Tensor` with a (semi) orthogonal matrix, as described in `Exact solutions to the nonlinear dynamics of learning in deep linear neural networks` - Saxe, A. et al. (2013). The input tensor must have at least 2 dimensions, and for tensors with more than 2 dimensions the trailing dimensions are flattened. Args: tensor: an n-dimensional `torch.Tensor`, where :math:`n \geq 2` gain: optional scaling factor Examples: >>> w = torch.empty(3, 5) >>> nn.init.orthogonal_(w) rz4Only tensors with 2 or more dimensions are supportedrrN)r;r,r@Znumelnewr Zt_rZlinalgZqrZdiagsignrZview_asZcopy_r) rrLrowscolsZ flattenedqrrFphr r r orthogonal_s"     r]{Gz?c Cs|jdkrtd|j\}}ttj||}tjF|jd|x2t |D]&}tj |}|d|}d|||f<qPWWdQRX|S)aNFills the 2D input `Tensor` as a sparse matrix, where the non-zero elements will be drawn from the normal distribution :math:`\mathcal{N}(0, 0.01)`, as described in `Deep learning via Hessian-free optimization` - Martens, J. (2010). Args: tensor: an n-dimensional `torch.Tensor` sparsity: The fraction of elements in each column to be set to zero std: the standard deviation of the normal distribution used to generate the non-zero values Examples: >>> w = torch.empty(3, 5) >>> nn.init.sparse_(w, sparsity=0.1) rz,Only tensors with 2 dimensions are supportedrN) r;r,r=r*rceilrrr rAZrandperm) rZsparsityrrXrYZ num_zerosZcol_idxZ row_indicesZ zero_indicesr r r sparse_s      r`cs<jddfdd}djd|_|_|S)Nrcs tjdjdd||S)Nz4nn.init.{} is now deprecated in favor of nn.init.{}.r)r)rrr-)argskwargs)methnew_nameold_namer r deprecated_initsz(_make_deprecate..deprecated_initz {old_name}(...) .. warning:: This method is now deprecated in favor of :func:`torch.nn.init.{new_name}`. See :func:`~torch.nn.init.{new_name}` for details.)rerd)__name__r-__doc__)rcrfr )rcrdrer _make_deprecates   rj)N)r1r2)r1r2)r1r2rkr4)r)r2)r2)rrIr&)rrIr&)r)r^)'rrrrr rrr!r#r0r+rr r5r6r7r8r>rGrKrMrNrQrTrUr]r`rjuniformnormalZconstantr<ZdiracZxavier_uniformZ xavier_normalZkaiming_uniformZkaiming_normalZ orthogonalsparser r r r sJ # 7   + & % )