neulab/docprompting-conala huggingface dataset:
requires_grad_(requires_grad=True)  
Change if autograd should record operations on parameters in this module. This method sets the parameters’ requires_grad attributes in-place. This method is helpful for freezing part of the module for finetuning or training parts of a model individually (e.g., GAN training).  Parameters 
requires_grad (bool) – whether autograd should record operations on parameters in this module. Default: True.  Returns 
self  Return type 
Module
save(f, _extra_files={})  
See torch.jit.save for details.
state_dict(destination=None, prefix='', keep_vars=False)  
Returns a dictionary containing a whole state of the module. Both parameters and persistent buffers (e.g. running averages) are included. Keys are corresponding parameter and buffer names.  Returns 
a dictionary containing a whole state of the module  Return type 
dict   Example: >>> module.state_dict().keys()
['bias', 'weight']
to(*args, **kwargs)  
Moves and/or casts the parameters and buffers. This can be called as  
to(device=None, dtype=None, non_blocking=False) 
  
to(dtype, non_blocking=False) 
  
to(tensor, non_blocking=False) 
  
to(memory_format=torch.channels_last) 
 Its signature is similar to torch.Tensor.to(), but only accepts floating point or complex dtype`s. In addition, this method will
only cast the floating point or complex parameters and buffers to :attr:`dtype (if given). The integral parameters and buffers will be moved device, if that is given, but with dtypes unchanged. When non_blocking is set, it tries to convert/move asynchronously with respect to the host if possible, e.g., moving CPU Tensors with pinned memory to CUDA devices. See below for examples.  Note This method modifies the module in-place.   Parameters 
 
device (torch.device) – the desired device of the parameters and buffers in this module 
dtype (torch.dtype) – the desired floating point or complex dtype of the parameters and buffers in this module 
tensor (torch.Tensor) – Tensor whose dtype and device are the desired dtype and device for all parameters and buffers in this module 
memory_format (torch.memory_format) – the desired memory format for 4D parameters and buffers in this module (keyword only argument)   Returns 
self  Return type 
Module   Examples: >>> linear = nn.Linear(2, 2)
>>> linear.weight
Parameter containing:
tensor([[ 0.1913, -0.3420],
        [-0.5113, -0.2325]])
>>> linear.to(torch.double)
Linear(in_features=2, out_features=2, bias=True)
>>> linear.weight
Parameter containing:
tensor([[ 0.1913, -0.3420],
        [-0.5113, -0.2325]], dtype=torch.float64)
>>> gpu1 = torch.device("cuda:1")
>>> linear.to(gpu1, dtype=torch.half, non_blocking=True)
Linear(in_features=2, out_features=2, bias=True)
>>> linear.weight
Parameter containing:
tensor([[ 0.1914, -0.3420],
        [-0.5112, -0.2324]], dtype=torch.float16, device='cuda:1')
>>> cpu = torch.device("cpu")
>>> linear.to(cpu)
Linear(in_features=2, out_features=2, bias=True)
>>> linear.weight
Parameter containing:
tensor([[ 0.1914, -0.3420],
        [-0.5112, -0.2324]], dtype=torch.float16)

>>> linear = nn.Linear(2, 2, bias=None).to(torch.cdouble)
>>> linear.weight
Parameter containing:
tensor([[ 0.3741+0.j,  0.2382+0.j],
        [ 0.5593+0.j, -0.4443+0.j]], dtype=torch.complex128)
>>> linear(torch.ones(3, 2, dtype=torch.cdouble))
tensor([[0.6122+0.j, 0.1150+0.j],
        [0.6122+0.j, 0.1150+0.j],
        [0.6122+0.j, 0.1150+0.j]], dtype=torch.complex128)
train(mode=True)  
Sets the module in training mode. This has any effect only on certain modules. See documentations of particular modules for details of their behaviors in training/evaluation mode, if they are affected, e.g. Dropout, BatchNorm, etc.  Parameters 
mode (bool) – whether to set training mode (True) or evaluation mode (False). Default: True.  Returns 
self  Return type 
Module
type(dst_type)  
Casts all parameters and buffers to dst_type.  Parameters 
dst_type (type or string) – the desired type  Returns 
self  Return type 
Module
xpu(device=None)  
Moves all model parameters and buffers to the XPU. This also makes associated parameters and buffers different objects. So it should be called before constructing optimizer if the module will live on XPU while being optimized.  Parameters 
device (int, optional) – if specified, all parameters will be copied to that device  Returns 
self  Return type 
Module
zero_grad(set_to_none=False)  
Sets gradients of all model parameters to zero. See similar function under torch.optim.Optimizer for more context.  Parameters 
set_to_none (bool) – instead of setting to zero, set the grads to None. See torch.optim.Optimizer.zero_grad() for details.
torch.jit.script_if_tracing(fn) [source]
 
Compiles fn when it is first called during tracing. torch.jit.script has a non-negligible start up time when it is first called due to lazy-initializations of many compiler builtins. Therefore you should not use it in library code. However, you may want to have parts of your library work in tracing even if they use control flow. In these cases, you should use @torch.jit.script_if_tracing to substitute for torch.jit.script.  Parameters 
fn – A function to compile.  Returns 
If called during tracing, a ScriptFunction created by torch.jit.script is returned. Otherwise, the original function fn is returned.
torch.jit.unused(fn) [source]
 
This decorator indicates to the compiler that a function or method should be ignored and replaced with the raising of an exception. This allows you to leave code in your model that is not yet TorchScript compatible and still export your model. Example (using @torch.jit.unused on a method): import torch
import torch.nn as nn

class MyModule(nn.Module):
    def __init__(self, use_memory_efficient):
        super(MyModule, self).__init__()
        self.use_memory_efficient = use_memory_efficient

    @torch.jit.unused
    def memory_efficient(self, x):
        import pdb
        pdb.set_trace()
        return x + 10

    def forward(self, x):
        # Use not-yet-scriptable memory efficient mode
        if self.use_memory_efficient:
            return self.memory_efficient(x)
        else:
            return x + 10

m = torch.jit.script(MyModule(use_memory_efficient=False))
m.save("m.pt")

m = torch.jit.script(MyModule(use_memory_efficient=True))
# exception raised
m(torch.rand(100))
torch.jit.wait(future) [source]
 
Forces completion of a torch.jit.Future[T] asynchronous task, returning the result of the task. See fork() for docs and examples. :param func: an asynchronous task reference, created through torch.jit.fork :type func: torch.jit.Future[T]  Returns 
the return value of the the completed task  Return type 
T
torch.kaiser_window(window_length, periodic=True, beta=12.0, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor  
Computes the Kaiser window with window length window_length and shape parameter beta. Let I_0 be the zeroth order modified Bessel function of the first kind (see torch.i0()) and N = L - 1 if periodic is False and L if periodic is True, where L is the window_length. This function computes:  outi=I0(β1−(i−N/2N/2)2)/I0(β)out_i = I_0 \left( \beta \sqrt{1 - \left( {\frac{i - N/2}{N/2}} \right) ^2 } \right) / I_0( \beta )  
Calling torch.kaiser_window(L, B, periodic=True) is equivalent to calling torch.kaiser_window(L + 1, B, periodic=False)[:-1]). The periodic argument is intended as a helpful shorthand to produce a periodic window as input to functions like torch.stft().  Note If window_length is one, then the returned window is a single element tensor containing a one.   Parameters 
 
window_length (int) – length of the window. 
periodic (bool, optional) – If True, returns a periodic window suitable for use in spectral analysis. If False, returns a symmetric window suitable for use in filter design. 
beta (float, optional) – shape parameter for the window.   Keyword Arguments 
 
dtype (torch.dtype, optional) – the desired data type of returned tensor. Default: if None, uses a global default (see torch.set_default_tensor_type()). 
layout (torch.layout, optional) – the desired layout of returned window tensor. Only torch.strided (dense layout) is supported. 
device (torch.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see torch.set_default_tensor_type()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. 
requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.
torch.kron(input, other, *, out=None) → Tensor  
Computes the Kronecker product, denoted by ⊗\otimes , of input and other. If input is a (a0×a1×⋯×an)(a_0 \times a_1 \times \dots \times a_n)  tensor and other is a (b0×b1×⋯×bn)(b_0 \times b_1 \times \dots \times b_n)  tensor, the result will be a (a0∗b0×a1∗b1×⋯×an∗bn)(a_0*b_0 \times a_1*b_1 \times \dots \times a_n*b_n)  tensor with the following entries:  (input⊗other)k0,k1,…,kn=inputi0,i1,…,in∗otherj0,j1,…,jn,(\text{input} \otimes \text{other})_{k_0, k_1, \dots, k_n} = \text{input}_{i_0, i_1, \dots, i_n} * \text{other}_{j_0, j_1, \dots, j_n},  
where kt=it∗bt+jtk_t = i_t * b_t + j_t  for 0≤t≤n0 \leq t \leq n . If one tensor has fewer dimensions than the other it is unsqueezed until it has the same number of dimensions. Supports real-valued and complex-valued inputs.  Note This function generalizes the typical definition of the Kronecker product for two matrices to two tensors, as described above. When input is a (m×n)(m \times n)  matrix and other is a (p×q)(p \times q)  matrix, the result will be a (p∗m×q∗n)(p*m \times q*n)  block matrix:  A⊗B=[a11B⋯a1nB⋮⋱⋮am1B⋯amnB]\mathbf{A} \otimes \mathbf{B}=\begin{bmatrix} a_{11} \mathbf{B} & \cdots & a_{1 n} \mathbf{B} \\ \vdots & \ddots & \vdots \\ a_{m 1} \mathbf{B} & \cdots & a_{m n} \mathbf{B} \end{bmatrix}  
where input is A\mathbf{A}  and other is B\mathbf{B} .   Parameters 
 
input (Tensor) –  
other (Tensor) –    Keyword Arguments 
out (Tensor, optional) – The output tensor. Ignored if None. Default: None   Examples: >>> mat1 = torch.eye(2)
>>> mat2 = torch.ones(2, 2)
>>> torch.kron(mat1, mat2)
tensor([[1., 1., 0., 0.],
        [1., 1., 0., 0.],
        [0., 0., 1., 1.],
        [0., 0., 1., 1.]])

>>> mat1 = torch.eye(2)
>>> mat2 = torch.arange(1, 5).reshape(2, 2)
>>> torch.kron(mat1, mat2)
tensor([[1., 2., 0., 0.],
        [3., 4., 0., 0.],
        [0., 0., 1., 2.],
        [0., 0., 3., 4.]])
torch.kthvalue(input, k, dim=None, keepdim=False, *, out=None) -> (Tensor, LongTensor)  
Returns a namedtuple (values, indices) where values is the k th smallest element of each row of the input tensor in the given dimension dim. And indices is the index location of each element found. If dim is not given, the last dimension of the input is chosen. If keepdim is True, both the values and indices tensors are the same size as input, except in the dimension dim where they are of size 1. Otherwise, dim is squeezed (see torch.squeeze()), resulting in both the values and indices tensors having 1 fewer dimension than the input tensor.  Note When input is a CUDA tensor and there are multiple valid k th values, this function may nondeterministically return indices for any of them.   Parameters 
 
input (Tensor) – the input tensor. 
k (int) – k for the k-th smallest element 
dim (int, optional) – the dimension to find the kth value along 
keepdim (bool) – whether the output tensor has dim retained or not.   Keyword Arguments 
out (tuple, optional) – the output tuple of (Tensor, LongTensor) can be optionally given to be used as output buffers   Example: >>> x = torch.arange(1., 6.)
>>> x
tensor([ 1.,  2.,  3.,  4.,  5.])
>>> torch.kthvalue(x, 4)
torch.return_types.kthvalue(values=tensor(4.), indices=tensor(3))

>>> x=torch.arange(1.,7.).resize_(2,3)
>>> x
tensor([[ 1.,  2.,  3.],
        [ 4.,  5.,  6.]])
>>> torch.kthvalue(x, 2, 0, True)
torch.return_types.kthvalue(values=tensor([[4., 5., 6.]]), indices=tensor([[1, 1, 1]]))
torch.lcm(input, other, *, out=None) → Tensor  
Computes the element-wise least common multiple (LCM) of input and other. Both input and other must have integer types.  Note This defines lcm(0,0)=0lcm(0, 0) = 0  and lcm(0,a)=0lcm(0, a) = 0 .   Parameters 
 
input (Tensor) – the input tensor. 
other (Tensor) – the second input tensor   Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example: >>> a = torch.tensor([5, 10, 15])
>>> b = torch.tensor([3, 4, 5])
>>> torch.lcm(a, b)
tensor([15, 20, 15])
>>> c = torch.tensor([3])
>>> torch.lcm(a, c)
tensor([15, 30, 15])
torch.ldexp(input, other, *, out=None) → Tensor  
Multiplies input by 2**:attr:other.  outi=inputi∗2iother\text{{out}}_i = \text{{input}}_i * 2^\text{{other}}_i  
Typically this function is used to construct floating point numbers by multiplying mantissas in input with integral powers of two created from the exponents in :attr:’other’.  Parameters 
 
input (Tensor) – the input tensor. 
other (Tensor) – a tensor of exponents, typically integers.   Keyword Arguments 
out (Tensor, optional) – the output tensor.    Example::

>>> torch.ldexp(torch.tensor([1.]), torch.tensor([1]))
tensor([2.])
>>> torch.ldexp(torch.tensor([1.0]), torch.tensor([1, 2, 3, 4]))
tensor([ 2.,  4.,  8., 16.])
torch.le(input, other, *, out=None) → Tensor  
Computes input≤other\text{input} \leq \text{other}  element-wise. The second argument can be a number or a tensor whose shape is broadcastable with the first argument.  Parameters 
 
input (Tensor) – the tensor to compare 
other (Tensor or Scalar) – the tensor or value to compare   Keyword Arguments 
out (Tensor, optional) – the output tensor.  Returns 
A boolean tensor that is True where input is less than or equal to other and False elsewhere   Example: >>> torch.le(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
tensor([[True, False], [True, True]])
torch.lerp(input, end, weight, *, out=None)  
Does a linear interpolation of two tensors start (given by input) and end based on a scalar or tensor weight and returns the resulting out tensor.  outi=starti+weighti×(endi−starti)\text{out}_i = \text{start}_i + \text{weight}_i \times (\text{end}_i - \text{start}_i)  
The shapes of start and end must be broadcastable. If weight is a tensor, then the shapes of weight, start, and end must be broadcastable.  Parameters 
 
input (Tensor) – the tensor with the starting points 
end (Tensor) – the tensor with the ending points 
weight (float or tensor) – the weight for the interpolation formula   Keyword Arguments 
out (Tensor, optional) – the output tensor.   Example: >>> start = torch.arange(1., 5.)
>>> end = torch.empty(4).fill_(10)
>>> start
tensor([ 1.,  2.,  3.,  4.])
>>> end
tensor([ 10.,  10.,  10.,  10.])
>>> torch.lerp(start, end, 0.5)
tensor([ 5.5000,  6.0000,  6.5000,  7.0000])
>>> torch.lerp(start, end, torch.full_like(start, 0.5))
tensor([ 5.5000,  6.0000,  6.5000,  7.0000])
torch.less(input, other, *, out=None) → Tensor  
Alias for torch.lt().
torch.less_equal(input, other, *, out=None) → Tensor  
Alias for torch.le().
torch.lgamma(input, *, out=None) → Tensor  
Computes the logarithm of the gamma function on input.  outi=log⁡Γ(inputi)\text{out}_{i} = \log \Gamma(\text{input}_{i})  
 Parameters 
 
input (Tensor) – the input tensor. 
out (Tensor, optional) – the output tensor.    Example: >>> a = torch.arange(0.5, 2, 0.5)
>>> torch.lgamma(a)
tensor([ 0.5724,  0.0000, -0.1208])
torch.linalg.cholesky(input, *, out=None) → Tensor  
Computes the Cholesky decomposition of a Hermitian (or symmetric for real-valued matrices) positive-definite matrix or the Cholesky decompositions for a batch of such matrices. Each decomposition has the form:  input=LLH\text{input} = LL^H 
where LL  is a lower-triangular matrix and LHL^H  is the conjugate transpose of LL , which is just a transpose for the case of real-valued input matrices. In code it translates to input = L @ L.t() if input is real-valued and input = L @ L.conj().t() if input is complex-valued. The batch of LL  matrices is returned. Supports real-valued and complex-valued inputs.  Note When given inputs on a CUDA device, this function synchronizes that device with the CPU.   Note LAPACK’s potrf is used for CPU inputs, and MAGMA’s potrf is used for CUDA inputs.   Note If input is not a Hermitian positive-definite matrix, or if it’s a batch of matrices and one or more of them is not a Hermitian positive-definite matrix, then a RuntimeError will be thrown. If input is a batch of matrices, then the error message will include the batch index of the first matrix that is not Hermitian positive-definite.   Parameters 
input (Tensor) – the input tensor of size (∗,n,n)(*, n, n)  consisting of Hermitian positive-definite n×nn \times n  matrices, where ∗*  is zero or more batch dimensions.  Keyword Arguments 
out (Tensor, optional) – The output tensor. Ignored if None. Default: None   Examples: >>> a = torch.randn(2, 2, dtype=torch.complex128)
>>> a = torch.mm(a, a.t().conj())  # creates a Hermitian positive-definite matrix
>>> l = torch.linalg.cholesky(a)
>>> a
tensor([[2.5266+0.0000j, 1.9586-2.0626j],
        [1.9586+2.0626j, 9.4160+0.0000j]], dtype=torch.complex128)
>>> l
tensor([[1.5895+0.0000j, 0.0000+0.0000j],
        [1.2322+1.2976j, 2.4928+0.0000j]], dtype=torch.complex128)
>>> torch.mm(l, l.t().conj())
tensor([[2.5266+0.0000j, 1.9586-2.0626j],
        [1.9586+2.0626j, 9.4160+0.0000j]], dtype=torch.complex128)

>>> a = torch.randn(3, 2, 2, dtype=torch.float64)
>>> a = torch.matmul(a, a.transpose(-2, -1))  # creates a symmetric positive-definite matrix
>>> l = torch.linalg.cholesky(a)
>>> a
tensor([[[ 1.1629,  2.0237],
        [ 2.0237,  6.6593]],

        [[ 0.4187,  0.1830],
        [ 0.1830,  0.1018]],

        [[ 1.9348, -2.5744],
        [-2.5744,  4.6386]]], dtype=torch.float64)
>>> l
tensor([[[ 1.0784,  0.0000],
        [ 1.8766,  1.7713]],

        [[ 0.6471,  0.0000],
        [ 0.2829,  0.1477]],

        [[ 1.3910,  0.0000],
        [-1.8509,  1.1014]]], dtype=torch.float64)
>>> torch.allclose(torch.matmul(l, l.transpose(-2, -1)), a)
True
torch.linalg.det(input) → Tensor  
Computes the determinant of a square matrix input, or of each square matrix in a batched input. This function supports float, double, cfloat and cdouble dtypes.  Note When given inputs on a CUDA device, this function synchronizes that device with the CPU.   Note The determinant is computed using LU factorization. LAPACK’s getrf is used for CPU inputs, and MAGMA’s getrf is used for CUDA inputs.   Note Backward through det internally uses torch.linalg.svd() when input is not invertible. In this case, double backward through det will be unstable when input doesn’t have distinct singular values. See torch.linalg.svd() for more details.   Parameters 
input (Tensor) – the input matrix of size (n, n) or the batch of matrices of size (*, n, n) where * is one or more batch dimensions.   Example: >>> a = torch.randn(3, 3)
>>> a
tensor([[ 0.9478,  0.9158, -1.1295],
        [ 0.9701,  0.7346, -1.8044],
        [-0.2337,  0.0557,  0.6929]])
>>> torch.linalg.det(a)
tensor(0.0934)

>>> a = torch.randn(3, 2, 2)
>>> a
tensor([[[ 0.9254, -0.6213],
         [-0.5787,  1.6843]],

        [[ 0.3242, -0.9665],
         [ 0.4539, -0.0887]],

        [[ 1.1336, -0.4025],
         [-0.7089,  0.9032]]])
>>> torch.linalg.det(a)
tensor([1.1990, 0.4099, 0.7386])
torch.linalg.eigh(input, UPLO='L', *, out=None) -> (Tensor, Tensor)  
Computes the eigenvalues and eigenvectors of a complex Hermitian (or real symmetric) matrix input, or of each such matrix in a batched input. For a single matrix input, the tensor of eigenvalues w and the tensor of eigenvectors V decompose the input such that input = V diag(w) Vᴴ, where Vᴴ is the transpose of V for real-valued input, or the conjugate transpose of V for complex-valued input. Since the matrix or matrices in input are assumed to be Hermitian, the imaginary part of their diagonals is always treated as zero. When UPLO is “L”, its default value, only the lower triangular part of each matrix is used in the computation. When UPLO is “U” only the upper triangular part of each matrix is used. Supports input of float, double, cfloat and cdouble dtypes.  Note When given inputs on a CUDA device, this function synchronizes that device with the CPU.   Note The eigenvalues/eigenvectors are computed using LAPACK’s syevd and heevd routines for CPU inputs, and MAGMA’s syevd and heevd routines for CUDA inputs.   Note The eigenvalues of real symmetric or complex Hermitian matrices are always real.   Note The eigenvectors of matrices are not unique, so any eigenvector multiplied by a constant remains a valid eigenvector. This function may compute different eigenvector representations on different device types. Usually the difference is only in the sign of the eigenvector.   Note See torch.linalg.eigvalsh() for a related function that computes only eigenvalues. However, that function is not differentiable.   Parameters 
 
input (Tensor) – the Hermitian n times n matrix or the batch of such matrices of size (*, n, n) where * is one or more batch dimensions. 
UPLO ('L', 'U', optional) – controls whether to use the upper-triangular or the lower-triangular part of input in the computations. Default is 'L'.   Keyword Arguments 
out (tuple, optional) – tuple of two tensors to write the output to. Default is None.  Returns 
A namedtuple (eigenvalues, eigenvectors) containing  
 
eigenvalues (Tensor): Shape (*, m). 

The eigenvalues in ascending order.    
 
eigenvectors (Tensor): Shape (*, m, m). 

The orthonormal eigenvectors of the input.      Return type 
(Tensor, Tensor)   Examples: >>> a = torch.randn(2, 2, dtype=torch.complex128)
>>> a = a + a.t().conj()  # creates a Hermitian matrix
>>> a
tensor([[2.9228+0.0000j, 0.2029-0.0862j],
        [0.2029+0.0862j, 0.3464+0.0000j]], dtype=torch.complex128)
>>> w, v = torch.linalg.eigh(a)
>>> w
tensor([0.3277, 2.9415], dtype=torch.float64)
>>> v
tensor([[-0.0846+-0.0000j, -0.9964+0.0000j],
        [ 0.9170+0.3898j, -0.0779-0.0331j]], dtype=torch.complex128)
>>> torch.allclose(torch.matmul(v, torch.matmul(w.to(v.dtype).diag_embed(), v.t().conj())), a)
True

>>> a = torch.randn(3, 2, 2, dtype=torch.float64)
>>> a = a + a.transpose(-2, -1)  # creates a symmetric matrix
>>> w, v = torch.linalg.eigh(a)
>>> torch.allclose(torch.matmul(v, torch.matmul(w.diag_embed(), v.transpose(-2, -1))), a)
True