neulab/docprompting-conala huggingface dataset:
torch.poisson(input, generator=None) → Tensor  
Returns a tensor of the same size as input with each element sampled from a Poisson distribution with rate parameter given by the corresponding element in input i.e.,  outi∼Poisson(inputi)\text{out}_i \sim \text{Poisson}(\text{input}_i)  
 Parameters 
input (Tensor) – the input tensor containing the rates of the Poisson distribution  Keyword Arguments 
generator (torch.Generator, optional) – a pseudorandom number generator for sampling   Example: >>> rates = torch.rand(4, 4) * 5  # rate parameter between 0 and 5
>>> torch.poisson(rates)
tensor([[9., 1., 3., 5.],
        [8., 6., 6., 0.],
        [0., 4., 5., 3.],
        [2., 1., 4., 2.]])
torch.polar(abs, angle, *, out=None) → Tensor  
Constructs a complex tensor whose elements are Cartesian coordinates corresponding to the polar coordinates with absolute value abs and angle angle.  out=abs⋅cos⁡(angle)+abs⋅sin⁡(angle)⋅j\text{out} = \text{abs} \cdot \cos(\text{angle}) + \text{abs} \cdot \sin(\text{angle}) \cdot j  
 Parameters 
 
abs (Tensor) – The absolute value the complex tensor. Must be float or double. 
angle (Tensor) – The angle of the complex tensor. Must be same dtype as abs.   Keyword Arguments 
out (Tensor) – If the inputs are torch.float32, must be torch.complex64. If the inputs are torch.float64, must be torch.complex128.    Example::

>>> import numpy as np
>>> abs = torch.tensor([1, 2], dtype=torch.float64)
>>> angle = torch.tensor([np.pi / 2, 5 * np.pi / 4], dtype=torch.float64)
>>> z = torch.polar(abs, angle)
>>> z
tensor([(0.0000+1.0000j), (-1.4142-1.4142j)], dtype=torch.complex128)
torch.polygamma(n, input, *, out=None) → Tensor  
Computes the nthn^{th}  derivative of the digamma function on input. n≥0n \geq 0  is called the order of the polygamma function.  ψ(n)(x)=d(n)dx(n)ψ(x)\psi^{(n)}(x) = \frac{d^{(n)}}{dx^{(n)}} \psi(x)  
 Note This function is implemented only for nonnegative integers n≥0n \geq 0 .   Parameters 
 
n (int) – the order of the polygamma function 
input (Tensor) – the input tensor.   Keyword Arguments 
out (Tensor, optional) – the output tensor.    Example::

>>> a = torch.tensor([1, 0.5])
>>> torch.polygamma(1, a)
tensor([1.64493, 4.9348])
>>> torch.polygamma(2, a)
tensor([ -2.4041, -16.8288])
>>> torch.polygamma(3, a)
tensor([ 6.4939, 97.4091])
>>> torch.polygamma(4, a)
tensor([ -24.8863, -771.4742])
torch.pow(input, exponent, *, out=None) → Tensor  
Takes the power of each element in input with exponent and returns a tensor with the result. exponent can be either a single float number or a Tensor with the same number of elements as input. When exponent is a scalar value, the operation applied is:  outi=xiexponent\text{out}_i = x_i ^ \text{exponent}  
When exponent is a tensor, the operation applied is:  outi=xiexponenti\text{out}_i = x_i ^ {\text{exponent}_i}  
When exponent is a tensor, the shapes of input and exponent must be broadcastable.  Parameters 
 
input (Tensor) – the input tensor. 
exponent (float or tensor) – the exponent value   Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.randn(4)
>>> a
tensor([ 0.4331,  1.2475,  0.6834, -0.2791])
>>> torch.pow(a, 2)
tensor([ 0.1875,  1.5561,  0.4670,  0.0779])
>>> exp = torch.arange(1., 5.)

>>> a = torch.arange(1., 5.)
>>> a
tensor([ 1.,  2.,  3.,  4.])
>>> exp
tensor([ 1.,  2.,  3.,  4.])
>>> torch.pow(a, exp)
tensor([   1.,    4.,   27.,  256.])
  
torch.pow(self, exponent, *, out=None) → Tensor 
 self is a scalar float value, and exponent is a tensor. The returned tensor out is of the same shape as exponent The operation applied is:  outi=selfexponenti\text{out}_i = \text{self} ^ {\text{exponent}_i}  
 Parameters 
 
self (float) – the scalar base value for the power operation 
exponent (Tensor) – the exponent tensor   Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example: >>> exp = torch.arange(1., 5.)
>>> base = 2
>>> torch.pow(base, exp)
tensor([  2.,   4.,   8.,  16.])
torch.prod(input, *, dtype=None) → Tensor  
Returns the product of all elements in the input tensor.  Parameters 
input (Tensor) – the input tensor.  Keyword Arguments 
dtype (torch.dtype, optional) – the desired data type of returned tensor. If specified, the input tensor is casted to dtype before the operation is performed. This is useful for preventing data type overflows. Default: None.   Example: >>> a = torch.randn(1, 3)
>>> a
tensor([[-0.8020,  0.5428, -1.5854]])
>>> torch.prod(a)
tensor(0.6902)
  
torch.prod(input, dim, keepdim=False, *, dtype=None) → Tensor 
 Returns the product of each row of the input tensor in the given dimension dim. If keepdim is True, the output tensor is of the same size as input except in the dimension dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze()), resulting in the output tensor having 1 fewer dimension than input.  Parameters 
 
input (Tensor) – the input tensor. 
dim (int) – the dimension to reduce. 
keepdim (bool) – whether the output tensor has dim retained or not.   Keyword Arguments 
dtype (torch.dtype, optional) – the desired data type of returned tensor. If specified, the input tensor is casted to dtype before the operation is performed. This is useful for preventing data type overflows. Default: None.   Example: >>> a = torch.randn(4, 2)
>>> a
tensor([[ 0.5261, -0.3837],
        [ 1.1857, -0.2498],
        [-1.1646,  0.0705],
        [ 1.1131, -1.0629]])
>>> torch.prod(a, 1)
tensor([-0.2018, -0.2962, -0.0821, -1.1831])
torch.promote_types(type1, type2) → dtype  
Returns the torch.dtype with the smallest size and scalar kind that is not smaller nor of lower kind than either type1 or type2. See type promotion documentation for more information on the type promotion logic.  Parameters 
 
type1 (torch.dtype) –  
type2 (torch.dtype) –     Example: >>> torch.promote_types(torch.int32, torch.float32)
torch.float32
>>> torch.promote_types(torch.uint8, torch.long)
torch.long
torch.qr(input, some=True, *, out=None) -> (Tensor, Tensor)  
Computes the QR decomposition of a matrix or a batch of matrices input, and returns a namedtuple (Q, R) of tensors such that input=QR\text{input} = Q R  with QQ  being an orthogonal matrix or batch of orthogonal matrices and RR  being an upper triangular matrix or batch of upper triangular matrices. If some is True, then this function returns the thin (reduced) QR factorization. Otherwise, if some is False, this function returns the complete QR factorization.  Warning torch.qr is deprecated. Please use torch.linalg.qr() instead. Differences with torch.linalg.qr:  
torch.linalg.qr takes a string parameter mode instead of some:  
some=True is equivalent of mode='reduced': both are the default 
some=False is equivalent of mode='complete'.      Warning If you plan to backpropagate through QR, note that the current backward implementation is only well-defined when the first min⁡(input.size(−1),input.size(−2))\min(input.size(-1), input.size(-2))  columns of input are linearly independent. This behavior will propably change once QR supports pivoting.   Note This function uses LAPACK for CPU inputs and MAGMA for CUDA inputs, and may produce different (valid) decompositions on different device types or different platforms.   Parameters 
 
input (Tensor) – the input tensor of size (∗,m,n)(*, m, n)  where * is zero or more batch dimensions consisting of matrices of dimension m×nm \times n . 
some (bool, optional) – 
Set to True for reduced QR decomposition and False for complete QR decomposition. If k = min(m, n) then:  
some=True : returns (Q, R) with dimensions (m, k), (k, n) (default) 
'some=False': returns (Q, R) with dimensions (m, m), (m, n)     Keyword Arguments 
out (tuple, optional) – tuple of Q and R tensors. The dimensions of Q and R are detailed in the description of some above.   Example: >>> a = torch.tensor([[12., -51, 4], [6, 167, -68], [-4, 24, -41]])
>>> q, r = torch.qr(a)
>>> q
tensor([[-0.8571,  0.3943,  0.3314],
        [-0.4286, -0.9029, -0.0343],
        [ 0.2857, -0.1714,  0.9429]])
>>> r
tensor([[ -14.0000,  -21.0000,   14.0000],
        [   0.0000, -175.0000,   70.0000],
        [   0.0000,    0.0000,  -35.0000]])
>>> torch.mm(q, r).round()
tensor([[  12.,  -51.,    4.],
        [   6.,  167.,  -68.],
        [  -4.,   24.,  -41.]])
>>> torch.mm(q.t(), q).round()
tensor([[ 1.,  0.,  0.],
        [ 0.,  1., -0.],
        [ 0., -0.,  1.]])
>>> a = torch.randn(3, 4, 5)
>>> q, r = torch.qr(a, some=False)
>>> torch.allclose(torch.matmul(q, r), a)
True
>>> torch.allclose(torch.matmul(q.transpose(-2, -1), q), torch.eye(5))
True
torch.quantile(input, q) → Tensor  
Returns the q-th quantiles of all elements in the input tensor, doing a linear interpolation when the q-th quantile lies between two data points.  Parameters 
 
input (Tensor) – the input tensor. 
q (float or Tensor) – a scalar or 1D tensor of quantile values in the range [0, 1]    Example: >>> a = torch.randn(1, 3)
>>> a
tensor([[ 0.0700, -0.5446,  0.9214]])
>>> q = torch.tensor([0, 0.5, 1])
>>> torch.quantile(a, q)
tensor([-0.5446,  0.0700,  0.9214])
  
torch.quantile(input, q, dim=None, keepdim=False, *, out=None) → Tensor 
 Returns the q-th quantiles of each row of the input tensor along the dimension dim, doing a linear interpolation when the q-th quantile lies between two data points. By default, dim is None resulting in the input tensor being flattened before computation. If keepdim is True, the output dimensions are of the same size as input except in the dimensions being reduced (dim or all if dim is None) where they have size 1. Otherwise, the dimensions being reduced are squeezed (see torch.squeeze()). If q is a 1D tensor, an extra dimension is prepended to the output tensor with the same size as q which represents the quantiles.  Parameters 
 
input (Tensor) – the input tensor. 
q (float or Tensor) – a scalar or 1D tensor of quantile values in the range [0, 1] 
dim (int) – the dimension to reduce. 
keepdim (bool) – whether the output tensor has dim retained or not.   Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.randn(2, 3)
>>> a
tensor([[ 0.0795, -1.2117,  0.9765],
        [ 1.1707,  0.6706,  0.4884]])
>>> q = torch.tensor([0.25, 0.5, 0.75])
>>> torch.quantile(a, q, dim=1, keepdim=True)
tensor([[[-0.5661],
        [ 0.5795]],

        [[ 0.0795],
        [ 0.6706]],

        [[ 0.5280],
        [ 0.9206]]])
>>> torch.quantile(a, q, dim=1, keepdim=True).shape
torch.Size([3, 2, 1])
torch.quantization.add_observer_(module, qconfig_propagation_list=None, non_leaf_module_list=None, device=None, custom_module_class_mapping=None) [source]
 
Add observer for the leaf child of the module. This function insert observer module to all leaf child module that has a valid qconfig attribute.  Parameters 
 
module – input module with qconfig attributes for all the leaf modules that we want to quantize 
device – parent device, if any 
non_leaf_module_list – list of non-leaf modules we want to add observer   Returns 
None, module is modified inplace with added observer modules and forward_hooks
torch.quantization.add_quant_dequant(module) [source]
 
Wrap the leaf child module in QuantWrapper if it has a valid qconfig Note that this function will modify the children of module inplace and it can return a new module which wraps the input module as well.  Parameters 
 
module – input module with qconfig attributes for all the leaf modules 
we want to quantize (that) –    Returns 
Either the inplace modified module with submodules wrapped in QuantWrapper based on qconfig or a new QuantWrapper module which wraps the input module, the latter case only happens when the input module is a leaf module and we want to quantize it.
torch.quantization.convert(module, mapping=None, inplace=False, remove_qconfig=True, convert_custom_config_dict=None) [source]
 
Converts submodules in input module to a different module according to mapping by calling from_float method on the target module class. And remove qconfig at the end if remove_qconfig is set to True.  Parameters 
 
module – prepared and calibrated module 
mapping – a dictionary that maps from source module type to target module type, can be overwritten to allow swapping user defined Modules 
inplace – carry out model transformations in-place, the original module is mutated 
convert_custom_config_dict – custom configuration dictionary for convert function    # Example of convert_custom_config_dict:
convert_custom_config_dict = {
    # user will manually define the corresponding quantized
    # module class which has a from_observed class method that converts
    # observed custom module to quantized custom module
    "observed_to_quantized_custom_module_class": {
        ObservedCustomModule: QuantizedCustomModule
    }
}
torch.quantization.default_eval_fn(model, calib_data) [source]
 
Default evaluation function takes a torch.utils.data.Dataset or a list of input Tensors and run the model on the dataset
class torch.quantization.DeQuantStub [source]
 
Dequantize stub module, before calibration, this is same as identity, this will be swapped as nnq.DeQuantize in convert.
class torch.quantization.FakeQuantize(observer=<class 'torch.quantization.observer.MovingAverageMinMaxObserver'>, quant_min=0, quant_max=255, **observer_kwargs) [source]
 
Simulate the quantize and dequantize operations in training time. The output of this module is given by x_out = (clamp(round(x/scale + zero_point), quant_min, quant_max)-zero_point)*scale  
scale defines the scale factor used for quantization. 
zero_point specifies the quantized value to which 0 in floating point maps to 
quant_min specifies the minimum allowable quantized value. 
quant_max specifies the maximum allowable quantized value. 
fake_quant_enable controls the application of fake quantization on tensors, note that statistics can still be updated. 
observer_enable controls statistics collection on tensors 
 
dtype specifies the quantized dtype that is being emulated with fake-quantization, 

allowable values are torch.qint8 and torch.quint8. The values of quant_min and quant_max should be chosen to be consistent with the dtype      Parameters 
 
observer (module) – Module for observing statistics on input tensors and calculating scale and zero-point. 
quant_min (int) – The minimum allowable quantized value. 
quant_max (int) – The maximum allowable quantized value. 
observer_kwargs (optional) – Arguments for the observer module   Variables 
~FakeQuantize.observer (Module) – User provided module that collects statistics on the input tensor and provides a method to calculate scale and zero-point.
torch.quantization.fuse_modules(model, modules_to_fuse, inplace=False, fuser_func=<function fuse_known_modules>, fuse_custom_config_dict=None) [source]
 
Fuses a list of modules into a single module Fuses only the following sequence of modules: conv, bn conv, bn, relu conv, relu linear, relu bn, relu All other sequences are left unchanged. For these sequences, replaces the first item in the list with the fused module, replacing the rest of the modules with identity.  Parameters 
 
model – Model containing the modules to be fused 
modules_to_fuse – list of list of module names to fuse. Can also be a list of strings if there is only a single list of modules to fuse. 
inplace – bool specifying if fusion happens in place on the model, by default a new model is returned 
fuser_func – Function that takes in a list of modules and outputs a list of fused modules of the same length. For example, fuser_func([convModule, BNModule]) returns the list [ConvBNModule, nn.Identity()] Defaults to torch.quantization.fuse_known_modules 
fuse_custom_config_dict – custom configuration for fusion    # Example of fuse_custom_config_dict
fuse_custom_config_dict = {
    # Additional fuser_method mapping
    "additional_fuser_method_mapping": {
        (torch.nn.Conv2d, torch.nn.BatchNorm2d): fuse_conv_bn
    },
}
  Returns 
model with fused modules. A new copy is created if inplace=True.   Examples: >>> m = myModel()
>>> # m is a module containing  the sub-modules below
>>> modules_to_fuse = [ ['conv1', 'bn1', 'relu1'], ['submodule.conv', 'submodule.relu']]
>>> fused_m = torch.quantization.fuse_modules(m, modules_to_fuse)
>>> output = fused_m(input)

>>> m = myModel()
>>> # Alternately provide a single list of modules to fuse
>>> modules_to_fuse = ['conv1', 'bn1', 'relu1']
>>> fused_m = torch.quantization.fuse_modules(m, modules_to_fuse)
>>> output = fused_m(input)
torch.quantization.get_observer_dict(mod, target_dict, prefix='') [source]
 
Traverse the modules and save all observers into dict. This is mainly used for quantization accuracy debug :param mod: the top module we want to save all observers :param prefix: the prefix for the current module :param target_dict: the dictionary used to save all the observers
class torch.quantization.HistogramObserver(bins=2048, upsample_rate=128, dtype=torch.quint8, qscheme=torch.per_tensor_affine, reduce_range=False) [source]
 
The module records the running histogram of tensor values along with min/max values. calculate_qparams will calculate scale and zero_point.  Parameters 
 
bins – Number of bins to use for the histogram 
upsample_rate – Factor by which the histograms are upsampled, this is used to interpolate histograms with varying ranges across observations 
dtype – Quantized data type 
qscheme – Quantization scheme to be used 
reduce_range – Reduces the range of the quantized data type by 1 bit    The scale and zero point are computed as follows:  
 Create the histogram of the incoming inputs.

The histogram is computed continuously, and the ranges per bin change with every new tensor observed.    
 Search the distribution in the histogram for optimal min/max values.

The search for the min/max values ensures the minimization of the quantization error with respect to the floating point model.    
 Compute the scale and zero point the same way as in the

MinMaxObserver
class torch.quantization.MinMaxObserver(dtype=torch.quint8, qscheme=torch.per_tensor_affine, reduce_range=False, quant_min=None, quant_max=None) [source]
 
Observer module for computing the quantization parameters based on the running min and max values. This observer uses the tensor min/max statistics to compute the quantization parameters. The module records the running minimum and maximum of incoming tensors, and uses this statistic to compute the quantization parameters.  Parameters 
 
dtype – Quantized data type 
qscheme – Quantization scheme to be used 
reduce_range – Reduces the range of the quantized data type by 1 bit 
quant_min – Minimum quantization value. If unspecified, it will follow the 8-bit setup. 
quant_max – Maximum quantization value. If unspecified, it will follow the 8-bit setup.    Given running min/max as xminx_\text{min}  and xmaxx_\text{max} , scale ss  and zero point zz  are computed as: The running minimum/maximum xmin/maxx_\text{min/max}  is computed as:  xmin={min⁡(X)if xmin=Nonemin⁡(xmin,min⁡(X))otherwisexmax={max⁡(X)if xmax=Nonemax⁡(xmax,max⁡(X))otherwise\begin{array}{ll} x_\text{min} &= \begin{cases} \min(X) & \text{if~}x_\text{min} = \text{None} \\ \min\left(x_\text{min}, \min(X)\right) & \text{otherwise} \end{cases}\\ x_\text{max} &= \begin{cases} \max(X) & \text{if~}x_\text{max} = \text{None} \\ \max\left(x_\text{max}, \max(X)\right) & \text{otherwise} \end{cases}\\ \end{array} 
where XX  is the observed tensor. The scale ss  and zero point zz  are then computed as:  if Symmetric:s=2max⁡(∣xmin∣,xmax)/(Qmax−Qmin)z={0if dtype is qint8128otherwiseOtherwise:s=(xmax−xmin)/(Qmax−Qmin)z=Qmin−round(xmin/s)\begin{aligned} \text{if Symmetric:}&\\ &s = 2 \max(|x_\text{min}|, x_\text{max}) / \left( Q_\text{max} - Q_\text{min} \right) \\ &z = \begin{cases} 0 & \text{if dtype is qint8} \\ 128 & \text{otherwise} \end{cases}\\ \text{Otherwise:}&\\ &s = \left( x_\text{max} - x_\text{min} \right ) / \left( Q_\text{max} - Q_\text{min} \right ) \\ &z = Q_\text{min} - \text{round}(x_\text{min} / s) \end{aligned} 
where QminQ_\text{min}  and QmaxQ_\text{max}  are the minimum and maximum of the quantized data type.  Warning Only works with torch.per_tensor_symmetric quantization scheme   Warning dtype can only take torch.qint8 or torch.quint8.   Note If the running minimum equals to the running maximum, the scale and zero_point are set to 1.0 and 0.
class torch.quantization.MovingAverageMinMaxObserver(averaging_constant=0.01, dtype=torch.quint8, qscheme=torch.per_tensor_affine, reduce_range=False, quant_min=None, quant_max=None) [source]
 
Observer module for computing the quantization parameters based on the moving average of the min and max values. This observer computes the quantization parameters based on the moving averages of minimums and maximums of the incoming tensors. The module records the average minimum and maximum of incoming tensors, and uses this statistic to compute the quantization parameters.  Parameters 
 
averaging_constant – Averaging constant for min/max. 
dtype – Quantized data type 
qscheme – Quantization scheme to be used 
reduce_range – Reduces the range of the quantized data type by 1 bit 
quant_min – Minimum quantization value. If unspecified, it will follow the 8-bit setup. 
quant_max – Maximum quantization value. If unspecified, it will follow the 8-bit setup.    The moving average min/max is computed as follows  xmin={min⁡(X)if xmin=None(1−c)xmin+cmin⁡(X)otherwisexmax={max⁡(X)if xmax=None(1−c)xmax+cmax⁡(X)otherwise\begin{array}{ll} x_\text{min} = \begin{cases} \min(X) & \text{if~}x_\text{min} = \text{None} \\ (1 - c) x_\text{min} + c \min(X) & \text{otherwise} \end{cases}\\ x_\text{max} = \begin{cases} \max(X) & \text{if~}x_\text{max} = \text{None} \\ (1 - c) x_\text{max} + c \max(X) & \text{otherwise} \end{cases}\\ \end{array} 
where xmin/maxx_\text{min/max}  is the running average min/max, XX  is is the incoming tensor, and cc  is the averaging_constant. The scale and zero point are then computed as in MinMaxObserver.  Note Only works with torch.per_tensor_affine quantization scheme.   Note If the running minimum equals to the running maximum, the scale and zero_point are set to 1.0 and 0.
class torch.quantization.MovingAveragePerChannelMinMaxObserver(averaging_constant=0.01, ch_axis=0, dtype=torch.quint8, qscheme=torch.per_channel_affine, reduce_range=False, quant_min=None, quant_max=None) [source]
 
Observer module for computing the quantization parameters based on the running per channel min and max values. This observer uses the tensor min/max statistics to compute the per channel quantization parameters. The module records the running minimum and maximum of incoming tensors, and uses this statistic to compute the quantization parameters.  Parameters 
 
averaging_constant – Averaging constant for min/max. 
ch_axis – Channel axis 
dtype – Quantized data type 
qscheme – Quantization scheme to be used 
reduce_range – Reduces the range of the quantized data type by 1 bit 
quant_min – Minimum quantization value. If unspecified, it will follow the 8-bit setup. 
quant_max – Maximum quantization value. If unspecified, it will follow the 8-bit setup.    The quantization parameters are computed the same way as in MovingAverageMinMaxObserver, with the difference that the running min/max values are stored per channel. Scales and zero points are thus computed per channel as well.  Note If the running minimum equals to the running maximum, the scales and zero_points are set to 1.0 and 0.
class torch.quantization.NoopObserver(dtype=torch.float16, custom_op_name='') [source]
 
Observer that doesn’t do anything and just passes its configuration to the quantized module’s .from_float(). Primarily used for quantization to float16 which doesn’t require determining ranges.  Parameters 
 
dtype – Quantized data type 
custom_op_name – (temporary) specify this observer for an operator that doesn’t require any observation (Can be used in Graph Mode Passes for special case ops).