shrinath-suresh/blogs-docs-splitted huggingface dataset:
@torch.jit.script
      def fn():
          # Telling TorchScript that this empty dictionary is a (str -> int) dictionary
          # instead of default dictionary type of (str -> Tensor).
          d = torch.jit.annotate(Dict[str, int], {})
      # Without `torch.jit.annotate` above, following statement would fail because of
      # type mismatch.
      d["name"] = 20

Parameters:
      * the_type -- Python type that should be passed to
        TorchScript compiler as type hint for the_value
  * **the_value** -- Value or expression to hint type for.

Returns:
      the_value is passed back as return value.
torch.isfinite
torch.isfinite(input) -> Tensor
Returns a new tensor with boolean elements representing if each
   element is finite or not.
Real values are finite when they are not NaN, negative infinity, or
   infinity. Complex values are finite when both their real and
   imaginary parts are finite.
Parameters:
      input (Tensor) -- the input tensor.
Returns:
      A boolean tensor that is True where "input" is finite and False
      elsewhere
Example:
  >>> torch.isfinite(torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]))
  tensor([True,  False,  True,  False,  False])
torch.linspace
torch.linspace(start, end, steps, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Creates a one-dimensional tensor of size "steps" whose values are
   evenly spaced from "start" to "end", inclusive. That is, the value
   are:
  (\text{start}, \text{start} + \frac{\text{end} -
  \text{start}}{\text{steps} - 1}, \ldots, \text{start} +
  (\text{steps} - 2) * \frac{\text{end} -
  \text{start}}{\text{steps} - 1}, \text{end})

From PyTorch 1.11 linspace requires the steps argument. Use
   steps=100 to restore the previous behavior.
Parameters:
      * start (float) -- the starting value for the set of
        points
  * **end** (*float*) -- the ending value for the set of points

  * **steps** (*int*) -- size of the constructed tensor

Keyword Arguments:
      * out (Tensor, optional) -- the output tensor.
  * **dtype** (*torch.dtype**, **optional*) -- the data type to
perform the computation in. Default: if None, uses the global
        default dtype (see torch.get_default_dtype()) when both
        "start" and "end" are real, and corresponding complex dtype
        when either is complex.
  * **layout** ("torch.layout", optional) -- the desired layout of
    returned Tensor. Default: "torch.strided".

  * **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".

Example:
  >>> torch.linspace(3, 10, steps=5)
  tensor([  3.0000,   4.7500,   6.5000,   8.2500,  10.0000])
  >>> torch.linspace(-10, 10, steps=5)
torch.linspace(-10, 10, steps=5)
      tensor([-10.,  -5.,   0.,   5.,  10.])
      >>> torch.linspace(start=-10, end=10, steps=5)
      tensor([-10.,  -5.,   0.,   5.,  10.])
      >>> torch.linspace(start=-10, end=10, steps=1)
      tensor([-10.])
elu
class torch.ao.nn.quantized.functional.elu(input, scale, zero_point, alpha=1.0)
This is the quantized version of "elu()".
Parameters:
      * input (Tensor) -- quantized input
  * **scale** (*float*) -- quantization scale of the output tensor

  * **zero_point** (*int*) -- quantization zero point of the
    output tensor

  * **alpha** (*float*) -- the alpha constant

Return type:
      Tensor
PolynomialLR
class torch.optim.lr_scheduler.PolynomialLR(optimizer, total_iters=5, power=1.0, last_epoch=- 1, verbose=False)
Decays the learning rate of each parameter group using a polynomial
   function in the given total_iters. When last_epoch=-1, sets initial
   lr as lr.
Parameters:
      * optimizer (Optimizer) -- Wrapped optimizer.
  * **total_iters** (*int*) -- The number of steps that the
    scheduler decays the learning rate. Default: 5.

  * **power** (*int*) -- The power of the polynomial. Default:
    1.0.

  * **verbose** (*bool*) -- If "True", prints a message to stdout
    for each update. Default: "False".

-[ Example ]-



Assuming optimizer uses lr = 0.001 for all groups
lr = 0.001     if epoch == 0
lr = 0.00075   if epoch == 1
lr = 0.00050   if epoch == 2
lr = 0.00025   if epoch == 3
lr = 0.0       if epoch >= 4
scheduler = PolynomialLR(self.opt, total_iters=4, power=1.0)
for epoch in range(100):
    train(...)
    validate(...)
    scheduler.step()



get_last_lr()
  Return last computed learning rate by current scheduler.

load_state_dict(state_dict)
  Loads the schedulers state.

  Parameters:
     **state_dict** (*dict*) -- scheduler state. Should be an
     object returned from a call to "state_dict()".

print_lr(is_verbose, group, lr, epoch=None)
  Display the current learning rate.

state_dict()
  Returns the state of the scheduler as a "dict".

  It contains an entry for every variable in self.__dict__ which
  is not the optimizer.
ReflectionPad2d
class torch.nn.ReflectionPad2d(padding)
Pads the input tensor using the reflection of the input boundary.
For N-dimensional padding, use "torch.nn.functional.pad()".
Parameters:
      padding (int, tuple) -- the size of the padding. If is
      int, uses the same padding in all boundaries. If a 4-tuple,
      uses (\text{padding_left}, \text{padding_right},
      \text{padding_top}, \text{padding_bottom})
Shape:
      * Input: (N, C, H_{in}, W_{in}) or (C, H_{in}, W_{in}).
  * Output: (N, C, H_{out}, W_{out}) or (C, H_{out}, W_{out})
    where

    H_{out} = H_{in} + \text{padding\_top} +
    \text{padding\_bottom}

    W_{out} = W_{in} + \text{padding\_left} +
    \text{padding\_right}

Examples:
  >>> m = nn.ReflectionPad2d(2)
  >>> input = torch.arange(9, dtype=torch.float).reshape(1, 1, 3, 3)
  >>> input
  tensor([[[[0., 1., 2.],
            [3., 4., 5.],
            [6., 7., 8.]]]])
[6., 7., 8.]]]])
      >>> m(input)
      tensor([[[[8., 7., 6., 7., 8., 7., 6.],
                [5., 4., 3., 4., 5., 4., 3.],
                [2., 1., 0., 1., 2., 1., 0.],
                [5., 4., 3., 4., 5., 4., 3.],
                [8., 7., 6., 7., 8., 7., 6.],
                [5., 4., 3., 4., 5., 4., 3.],
                [2., 1., 0., 1., 2., 1., 0.]]]])
      >>> # using different paddings for different sides
      >>> m = nn.ReflectionPad2d((1, 1, 2, 0))
      >>> m(input)
      tensor([[[[7., 6., 7., 8., 7.],
                [4., 3., 4., 5., 4.],
                [1., 0., 1., 2., 1.],
                [4., 3., 4., 5., 4.],
                [7., 6., 7., 8., 7.]]]])
torch.matmul
torch.matmul(input, other, *, out=None) -> Tensor
Matrix product of two tensors.
The behavior depends on the dimensionality of the tensors as
   follows:


If both tensors are 1-dimensional, the dot product (scalar) is
     returned.


If both arguments are 2-dimensional, the matrix-matrix product is
     returned.


If the first argument is 1-dimensional and the second argument is
     2-dimensional, a 1 is prepended to its dimension for the purpose
     of the matrix multiply. After the matrix multiply, the prepended
     dimension is removed.


If the first argument is 2-dimensional and the second argument is
     1-dimensional, the matrix-vector product is returned.


If both arguments are at least 1-dimensional and at least one
     argument is N-dimensional (where N > 2), then a batched matrix
     multiply is returned.  If the first argument is 1-dimensional, a
     1 is prepended to its dimension for the purpose of the batched
matrix multiply and removed after.  If the second argument is
     1-dimensional, a 1 is appended to its dimension for the purpose
     of the batched matrix multiple and removed after. The non-matrix
     (i.e. batch) dimensions are broadcasted (and thus must be
     broadcastable).  For example, if "input" is a (j \times 1 \times
     n \times n) tensor and "other" is a (k \times n \times n) tensor,
     "out" will be a (j \times k \times n \times n) tensor.
 Note that the broadcasting logic only looks at the batch
 dimensions when determining if the inputs are broadcastable, and
 not the matrix dimensions. For example, if "input" is a (j \times
 1 \times n \times m) tensor and "other" is a (k \times m \times
 p) tensor, these inputs are valid for broadcasting even though
 the final two dimensions (i.e. the matrix dimensions) are
 different. "out" will be a (j \times k \times n \times p) tensor.

This operation has support for arguments with sparse layouts. In
particular the matrix-matrix (both arguments 2-dimensional)
   supports sparse arguments with the same restrictions as
   "torch.mm()"
Warning:
 Sparse support is a beta feature and some layout(s)/dtype/device
 combinations may not be supported, or may not have autograd
 support. If you notice missing functionality please open a
 feature request.

This operator supports TensorFloat32.
On certain ROCm devices, when using float16 inputs this module will
   use different precision for backward.
Note:
 The 1-dimensional dot product version of this function does not
 support an "out" parameter.

Parameters:
      * input (Tensor) -- the first tensor to be multiplied
  * **other** (*Tensor*) -- the second tensor to be multiplied

Keyword Arguments:
      out (Tensor, optional) -- the output tensor.
Example:
  >>> # vector x vector
  >>> tensor1 = torch.randn(3)
  >>> tensor2 = torch.randn(3)
tensor2 = torch.randn(3)
      >>> torch.matmul(tensor1, tensor2).size()
      torch.Size([])
      >>> # matrix x vector
      >>> tensor1 = torch.randn(3, 4)
      >>> tensor2 = torch.randn(4)
      >>> torch.matmul(tensor1, tensor2).size()
      torch.Size([3])
      >>> # batched matrix x broadcasted vector
      >>> tensor1 = torch.randn(10, 3, 4)
      >>> tensor2 = torch.randn(4)
      >>> torch.matmul(tensor1, tensor2).size()
      torch.Size([10, 3])
      >>> # batched matrix x batched matrix
      >>> tensor1 = torch.randn(10, 3, 4)
      >>> tensor2 = torch.randn(10, 4, 5)
      >>> torch.matmul(tensor1, tensor2).size()
      torch.Size([10, 3, 5])
      >>> # batched matrix x broadcasted matrix
      >>> tensor1 = torch.randn(10, 3, 4)
      >>> tensor2 = torch.randn(4, 5)
      >>> torch.matmul(tensor1, tensor2).size()
      torch.Size([10, 3, 5])
Linear
class torch.ao.nn.quantized.Linear(in_features, out_features, bias_=True, dtype=torch.qint8)
A quantized linear module with quantized tensor as inputs and
   outputs. 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 "Linear", attributes will be randomly initialized at
   module creation time and will be overwritten later
Variables:
      * weight (Tensor) -- the non-learnable quantized weights
        of the module of shape (\text{out_features},
        \text{in_features}).
  * **bias** (*Tensor*) -- the non-learnable bias of the module of
    shape (\text{out\_features}). If "bias" is "True", the values
    are initialized to zero.

  * **scale** -- *scale* parameter of output Quantized Tensor,
    type: double

  * **zero_point** -- *zero_point* parameter for output Quantized
    Tensor, type: long

Examples:
Tensor, type: long
Examples:
  >>> m = nn.quantized.Linear(20, 30)
  >>> input = torch.randn(128, 20)
  >>> input = torch.quantize_per_tensor(input, 1.0, 0, torch.quint8)
  >>> output = m(input)
  >>> print(output.size())
  torch.Size([128, 30])

classmethod from_float(mod)
  Create a quantized module from an observed float module

  Parameters:
     **mod** (*Module*) -- a float module, either produced by
     torch.ao.quantization utilities or provided by the user

classmethod from_reference(ref_qlinear, output_scale, output_zero_point)
  Create a (fbgemm/qnnpack) quantized module from a reference
  quantized module

  Parameters:
     * **ref_qlinear** (*Module*) -- a reference quantized linear
       module, either produced by torch.ao.quantization utilities
       or provided by the user

     * **output_scale** (*float*) -- scale for output Tensor

     * **output_zero_point** (*int*) -- zero point for output
torch.lerp
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.
  \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.])
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.nn.functional.softmax
torch.nn.functional.softmax(input, dim=None, _stacklevel=3, dtype=None)
Applies a softmax function.
Softmax is defined as:
\text{Softmax}(x_{i}) = \frac{\exp(x_i)}{\sum_j \exp(x_j)}
It is applied to all slices along dim, and will re-scale them so
   that the elements lie in the range [0, 1] and sum to 1.
See "Softmax" for more details.
Parameters:
      * input (Tensor) -- input
  * **dim** (*int*) -- A dimension along which softmax will be
    computed.

  * **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.

Return type:
      Tensor
Note:
 This function doesn't work directly with NLLLoss, which expects
 the Log to be computed between the Softmax and itself. Use
torch.addr
torch.addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) -> Tensor
Performs the outer-product of vectors "vec1" and "vec2" and adds it
   to the matrix "input".
Optional values "beta" and "alpha" are scaling factors on the outer
   product between "vec1" and "vec2" and the added matrix "input"
   respectively.
  \text{out} = \beta\ \text{input} + \alpha\ (\text{vec1} \otimes
  \text{vec2})

If "beta" is 0, then "input" will be ignored, and nan and inf
   in it will not be propagated.
If "vec1" is a vector of size n and "vec2" is a vector of size
   m, then "input" must be broadcastable with a matrix of size (n
   \times m) and "out" will be a matrix of size (n \times m).
Parameters:
      * input (Tensor) -- matrix to be added
  * **vec1** (*Tensor*) -- the first vector of the outer product

  * **vec2** (*Tensor*) -- the second vector of the outer product

Keyword Arguments:
Keyword Arguments:
      * beta (Number, optional) -- multiplier for "input"
        (\beta)
  * **alpha** (*Number**, **optional*) -- multiplier for
    \text{vec1} \otimes \text{vec2} (\alpha)

  * **out** (*Tensor**, **optional*) -- the output tensor.

Example:
  >>> vec1 = torch.arange(1., 4.)
  >>> vec2 = torch.arange(1., 3.)
  >>> M = torch.zeros(3, 2)
  >>> torch.addr(M, vec1, vec2)
  tensor([[ 1.,  2.],
          [ 2.,  4.],
          [ 3.,  6.]])
torch.linalg.pinv
torch.linalg.pinv(A, *, atol=None, rtol=None, hermitian=False, out=None) -> Tensor
Computes the pseudoinverse (Moore-Penrose inverse) of a matrix.
The pseudoinverse may be defined algebraically but it is more
   computationally convenient to understand it through the SVD
Supports input of float, double, cfloat and cdouble dtypes. Also
   supports batches of matrices, and if "A" is a batch of matrices
   then the output has the same batch dimensions.
If "hermitian"= True, "A" is assumed to be Hermitian if complex
   or symmetric if real, but this is not checked internally. Instead,
   just the lower triangular part of the matrix is used in the
   computations.
The singular values (or the norm of the eigenvalues when
   "hermitian"= True) that are below \max(\text{atol}, \sigma_1
   \cdot \text{rtol}) threshold are treated as zero and discarded in
   the computation, where \sigma_1 is the largest singular value (or
   eigenvalue).
eigenvalue).
If "rtol" is not specified and "A" is a matrix of dimensions (m,
   n), the relative tolerance is set to be \text{rtol} = \max(m, n)
   \varepsilon and \varepsilon is the epsilon value for the dtype of
   "A" (see "finfo"). If "rtol" is not specified and "atol" is
   specified to be larger than zero then "rtol" is set to zero.
If "atol" or "rtol" is a "torch.Tensor", its shape must be
   broadcastable to that of the singular values of "A" as returned by
   "torch.linalg.svd()".
Note:
 This function uses "torch.linalg.svd()" if "hermitian"*= False*
 and "torch.linalg.eigh()" if "hermitian"*= True*. For CUDA
 inputs, this function synchronizes that device with the CPU.

Note:
 Consider using "torch.linalg.lstsq()" if possible for multiplying
 a matrix on the left by the pseudoinverse, as:

    torch.linalg.lstsq(A, B).solution == A.pinv() @ B

 It is always preferred to use "lstsq()" when possible, as it is
faster and more numerically stable than computing the
     pseudoinverse explicitly.
Note:
 This function has NumPy compatible variant *linalg.pinv(A, rcond,
 hermitian=False)*. However, use of the positional argument
 "rcond" is deprecated in favor of "rtol".

Warning:
 This function uses internally "torch.linalg.svd()" (or
 "torch.linalg.eigh()" when "hermitian"*= True*), so its
 derivative has the same problems as those of these functions. See
 the warnings in "torch.linalg.svd()" and "torch.linalg.eigh()"
 for more details.

See also:
 "torch.linalg.inv()" computes the inverse of a square matrix.

 "torch.linalg.lstsq()" computes "A"*.pinv() @ *"B" with a
 numerically stable algorithm.

Parameters:
      * A (Tensor) -- tensor of shape (, m, n)* where *** is
        zero or more batch dimensions.
  * **rcond** (*float**, **Tensor**, **optional*) -- [NumPy
    Compat]. Alias for "rtol". Default: *None*.

Keyword Arguments:
Keyword Arguments:
      * atol (float, Tensor, optional) -- the absolute
        tolerance value. When None it's considered to be zero.
        Default: None.
  * **rtol** (*float**, **Tensor**, **optional*) -- the relative
    tolerance value. See above for the value it takes when *None*.
    Default: *None*.

  * **hermitian** (*bool**, **optional*) -- indicates whether "A"
    is Hermitian if complex or symmetric if real. Default:
    *False*.

  * **out** (*Tensor**, **optional*) -- output tensor. Ignored if
    *None*. Default: *None*.

Examples:
  >>> A = torch.randn(3, 5)
  >>> A
  tensor([[ 0.5495,  0.0979, -1.4092, -0.1128,  0.4132],
          [-1.1143, -0.3662,  0.3042,  1.6374, -0.9294],
          [-0.3269, -0.5745, -0.0382, -0.5922, -0.6759]])
  >>> torch.linalg.pinv(A)
  tensor([[ 0.0600, -0.1933, -0.2090],
          [-0.0903, -0.0817, -0.4752],
          [-0.7124, -0.1631, -0.2272],
[-0.7124, -0.1631, -0.2272],
              [ 0.1356,  0.3933, -0.5023],
              [-0.0308, -0.1725, -0.5216]])
  >>> A = torch.randn(2, 6, 3)
  >>> Apinv = torch.linalg.pinv(A)
  >>> torch.dist(Apinv @ A, torch.eye(3))
  tensor(8.5633e-07)

  >>> A = torch.randn(3, 3, dtype=torch.complex64)
  >>> A = A + A.T.conj()  # creates a Hermitian matrix
  >>> Apinv = torch.linalg.pinv(A, hermitian=True)
  >>> torch.dist(Apinv @ A, torch.eye(3))
  tensor(1.0830e-06)
HingeEmbeddingLoss
class torch.nn.HingeEmbeddingLoss(margin=1.0, size_average=None, reduce=None, reduction='mean')
Measures the loss given an input tensor x and a labels tensor y
   (containing 1 or -1). This is usually used for measuring whether
   two inputs are similar or dissimilar, e.g. using the L1 pairwise
   distance as x, and is typically used for learning nonlinear
   embeddings or semi-supervised learning.
The loss function for n-th sample in the mini-batch is
  l_n = \begin{cases}     x_n, & \text{if}\; y_n = 1,\\     \max
  \{0, \Delta - x_n\}, & \text{if}\; y_n = -1, \end{cases}

and the total loss functions is
  \ell(x, y) = \begin{cases}     \operatorname{mean}(L), &
  \text{if reduction} = \text{`mean';}\\
  \operatorname{sum}(L),  & \text{if reduction} = \text{`sum'.}
  \end{cases}

where L = {l_1,\dots,l_N}^\top.
Parameters:
      * margin (float, optional) -- Has a default value of
        1.
1.
  * **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** (*str**, **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: (*) where * means, any number of dimensions. The sum
        operation operates over all the elements.
  * Target: (*), same shape as the input

  * Output: scalar. If "reduction" is "'none'", then same shape as
    the input
torch.set_default_device
torch.set_default_device(device)
Sets the default "torch.Tensor" to be allocated on "device".  This
   does not affect factory function calls which are called with an
   explicit "device" argument.  Factory calls will be performed as if
   they were passed "device" as an argument.
To only temporarily change the default device instead of setting it
   globally, use "with torch.device(device):" instead.
The default device is initially "cpu".  If you set the default
   tensor device to another device (e.g., "cuda") without a device
   index, tensors will be allocated on whatever the current device for
   the device type, even after "torch.cuda.set_device()" is called.
Warning:
 This function imposes a slight performance cost on every Python
 call to the torch API (not just factory functions).  If this is
 causing problems for you, please comment on
 https://github.com/pytorch/pytorch/issues/92701

Parameters:
Parameters:
      device (device or string) -- the device to set as
      default
Example:
  >>> torch.tensor([1.2, 3]).device
  device(type='cpu')
  >>> torch.set_default_device('cuda')  # current device is 0
  >>> torch.tensor([1.2, 3]).device
  device(type='cuda', index=0)
  >>> torch.set_default_device('cuda:1')
  >>> torch.tensor([1.2, 3]).device
  device(type='cuda', index=1)