neulab/docprompting-conala huggingface dataset:
class torch.nn.MultiLabelSoftMarginLoss(weight=None, size_average=None, reduce=None, reduction='mean') [source]
 
Creates a criterion that optimizes a multi-label one-versus-all loss based on max-entropy, between input xx  and target yy  of size (N,C)(N, C) . For each sample in the minibatch:  loss(x,y)=−1C∗∑iy[i]∗log⁡((1+exp⁡(−x[i]))−1)+(1−y[i])∗log⁡(exp⁡(−x[i])(1+exp⁡(−x[i])))loss(x, y) = - \frac{1}{C} * \sum_i y[i] * \log((1 + \exp(-x[i]))^{-1}) + (1-y[i]) * \log\left(\frac{\exp(-x[i])}{(1 + \exp(-x[i]))}\right)  
where i∈{0,⋯,x.nElement()−1}i \in \left\{0, \; \cdots , \; \text{x.nElement}() - 1\right\} , y[i]∈{0,1}y[i] \in \left\{0, \; 1\right\} .  Parameters 
 
weight (Tensor, optional) – a manual rescaling weight given to each class. If given, it has to be a Tensor of size C. Otherwise, it is treated as if having all ones. 
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,C)(N, C)  where N is the batch size and C is the number of classes. Target: (N,C)(N, C) , label targets padded by -1 ensuring same shape as the input. Output: scalar. If reduction is 'none', then (N)(N) .
class torch.nn.MultiMarginLoss(p=1, margin=1.0, weight=None, size_average=None, reduce=None, reduction='mean') [source]
 
Creates a criterion that optimizes a multi-class classification hinge loss (margin-based loss) between input xx  (a 2D mini-batch Tensor) and output yy  (which is a 1D tensor of target class indices, 0≤y≤x.size(1)−10 \leq y \leq \text{x.size}(1)-1 ): For each mini-batch sample, the loss in terms of the 1D input xx  and scalar output yy  is:  loss(x,y)=∑imax⁡(0,margin−x[y]+x[i]))px.size(0)\text{loss}(x, y) = \frac{\sum_i \max(0, \text{margin} - x[y] + x[i]))^p}{\text{x.size}(0)}  
where x∈{0,⋯,x.size(0)−1}x \in \left\{0, \; \cdots , \; \text{x.size}(0) - 1\right\}  and i≠yi \neq y . Optionally, you can give non-equal weighting on the classes by passing a 1D weight tensor into the constructor. The loss function then becomes:  loss(x,y)=∑imax⁡(0,w[y]∗(margin−x[y]+x[i]))p)x.size(0)\text{loss}(x, y) = \frac{\sum_i \max(0, w[y] * (\text{margin} - x[y] + x[i]))^p)}{\text{x.size}(0)}  
 Parameters 
 
p (int, optional) – Has a default value of 11 . 11  and 22  are the only supported values. 
margin (float, optional) – Has a default value of 11 . 
weight (Tensor, optional) – a manual rescaling weight given to each class. If given, it has to be a Tensor of size C. Otherwise, it is treated as if having all ones. 
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'
class torch.nn.PairwiseDistance(p=2.0, eps=1e-06, keepdim=False) [source]
 
Computes the batchwise pairwise distance between vectors v1v_1 , v2v_2  using the p-norm:  ∥x∥p=(∑i=1n∣xi∣p)1/p.\Vert x \Vert _p = \left( \sum_{i=1}^n \vert x_i \vert ^ p \right) ^ {1/p}.  
 Parameters 
 
p (real) – the norm degree. Default: 2 
eps (float, optional) – Small value to avoid division by zero. Default: 1e-6 
keepdim (bool, optional) – Determines whether or not to keep the vector dimension. Default: False     Shape:

 Input1: (N,D)(N, D)  where D = vector dimension
 Input2: (N,D)(N, D) , same shape as the Input1 Output: (N)(N) . If keepdim is True, then (N,1)(N, 1) .   Examples::

>>> pdist = nn.PairwiseDistance(p=2)
>>> input1 = torch.randn(100, 128)
>>> input2 = torch.randn(100, 128)
>>> output = pdist(input1, input2)
torch.nn.parallel.data_parallel(module, inputs, device_ids=None, output_device=None, dim=0, module_kwargs=None) [source]
 
Evaluates module(input) in parallel across the GPUs given in device_ids. This is the functional version of the DataParallel module.  Parameters 
 
module (Module) – the module to evaluate in parallel 
inputs (Tensor) – inputs to the module 
device_ids (list of python:int or torch.device) – GPU ids on which to replicate module 
output_device (list of python:int or torch.device) – GPU location of the output Use -1 to indicate the CPU. (default: device_ids[0])   Returns 
a Tensor containing the result of module(input) located on output_device
no_sync() [source]
 
A context manager to disable gradient synchronizations across DDP processes. Within this context, gradients will be accumulated on module variables, which will later be synchronized in the first forward-backward pass exiting the context. Example: >>> ddp = torch.nn.parallel.DistributedDataParallel(model, pg)
>>> with ddp.no_sync():
>>>   for input in inputs:
>>>     ddp(input).backward()  # no synchronization, accumulate grads
>>> ddp(another_input).backward()  # synchronize grads
class torch.nn.parameter.Parameter [source]
 
A kind of Tensor that is to be considered a module parameter. Parameters are Tensor subclasses, that have a very special property when used with Module s - when they’re assigned as Module attributes they are automatically added to the list of its parameters, and will appear e.g. in parameters() iterator. Assigning a Tensor doesn’t have such effect. This is because one might want to cache some temporary state, like last hidden state of the RNN, in the model. If there was no such class as Parameter, these temporaries would get registered too.  Parameters 
 
data (Tensor) – parameter tensor. 
requires_grad (bool, optional) – if the parameter requires gradient. See Excluding subgraphs from backward for more details. Default: True
class torch.nn.parameter.UninitializedParameter [source]
 
A parameter that is not initialized. Unitialized Parameters are a a special case of torch.nn.Parameter where the shape of the data is still unknown. Unlikely a torch.nn.Parameter, uninitialized parameters hold no data and attempting to access some properties, like their shape, will throw a runtime error. The only operations that can be performed on a uninitialized parameter are changing its datatype, moving it to a different device and converting it to a regular torch.nn.Parameter.  
materialize(shape, device=None, dtype=None) [source]
 
Create a Parameter with the same properties of the uninitialized one. Given a shape, it materializes a parameter in the same device and with the same dtype as the current one or the specified ones in the arguments.  Parameters 
 
shape – (tuple): the shape for the materialized tensor. 
device (torch.device) – the desired device of the parameters and buffers in this module. Optional. 
dtype (torch.dtype) – the desired floating point type of the floating point parameters and buffers in this module. Optional.
materialize(shape, device=None, dtype=None) [source]
 
Create a Parameter with the same properties of the uninitialized one. Given a shape, it materializes a parameter in the same device and with the same dtype as the current one or the specified ones in the arguments.  Parameters 
 
shape – (tuple): the shape for the materialized tensor. 
device (torch.device) – the desired device of the parameters and buffers in this module. Optional. 
dtype (torch.dtype) – the desired floating point type of the floating point parameters and buffers in this module. Optional.
class torch.nn.ParameterDict(parameters=None) [source]
 
Holds parameters in a dictionary. ParameterDict can be indexed like a regular Python dictionary, but parameters it contains are properly registered, and will be visible by all Module methods. ParameterDict is an ordered dictionary that respects  the order of insertion, and in update(), the order of the merged OrderedDict or another ParameterDict (the argument to update()).  Note that update() with other unordered mapping types (e.g., Python’s plain dict) does not preserve the order of the merged mapping.  Parameters 
parameters (iterable, optional) – a mapping (dictionary) of (string : Parameter) or an iterable of key-value pairs of type (string, Parameter)   Example: class MyModule(nn.Module):
    def __init__(self):
        super(MyModule, self).__init__()
        self.params = nn.ParameterDict({
                'left': nn.Parameter(torch.randn(5, 10)),
                'right': nn.Parameter(torch.randn(5, 10))
        })

    def forward(self, x, choice):
        x = self.params[choice].mm(x)
        return x
  
clear() [source]
 
Remove all items from the ParameterDict. 
  
items() [source]
 
Return an iterable of the ParameterDict key/value pairs. 
  
keys() [source]
 
Return an iterable of the ParameterDict keys. 
  
pop(key) [source]
 
Remove key from the ParameterDict and return its parameter.  Parameters 
key (string) – key to pop from the ParameterDict   
  
update(parameters) [source]
 
Update the ParameterDict with the key-value pairs from a mapping or an iterable, overwriting existing keys.  Note If parameters is an OrderedDict, a ParameterDict, or an iterable of key-value pairs, the order of new elements in it is preserved.   Parameters 
parameters (iterable) – a mapping (dictionary) from string to Parameter, or an iterable of key-value pairs of type (string, Parameter)   
  
values() [source]
 
Return an iterable of the ParameterDict values.
items() [source]
 
Return an iterable of the ParameterDict key/value pairs.
pop(key) [source]
 
Remove key from the ParameterDict and return its parameter.  Parameters 
key (string) – key to pop from the ParameterDict
update(parameters) [source]
 
Update the ParameterDict with the key-value pairs from a mapping or an iterable, overwriting existing keys.  Note If parameters is an OrderedDict, a ParameterDict, or an iterable of key-value pairs, the order of new elements in it is preserved.   Parameters 
parameters (iterable) – a mapping (dictionary) from string to Parameter, or an iterable of key-value pairs of type (string, Parameter)
class torch.nn.ParameterList(parameters=None) [source]
 
Holds parameters in a list. ParameterList can be indexed like a regular Python list, but parameters it contains are properly registered, and will be visible by all Module methods.  Parameters 
parameters (iterable, optional) – an iterable of Parameter to add   Example: class MyModule(nn.Module):
    def __init__(self):
        super(MyModule, self).__init__()
        self.params = nn.ParameterList([nn.Parameter(torch.randn(10, 10)) for i in range(10)])

    def forward(self, x):
        # ParameterList can act as an iterable, or be indexed using ints
        for i, p in enumerate(self.params):
            x = self.params[i // 2].mm(x) + p.mm(x)
        return x
  
append(parameter) [source]
 
Appends a given parameter at the end of the list.  Parameters 
parameter (nn.Parameter) – parameter to append   
  
extend(parameters) [source]
 
Appends parameters from a Python iterable to the end of the list.  Parameters 
parameters (iterable) – iterable of parameters to append
append(parameter) [source]
 
Appends a given parameter at the end of the list.  Parameters 
parameter (nn.Parameter) – parameter to append
extend(parameters) [source]
 
Appends parameters from a Python iterable to the end of the list.  Parameters 
parameters (iterable) – iterable of parameters to append
class torch.nn.PixelShuffle(upscale_factor) [source]
 
Rearranges elements in a tensor of shape (∗,C×r2,H,W)(*, C \times r^2, H, W)  to a tensor of shape (∗,C,H×r,W×r)(*, C, H \times r, W \times r) , where r is an upscale factor. This is useful for implementing efficient sub-pixel convolution with a stride of 1/r1/r . See the paper: Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Network by Shi et. al (2016) for more details.  Parameters 
upscale_factor (int) – factor to increase spatial resolution by    Shape:

 Input: (∗,Cin,Hin,Win)(*, C_{in}, H_{in}, W_{in}) , where * is zero or more batch dimensions Output: (∗,Cout,Hout,Wout)(*, C_{out}, H_{out}, W_{out}) , where     Cout=Cin÷upscale_factor2C_{out} = C_{in} \div \text{upscale\_factor}^2  
 Hout=Hin×upscale_factorH_{out} = H_{in} \times \text{upscale\_factor}  
 Wout=Win×upscale_factorW_{out} = W_{in} \times \text{upscale\_factor}  
Examples: >>> pixel_shuffle = nn.PixelShuffle(3)
>>> input = torch.randn(1, 9, 4, 4)
>>> output = pixel_shuffle(input)
>>> print(output.size())
torch.Size([1, 1, 12, 12])
class torch.nn.PixelUnshuffle(downscale_factor) [source]
 
Reverses the PixelShuffle operation by rearranging elements in a tensor of shape (∗,C,H×r,W×r)(*, C, H \times r, W \times r)  to a tensor of shape (∗,C×r2,H,W)(*, C \times r^2, H, W) , where r is a downscale factor. See the paper: Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Network by Shi et. al (2016) for more details.  Parameters 
downscale_factor (int) – factor to decrease spatial resolution by    Shape:

 Input: (∗,Cin,Hin,Win)(*, C_{in}, H_{in}, W_{in}) , where * is zero or more batch dimensions Output: (∗,Cout,Hout,Wout)(*, C_{out}, H_{out}, W_{out}) , where     Cout=Cin×downscale_factor2C_{out} = C_{in} \times \text{downscale\_factor}^2  
 Hout=Hin÷downscale_factorH_{out} = H_{in} \div \text{downscale\_factor}  
 Wout=Win÷downscale_factorW_{out} = W_{in} \div \text{downscale\_factor}  
Examples: >>> pixel_unshuffle = nn.PixelUnshuffle(3)
>>> input = torch.randn(1, 1, 12, 12)
>>> output = pixel_unshuffle(input)
>>> print(output.size())
torch.Size([1, 9, 4, 4])
class torch.nn.PoissonNLLLoss(log_input=True, full=False, size_average=None, eps=1e-08, reduce=None, reduction='mean') [source]
 
Negative log likelihood loss with Poisson distribution of target. The loss can be described as:  target∼Poisson(input)loss(input,target)=input−target∗log⁡(input)+log⁡(target!)\text{target} \sim \mathrm{Poisson}(\text{input}) \text{loss}(\text{input}, \text{target}) = \text{input} - \text{target} * \log(\text{input}) + \log(\text{target!}) 
The last term can be omitted or approximated with Stirling formula. The approximation is used for target values more than 1. For targets less or equal to 1 zeros are added to the loss.  Parameters 
 
log_input (bool, optional) – if True the loss is computed as exp⁡(input)−target∗input\exp(\text{input}) - \text{target}*\text{input} , if False the loss is input−target∗log⁡(input+eps)\text{input} - \text{target}*\log(\text{input}+\text{eps}) . 
full (bool, optional) – 
whether to compute full loss, i. e. to add the Stirling approximation term  target∗log⁡(target)−target+0.5∗log⁡(2πtarget).\text{target}*\log(\text{target}) - \text{target} + 0.5 * \log(2\pi\text{target}).  
 
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
 
eps (float, optional) – Small value to avoid evaluation of log⁡(0)\log(0)  when log_input = False. Default: 1e-8 
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'
    Examples: >>> loss = nn.PoissonNLLLoss()
>>> log_input = torch.randn(5, 2, requires_grad=True)
>>> target = torch.randn(5, 2)
>>> output = loss(log_input, target)
>>> output.backward()
  Shape:

 Input: (N,∗)(N, *)  where ∗*  means, any number of additional dimensions Target: (N,∗)(N, *) , same shape as the input Output: scalar by default. If reduction is 'none', then (N,∗)(N, *) , the same shape as the input
class torch.nn.PReLU(num_parameters=1, init=0.25) [source]
 
Applies the element-wise function:  PReLU(x)=max⁡(0,x)+a∗min⁡(0,x)\text{PReLU}(x) = \max(0,x) + a * \min(0,x)  
or  PReLU(x)={x, if x≥0ax, otherwise \text{PReLU}(x) = \begin{cases} x, & \text{ if } x \geq 0 \\ ax, & \text{ otherwise } \end{cases}  
Here aa  is a learnable parameter. When called without arguments, nn.PReLU() uses a single parameter aa  across all input channels. If called with nn.PReLU(nChannels), a separate aa  is used for each input channel.  Note weight decay should not be used when learning aa  for good performance.   Note Channel dim is the 2nd dim of input. When input has dims < 2, then there is no channel dim and the number of channels = 1.   Parameters 
 
num_parameters (int) – number of aa  to learn. Although it takes an int as input, there is only two values are legitimate: 1, or the number of channels at input. Default: 1 
init (float) – the initial value of aa . Default: 0.25     Shape:

 Input: (N,∗)(N, *)  where * means, any number of additional dimensions Output: (N,∗)(N, *) , same shape as the input     Variables 
~PReLU.weight (Tensor) – the learnable weights of shape (num_parameters).    Examples: >>> m = nn.PReLU()
>>> input = torch.randn(2)
>>> output = m(input)
class torch.nn.qat.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros', qconfig=None) [source]
 
A Conv2d module attached with FakeQuantize modules for weight, used for quantization aware training. We adopt the same interface as torch.nn.Conv2d, please see https://pytorch.org/docs/stable/nn.html?highlight=conv2d#torch.nn.Conv2d for documentation. Similar to torch.nn.Conv2d, with FakeQuantize modules initialized to default.  Variables 
~Conv2d.weight_fake_quant – fake quant module for weight    
classmethod from_float(mod) [source]
 
Create a qat module from a float module or qparams_dict Args: mod a float module, either produced by torch.quantization utilities or directly from user
classmethod from_float(mod) [source]
 
Create a qat module from a float module or qparams_dict Args: mod a float module, either produced by torch.quantization utilities or directly from user
class torch.nn.qat.Linear(in_features, out_features, bias=True, qconfig=None) [source]
 
A linear module attached with FakeQuantize modules for weight, used for quantization aware training. We adopt the same interface as torch.nn.Linear, please see https://pytorch.org/docs/stable/nn.html#torch.nn.Linear for documentation. Similar to torch.nn.Linear, with FakeQuantize modules initialized to default.  Variables 
~Linear.weight – fake quant module for weight    
classmethod from_float(mod) [source]
 
Create a qat module from a float module or qparams_dict Args: mod a float module, either produced by torch.quantization utilities or directly from user
class torch.nn.quantized.BatchNorm2d(num_features, eps=1e-05, momentum=0.1) [source]
 
This is the quantized version of BatchNorm2d.
class torch.nn.quantized.BatchNorm3d(num_features, eps=1e-05, momentum=0.1) [source]
 
This is the quantized version of BatchNorm3d.
class torch.nn.quantized.Conv1d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros') [source]
 
Applies a 1D convolution over a quantized input signal composed of several quantized input planes. For details on input arguments, parameters, and implementation see Conv1d.  Note Only zeros is supported for the padding_mode argument.   Note Only torch.quint8 is supported for the input data type.   Variables 
 
~Conv1d.weight (Tensor) – packed tensor derived from the learnable weight parameter. 
~Conv1d.scale (Tensor) – scalar for the output scale 
~Conv1d.zero_point (Tensor) – scalar for the output zero point    See Conv1d for other attributes. Examples: >>> m = nn.quantized.Conv1d(16, 33, 3, stride=2)
>>> input = torch.randn(20, 16, 100)
>>> # quantize input to quint8
>>> q_input = torch.quantize_per_tensor(input, scale=1.0, zero_point=0,
                                        dtype=torch.quint8)
>>> output = m(q_input)
  
classmethod from_float(mod) [source]
 
Creates a quantized module from a float module or qparams_dict.  Parameters 
mod (Module) – a float module, either produced by torch.quantization utilities or provided by the user
classmethod from_float(mod) [source]
 
Creates a quantized module from a float module or qparams_dict.  Parameters 
mod (Module) – a float module, either produced by torch.quantization utilities or provided by the user
class torch.nn.quantized.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros') [source]
 
Applies a 2D convolution over a quantized input signal composed of several quantized input planes. For details on input arguments, parameters, and implementation see Conv2d.  Note Only zeros is supported for the padding_mode argument.   Note Only torch.quint8 is supported for the input data type.   Variables 
 
~Conv2d.weight (Tensor) – packed tensor derived from the learnable weight parameter. 
~Conv2d.scale (Tensor) – scalar for the output scale 
~Conv2d.zero_point (Tensor) – scalar for the output zero point    See Conv2d for other attributes. Examples: >>> # With square kernels and equal stride
>>> m = nn.quantized.Conv2d(16, 33, 3, stride=2)
>>> # non-square kernels and unequal stride and with padding
>>> m = nn.quantized.Conv2d(16, 33, (3, 5), stride=(2, 1), padding=(4, 2))
>>> # non-square kernels and unequal stride and with padding and dilation
>>> m = nn.quantized.Conv2d(16, 33, (3, 5), stride=(2, 1), padding=(4, 2), dilation=(3, 1))
>>> input = torch.randn(20, 16, 50, 100)
>>> # quantize input to quint8
>>> q_input = torch.quantize_per_tensor(input, scale=1.0, zero_point=0, dtype=torch.quint8)
>>> output = m(q_input)
  
classmethod from_float(mod) [source]
 
Creates a quantized module from a float module or qparams_dict.  Parameters 
mod (Module) – a float module, either produced by torch.quantization utilities or provided by the user