neulab/docprompting-conala huggingface dataset:
class torch.nn.Softplus(beta=1, threshold=20) [source]
 
Applies the element-wise function:  Softplus(x)=1β∗log⁡(1+exp⁡(β∗x))\text{Softplus}(x) = \frac{1}{\beta} * \log(1 + \exp(\beta * x))  
SoftPlus is a smooth approximation to the ReLU function and can be used to constrain the output of a machine to always be positive. For numerical stability the implementation reverts to the linear function when input×β>thresholdinput \times \beta > threshold .  Parameters 
 
beta – the β\beta  value for the Softplus formulation. Default: 1 
threshold – values above this revert to a linear function. Default: 20     Shape:

 Input: (N,∗)(N, *)  where * means, any number of additional dimensions Output: (N,∗)(N, *) , same shape as the input     Examples: >>> m = nn.Softplus()
>>> input = torch.randn(2)
>>> output = m(input)
class torch.nn.Softshrink(lambd=0.5) [source]
 
Applies the soft shrinkage function elementwise:  SoftShrinkage(x)={x−λ, if x>λx+λ, if x<−λ0, otherwise \text{SoftShrinkage}(x) = \begin{cases} x - \lambda, & \text{ if } x > \lambda \\ x + \lambda, & \text{ if } x < -\lambda \\ 0, & \text{ otherwise } \end{cases}  
 Parameters 
lambd – the λ\lambda  (must be no less than zero) value for the Softshrink formulation. Default: 0.5    Shape:

 Input: (N,∗)(N, *)  where * means, any number of additional dimensions Output: (N,∗)(N, *) , same shape as the input     Examples: >>> m = nn.Softshrink()
>>> input = torch.randn(2)
>>> output = m(input)
class torch.nn.Softsign [source]
 
Applies the element-wise function:  SoftSign(x)=x1+∣x∣\text{SoftSign}(x) = \frac{x}{ 1 + |x|}  
 Shape:

 Input: (N,∗)(N, *)  where * means, any number of additional dimensions Output: (N,∗)(N, *) , same shape as the input     Examples: >>> m = nn.Softsign()
>>> input = torch.randn(2)
>>> output = m(input)
classmethod convert_sync_batchnorm(module, process_group=None) [source]
 
Helper function to convert all BatchNorm*D layers in the model to torch.nn.SyncBatchNorm layers.  Parameters 
 
module (nn.Module) – module containing one or more attr:BatchNorm*D layers 
process_group (optional) – process group to scope synchronization, default is the whole world   Returns 
The original module with the converted torch.nn.SyncBatchNorm layers. If the original module is a BatchNorm*D layer, a new torch.nn.SyncBatchNorm layer object will be returned instead.   Example: >>> # Network with nn.BatchNorm layer
>>> module = torch.nn.Sequential(
>>>            torch.nn.Linear(20, 100),
>>>            torch.nn.BatchNorm1d(100),
>>>          ).cuda()
>>> # creating process group (optional)
>>> # ranks is a list of int identifying rank ids.
>>> ranks = list(range(8))
>>> r1, r2 = ranks[:4], ranks[4:]
>>> # Note: every rank calls into new_group for every
>>> # process group created, even if that rank is not
>>> # part of the group.
>>> process_groups = [torch.distributed.new_group(pids) for pids in [r1, r2]]
>>> process_group = process_groups[0 if dist.get_rank() <= 3 else 1]
>>> sync_bn_module = torch.nn.SyncBatchNorm.convert_sync_batchnorm(module, process_group)
class torch.nn.Tanh [source]
 
Applies the element-wise function:  Tanh(x)=tanh⁡(x)=exp⁡(x)−exp⁡(−x)exp⁡(x)+exp⁡(−x)\text{Tanh}(x) = \tanh(x) = \frac{\exp(x) - \exp(-x)} {\exp(x) + \exp(-x)}  
 Shape:

 Input: (N,∗)(N, *)  where * means, any number of additional dimensions Output: (N,∗)(N, *) , same shape as the input     Examples: >>> m = nn.Tanh()
>>> input = torch.randn(2)
>>> output = m(input)
class torch.nn.Tanhshrink [source]
 
Applies the element-wise function:  Tanhshrink(x)=x−tanh⁡(x)\text{Tanhshrink}(x) = x - \tanh(x)  
 Shape:

 Input: (N,∗)(N, *)  where * means, any number of additional dimensions Output: (N,∗)(N, *) , same shape as the input     Examples: >>> m = nn.Tanhshrink()
>>> input = torch.randn(2)
>>> output = m(input)
class torch.nn.Threshold(threshold, value, inplace=False) [source]
 
Thresholds each element of the input Tensor. Threshold is defined as:  y={x, if x>thresholdvalue, otherwise y = \begin{cases} x, &\text{ if } x > \text{threshold} \\ \text{value}, &\text{ otherwise } \end{cases}  
 Parameters 
 
threshold – The value to threshold at 
value – The value to replace with 
inplace – can optionally do the operation in-place. Default: False
     Shape:

 Input: (N,∗)(N, *)  where * means, any number of additional dimensions Output: (N,∗)(N, *) , same shape as the input    Examples: >>> m = nn.Threshold(0.1, 20)
>>> input = torch.randn(2)
>>> output = m(input)
forward(src, tgt, src_mask=None, tgt_mask=None, memory_mask=None, src_key_padding_mask=None, tgt_key_padding_mask=None, memory_key_padding_mask=None) [source]
 
Take in and process masked source/target sequences.  Parameters 
 
src – the sequence to the encoder (required). 
tgt – the sequence to the decoder (required). 
src_mask – the additive mask for the src sequence (optional). 
tgt_mask – the additive mask for the tgt sequence (optional). 
memory_mask – the additive mask for the encoder output (optional). 
src_key_padding_mask – the ByteTensor mask for src keys per batch (optional). 
tgt_key_padding_mask – the ByteTensor mask for tgt keys per batch (optional). 
memory_key_padding_mask – the ByteTensor mask for memory keys per batch (optional).     Shape:

 src: (S,N,E)(S, N, E) . tgt: (T,N,E)(T, N, E) . src_mask: (S,S)(S, S) . tgt_mask: (T,T)(T, T) . memory_mask: (T,S)(T, S) . src_key_padding_mask: (N,S)(N, S) . tgt_key_padding_mask: (N,T)(N, T) . memory_key_padding_mask: (N,S)(N, S) .  Note: [src/tgt/memory]_mask ensures that position i is allowed to attend the unmasked positions. If a ByteTensor is provided, the non-zero positions are not allowed to attend while the zero positions will be unchanged. If a BoolTensor is provided, positions with True are not allowed to attend while False values will be unchanged. If a FloatTensor is provided, it will be added to the attention weight. [src/tgt/memory]_key_padding_mask provides specified elements in the key to be ignored by the attention. If a ByteTensor is provided, the non-zero positions will be ignored while the zero positions will be unchanged. If a BoolTensor is provided, the positions with the value of True will be ignored while the position with the value of False will be unchanged.  output: (T,N,E)(T, N, E) .  Note: Due to the multi-head attention architecture in the transformer model, the output sequence length of a transformer is same as the input sequence (i.e. target) length of the decode. where S is the source sequence length, T is the target sequence length, N is the batch size, E is the feature number   Examples >>> output = transformer_model(src, tgt, src_mask=src_mask, tgt_mask=tgt_mask)
generate_square_subsequent_mask(sz) [source]
 
Generate a square mask for the sequence. The masked positions are filled with float(‘-inf’). Unmasked positions are filled with float(0.0).
class torch.nn.TransformerDecoder(decoder_layer, num_layers, norm=None) [source]
 
TransformerDecoder is a stack of N decoder layers  Parameters 
 
decoder_layer – an instance of the TransformerDecoderLayer() class (required). 
num_layers – the number of sub-decoder-layers in the decoder (required). 
norm – the layer normalization component (optional).     Examples::

>>> decoder_layer = nn.TransformerDecoderLayer(d_model=512, nhead=8)
>>> transformer_decoder = nn.TransformerDecoder(decoder_layer, num_layers=6)
>>> memory = torch.rand(10, 32, 512)
>>> tgt = torch.rand(20, 32, 512)
>>> out = transformer_decoder(tgt, memory)
    
forward(tgt, memory, tgt_mask=None, memory_mask=None, tgt_key_padding_mask=None, memory_key_padding_mask=None) [source]
 
Pass the inputs (and mask) through the decoder layer in turn.  Parameters 
 
tgt – the sequence to the decoder (required). 
memory – the sequence from the last layer of the encoder (required). 
tgt_mask – the mask for the tgt sequence (optional). 
memory_mask – the mask for the memory sequence (optional). 
tgt_key_padding_mask – the mask for the tgt keys per batch (optional). 
memory_key_padding_mask – the mask for the memory keys per batch (optional).     Shape:

see the docs in Transformer class.
forward(tgt, memory, tgt_mask=None, memory_mask=None, tgt_key_padding_mask=None, memory_key_padding_mask=None) [source]
 
Pass the inputs (and mask) through the decoder layer in turn.  Parameters 
 
tgt – the sequence to the decoder (required). 
memory – the sequence from the last layer of the encoder (required). 
tgt_mask – the mask for the tgt sequence (optional). 
memory_mask – the mask for the memory sequence (optional). 
tgt_key_padding_mask – the mask for the tgt keys per batch (optional). 
memory_key_padding_mask – the mask for the memory keys per batch (optional).     Shape:

see the docs in Transformer class.
class torch.nn.TransformerDecoderLayer(d_model, nhead, dim_feedforward=2048, dropout=0.1, activation='relu') [source]
 
TransformerDecoderLayer is made up of self-attn, multi-head-attn and feedforward network. This standard decoder layer is based on the paper “Attention Is All You Need”. Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Lukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In Advances in Neural Information Processing Systems, pages 6000-6010. Users may modify or implement in a different way during application.  Parameters 
 
d_model – the number of expected features in the input (required). 
nhead – the number of heads in the multiheadattention models (required). 
dim_feedforward – the dimension of the feedforward network model (default=2048). 
dropout – the dropout value (default=0.1). 
activation – the activation function of intermediate layer, relu or gelu (default=relu).     Examples::

>>> decoder_layer = nn.TransformerDecoderLayer(d_model=512, nhead=8)
>>> memory = torch.rand(10, 32, 512)
>>> tgt = torch.rand(20, 32, 512)
>>> out = decoder_layer(tgt, memory)
    
forward(tgt, memory, tgt_mask=None, memory_mask=None, tgt_key_padding_mask=None, memory_key_padding_mask=None) [source]
 
Pass the inputs (and mask) through the decoder layer.  Parameters 
 
tgt – the sequence to the decoder layer (required). 
memory – the sequence from the last layer of the encoder (required). 
tgt_mask – the mask for the tgt sequence (optional). 
memory_mask – the mask for the memory sequence (optional). 
tgt_key_padding_mask – the mask for the tgt keys per batch (optional). 
memory_key_padding_mask – the mask for the memory keys per batch (optional).     Shape:

see the docs in Transformer class.
forward(tgt, memory, tgt_mask=None, memory_mask=None, tgt_key_padding_mask=None, memory_key_padding_mask=None) [source]
 
Pass the inputs (and mask) through the decoder layer.  Parameters 
 
tgt – the sequence to the decoder layer (required). 
memory – the sequence from the last layer of the encoder (required). 
tgt_mask – the mask for the tgt sequence (optional). 
memory_mask – the mask for the memory sequence (optional). 
tgt_key_padding_mask – the mask for the tgt keys per batch (optional). 
memory_key_padding_mask – the mask for the memory keys per batch (optional).     Shape:

see the docs in Transformer class.
class torch.nn.TransformerEncoder(encoder_layer, num_layers, norm=None) [source]
 
TransformerEncoder is a stack of N encoder layers  Parameters 
 
encoder_layer – an instance of the TransformerEncoderLayer() class (required). 
num_layers – the number of sub-encoder-layers in the encoder (required). 
norm – the layer normalization component (optional).     Examples::

>>> encoder_layer = nn.TransformerEncoderLayer(d_model=512, nhead=8)
>>> transformer_encoder = nn.TransformerEncoder(encoder_layer, num_layers=6)
>>> src = torch.rand(10, 32, 512)
>>> out = transformer_encoder(src)
    
forward(src, mask=None, src_key_padding_mask=None) [source]
 
Pass the input through the encoder layers in turn.  Parameters 
 
src – the sequence to the encoder (required). 
mask – the mask for the src sequence (optional). 
src_key_padding_mask – the mask for the src keys per batch (optional).     Shape:

see the docs in Transformer class.
forward(src, mask=None, src_key_padding_mask=None) [source]
 
Pass the input through the encoder layers in turn.  Parameters 
 
src – the sequence to the encoder (required). 
mask – the mask for the src sequence (optional). 
src_key_padding_mask – the mask for the src keys per batch (optional).     Shape:

see the docs in Transformer class.
class torch.nn.TransformerEncoderLayer(d_model, nhead, dim_feedforward=2048, dropout=0.1, activation='relu') [source]
 
TransformerEncoderLayer is made up of self-attn and feedforward network. This standard encoder layer is based on the paper “Attention Is All You Need”. Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Lukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In Advances in Neural Information Processing Systems, pages 6000-6010. Users may modify or implement in a different way during application.  Parameters 
 
d_model – the number of expected features in the input (required). 
nhead – the number of heads in the multiheadattention models (required). 
dim_feedforward – the dimension of the feedforward network model (default=2048). 
dropout – the dropout value (default=0.1). 
activation – the activation function of intermediate layer, relu or gelu (default=relu).     Examples::

>>> encoder_layer = nn.TransformerEncoderLayer(d_model=512, nhead=8)
>>> src = torch.rand(10, 32, 512)
>>> out = encoder_layer(src)
    
forward(src, src_mask=None, src_key_padding_mask=None) [source]
 
Pass the input through the encoder layer.  Parameters 
 
src – the sequence to the encoder layer (required). 
src_mask – the mask for the src sequence (optional). 
src_key_padding_mask – the mask for the src keys per batch (optional).     Shape:

see the docs in Transformer class.
forward(src, src_mask=None, src_key_padding_mask=None) [source]
 
Pass the input through the encoder layer.  Parameters 
 
src – the sequence to the encoder layer (required). 
src_mask – the mask for the src sequence (optional). 
src_key_padding_mask – the mask for the src keys per batch (optional).     Shape:

see the docs in Transformer class.
class torch.nn.TripletMarginLoss(margin=1.0, p=2.0, eps=1e-06, swap=False, size_average=None, reduce=None, reduction='mean') [source]
 
Creates a criterion that measures the triplet loss given an input tensors x1x1 , x2x2 , x3x3  and a margin with a value greater than 00 . This is used for measuring a relative similarity between samples. A triplet is composed by a, p and n (i.e., anchor, positive examples and negative examples respectively). The shapes of all input tensors should be (N,D)(N, D) . The distance swap is described in detail in the paper Learning shallow convolutional feature descriptors with triplet losses by V. Balntas, E. Riba et al. The loss function for each sample in the mini-batch is:  L(a,p,n)=max⁡{d(ai,pi)−d(ai,ni)+margin,0}L(a, p, n) = \max \{d(a_i, p_i) - d(a_i, n_i) + {\rm margin}, 0\}  
where  d(xi,yi)=∥xi−yi∥pd(x_i, y_i) = \left\lVert {\bf x}_i - {\bf y}_i \right\rVert_p  
See also TripletMarginWithDistanceLoss, which computes the triplet margin loss for input tensors using a custom distance function.  Parameters 
 
margin (float, optional) – Default: 11 . 
p (int, optional) – The norm degree for pairwise distance. Default: 22 . 
swap (bool, optional) – The distance swap is described in detail in the paper Learning shallow convolutional feature descriptors with triplet losses by V. Balntas, E. Riba et al. Default: False. 
size_average (bool, optional) – Deprecated (see reduction). By default, the losses are averaged over each loss element in the batch. Note that for some losses, there are multiple elements per sample. If the field size_average is set to False, the losses are instead summed for each minibatch. Ignored when reduce is False. Default: True
 
reduce (bool, optional) – Deprecated (see reduction). By default, the losses are averaged or summed over observations for each minibatch depending on size_average. When reduce is False, returns a loss per batch element instead and ignores size_average. Default: True
 
reduction (string, optional) – Specifies the reduction to apply to the output: 'none' | 'mean' | 'sum'. 'none': no reduction will be applied, 'mean': the sum of the output will be divided by the number of elements in the output, 'sum': the output will be summed. Note: size_average and reduce are in the process of being deprecated, and in the meantime, specifying either of those two args will override reduction. Default: 'mean'
     Shape:

 Input: (N,D)(N, D)  where DD  is the vector dimension. 
 
Output: A Tensor of shape (N)(N)  if reduction is 'none', or a scalar 

otherwise.       >>> triplet_loss = nn.TripletMarginLoss(margin=1.0, p=2)
>>> anchor = torch.randn(100, 128, requires_grad=True)
>>> positive = torch.randn(100, 128, requires_grad=True)
>>> negative = torch.randn(100, 128, requires_grad=True)
>>> output = triplet_loss(anchor, positive, negative)
>>> output.backward()
class torch.nn.UpsamplingBilinear2d(size=None, scale_factor=None) [source]
 
Applies a 2D bilinear upsampling to an input signal composed of several input channels. To specify the scale, it takes either the size or the scale_factor as it’s constructor argument. When size is given, it is the output size of the image (h, w).  Parameters 
 
size (int or Tuple[int, int], optional) – output spatial sizes 
scale_factor (float or Tuple[float, float], optional) – multiplier for spatial size.     Warning This class is deprecated in favor of interpolate(). It is equivalent to nn.functional.interpolate(..., mode='bilinear', align_corners=True).   Shape:

 Input: (N,C,Hin,Win)(N, C, H_{in}, W_{in}) 
 Output: (N,C,Hout,Wout)(N, C, H_{out}, W_{out})  where     Hout=⌊Hin×scale_factor⌋H_{out} = \left\lfloor H_{in} \times \text{scale\_factor} \right\rfloor  
 Wout=⌊Win×scale_factor⌋W_{out} = \left\lfloor W_{in} \times \text{scale\_factor} \right\rfloor  
Examples: >>> input = torch.arange(1, 5, dtype=torch.float32).view(1, 1, 2, 2)
>>> input
tensor([[[[ 1.,  2.],
          [ 3.,  4.]]]])

>>> m = nn.UpsamplingBilinear2d(scale_factor=2)
>>> m(input)
tensor([[[[ 1.0000,  1.3333,  1.6667,  2.0000],
          [ 1.6667,  2.0000,  2.3333,  2.6667],
          [ 2.3333,  2.6667,  3.0000,  3.3333],
          [ 3.0000,  3.3333,  3.6667,  4.0000]]]])
class torch.nn.UpsamplingNearest2d(size=None, scale_factor=None) [source]
 
Applies a 2D nearest neighbor upsampling to an input signal composed of several input channels. To specify the scale, it takes either the size or the scale_factor as it’s constructor argument. When size is given, it is the output size of the image (h, w).  Parameters 
 
size (int or Tuple[int, int], optional) – output spatial sizes 
scale_factor (float or Tuple[float, float], optional) – multiplier for spatial size.     Warning This class is deprecated in favor of interpolate().   Shape:

 Input: (N,C,Hin,Win)(N, C, H_{in}, W_{in}) 
 Output: (N,C,Hout,Wout)(N, C, H_{out}, W_{out})  where     Hout=⌊Hin×scale_factor⌋H_{out} = \left\lfloor H_{in} \times \text{scale\_factor} \right\rfloor  
 Wout=⌊Win×scale_factor⌋W_{out} = \left\lfloor W_{in} \times \text{scale\_factor} \right\rfloor  
Examples: >>> input = torch.arange(1, 5, dtype=torch.float32).view(1, 1, 2, 2)
>>> input
tensor([[[[ 1.,  2.],
          [ 3.,  4.]]]])

>>> m = nn.UpsamplingNearest2d(scale_factor=2)
>>> m(input)
tensor([[[[ 1.,  1.,  2.,  2.],
          [ 1.,  1.,  2.,  2.],
          [ 3.,  3.,  4.,  4.],
          [ 3.,  3.,  4.,  4.]]]])
torch.nn.utils.clip_grad_norm_(parameters, max_norm, norm_type=2.0) [source]
 
Clips gradient norm of an iterable of parameters. The norm is computed over all gradients together, as if they were concatenated into a single vector. Gradients are modified in-place.  Parameters 
 
parameters (Iterable[Tensor] or Tensor) – an iterable of Tensors or a single Tensor that will have gradients normalized 
max_norm (float or int) – max norm of the gradients 
norm_type (float or int) – type of the used p-norm. Can be 'inf' for infinity norm.   Returns 
Total norm of the parameters (viewed as a single vector).
torch.nn.utils.clip_grad_value_(parameters, clip_value) [source]
 
Clips gradient of an iterable of parameters at specified value. Gradients are modified in-place.  Parameters 
 
parameters (Iterable[Tensor] or Tensor) – an iterable of Tensors or a single Tensor that will have gradients normalized 
clip_value (float or int) – maximum allowed value of the gradients. The gradients are clipped in the range [-clip_value,clip_value]\left[\text{-clip\_value}, \text{clip\_value}\right]
torch.nn.utils.parameters_to_vector(parameters) [source]
 
Convert parameters to one vector  Parameters 
parameters (Iterable[Tensor]) – an iterator of Tensors that are the parameters of a model.  Returns 
The parameters represented by a single vector
classmethod apply(module, name, *args, importance_scores=None, **kwargs) [source]
 
Adds the forward pre-hook that enables pruning on the fly and the reparametrization of a tensor in terms of the original tensor and the pruning mask.  Parameters 
 
module (nn.Module) – module containing the tensor to prune 
name (str) – parameter name within module on which pruning will act. 
args – arguments passed on to a subclass of BasePruningMethod
 
importance_scores (torch.Tensor) – tensor of importance scores (of same shape as module parameter) used to compute mask for pruning. The values in this tensor indicate the importance of the corresponding elements in the parameter being pruned. If unspecified or None, the parameter will be used in its place. 
kwargs – keyword arguments passed on to a subclass of a BasePruningMethod
apply_mask(module) [source]
 
Simply handles the multiplication between the parameter being pruned and the generated mask. Fetches the mask and the original tensor from the module and returns the pruned version of the tensor.  Parameters 
module (nn.Module) – module containing the tensor to prune  Returns 
pruned version of the input tensor  Return type 
pruned_tensor (torch.Tensor)
abstract compute_mask(t, default_mask) [source]
 
Computes and returns a mask for the input tensor t. Starting from a base default_mask (which should be a mask of ones if the tensor has not been pruned yet), generate a random mask to apply on top of the default_mask according to the specific pruning method recipe.  Parameters 
 
t (torch.Tensor) – tensor representing the importance scores of the 
to prune. (parameter) –  
default_mask (torch.Tensor) – Base mask from previous pruning 
that need to be respected after the new mask is (iterations,) –  
Same dims as t. (applied.) –    Returns 
mask to apply to t, of same dims as t  Return type 
mask (torch.Tensor)
prune(t, default_mask=None, importance_scores=None) [source]
 
Computes and returns a pruned version of input tensor t according to the pruning rule specified in compute_mask().  Parameters 
 
t (torch.Tensor) – tensor to prune (of same dimensions as default_mask). 
importance_scores (torch.Tensor) – tensor of importance scores (of same shape as t) used to compute mask for pruning t. The values in this tensor indicate the importance of the corresponding elements in the t that is being pruned. If unspecified or None, the tensor t will be used in its place. 
default_mask (torch.Tensor, optional) – mask from previous pruning iteration, if any. To be considered when determining what portion of the tensor that pruning should act on. If None, default to a mask of ones.   Returns 
pruned version of tensor t.
remove(module) [source]
 
Removes the pruning reparameterization from a module. The pruned parameter named name remains permanently pruned, and the parameter named name+'_orig' is removed from the parameter list. Similarly, the buffer named name+'_mask' is removed from the buffers.  Note Pruning itself is NOT undone or reversed!