shrinath-suresh/blogs-docs-splitted huggingface dataset:
torch.cat
torch.cat(tensors, dim=0, *, out=None) -> Tensor
Concatenates the given sequence of "seq" tensors in the given
   dimension. All tensors must either have the same shape (except in
   the concatenating dimension) or be empty.
"torch.cat()" can be seen as an inverse operation for
   "torch.split()" and "torch.chunk()".
"torch.cat()" can be best understood via examples.
Parameters:
      * tensors (sequence of Tensors) -- any python sequence of
        tensors of the same type. Non-empty tensors provided must have
        the same shape, except in the cat dimension.
  * **dim** (*int**, **optional*) -- the dimension over which the
    tensors are concatenated

Keyword Arguments:
      out (Tensor, optional) -- the output tensor.
Example:
  >>> x = torch.randn(2, 3)
  >>> x
  tensor([[ 0.6580, -1.0969, -0.4614],
          [-0.1034, -0.5790,  0.1497]])
  >>> torch.cat((x, x, x), 0)
  tensor([[ 0.6580, -1.0969, -0.4614],
tensor([[ 0.6580, -1.0969, -0.4614],
              [-0.1034, -0.5790,  0.1497],
              [ 0.6580, -1.0969, -0.4614],
              [-0.1034, -0.5790,  0.1497],
              [ 0.6580, -1.0969, -0.4614],
              [-0.1034, -0.5790,  0.1497]])
      >>> torch.cat((x, x, x), 1)
      tensor([[ 0.6580, -1.0969, -0.4614,  0.6580, -1.0969, -0.4614,  0.6580,
               -1.0969, -0.4614],
              [-0.1034, -0.5790,  0.1497, -0.1034, -0.5790,  0.1497, -0.1034,
               -0.5790,  0.1497]])
torch.load
torch.load(f, map_location=None, pickle_module=pickle, , weights_only=False, *pickle_load_args)
Loads an object saved with "torch.save()" from a file.
"torch.load()" uses Python's unpickling facilities but treats
   storages, which underlie tensors, specially. They are first
   deserialized on the CPU and are then moved to the device they were
   saved from. If this fails (e.g. because the run time system doesn't
   have certain devices), an exception is raised. However, storages
   can be dynamically remapped to an alternative set of devices using
   the "map_location" argument.
If "map_location" is a callable, it will be called once for each
   serialized storage with two arguments: storage and location. The
   storage argument will be the initial deserialization of the
   storage, residing on the CPU. Each serialized storage has a
   location tag associated with it which identifies the device it was
   saved from, and this tag is the second argument passed to
"map_location". The builtin location tags are "'cpu'" for CPU
   tensors and "'cuda:device_id'" (e.g. "'cuda:2'") for CUDA tensors.
   "map_location" should return either "None" or a storage. If
   "map_location" returns a storage, it will be used as the final
   deserialized object, already moved to the right device. Otherwise,
   "torch.load()" will fall back to the default behavior, as if
   "map_location" wasn't specified.
If "map_location" is a "torch.device" object or a string containing
   a device tag, it indicates the location where all tensors should be
   loaded.
Otherwise, if "map_location" is a dict, it will be used to remap
   location tags appearing in the file (keys), to ones that specify
   where to put the storages (values).
User extensions can register their own location tags and tagging
   and deserialization methods using
   "torch.serialization.register_package()".
Parameters:
      * f (Union[str, PathLike, BinaryIO*,
IO[bytes]*]) -- a file-like object (has to implement
        "read()", "readline()", "tell()", and "seek()"), or a string
        or os.PathLike object containing a file name
  * **map_location**
    (*Optional**[**Union**[**Callable**[**[**Tensor**, **str**]**,
    **Tensor**]**, **device**, **str**, **Dict**[**str**,
    **str**]**]**]*) -- a function, "torch.device", string or a
    dict specifying how to remap storage locations

  * **pickle_module** (*Optional**[**Any**]*) -- module used for
    unpickling metadata and objects (has to match the
    "pickle_module" used to serialize file)

  * **weights_only** (*bool*) -- Indicates whether unpickler
    should be restricted to loading only tensors, primitive types
    and dictionaries

  * **pickle_load_args** (*Any*) -- (Python 3 only) optional
    keyword arguments passed over to "pickle_module.load()" and
    "pickle_module.Unpickler()", e.g., "errors=...".

Return type:
Return type:
      Any
Warning:
 "torch.load()" unless *weights_only* parameter is set to *True*,
 uses "pickle" module implicitly, which is known to be insecure.
 It is possible to construct malicious pickle data which will
 execute arbitrary code during unpickling. Never load data that
 could have come from an untrusted source in an unsafe mode, or
 that could have been tampered with. **Only load data you trust**.

Note:
 When you call "torch.load()" on a file which contains GPU
 tensors, those tensors will be loaded to GPU by default. You can
 call "torch.load(.., map_location='cpu')" and then
 "load_state_dict()" to avoid GPU RAM surge when loading a model
 checkpoint.

Note:
 By default, we decode byte strings as "utf-8".  This is to avoid
 a common error case "UnicodeDecodeError: 'ascii' codec can't
 decode byte 0x..." when loading files saved by Python 2 in Python
If this default is incorrect, you may use an extra "encoding"
     keyword argument to specify how these objects should be loaded,
     e.g., "encoding='latin1'" decodes them to strings using "latin1"
     encoding, and "encoding='bytes'" keeps them as byte arrays which
     can be decoded later with "byte_array.decode(...)".

-[ Example ]-



torch.load('tensors.pt')
   # Load all tensors onto the CPU
torch.load('tensors.pt', map_location=torch.device('cpu'))
   # Load all tensors onto the CPU, using a function
torch.load('tensors.pt', map_location=lambda storage, loc: storage)
   # Load all tensors onto GPU 1
torch.load('tensors.pt', map_location=lambda storage, loc: storage.cuda(1))
   # Map tensors from GPU 1 to GPU 0
torch.load('tensors.pt', map_location={'cuda:1': 'cuda:0'})
   # Load tensor from io.BytesIO object
with open('tensor.pt', 'rb') as f:
   ...     buffer = io.BytesIO(f.read())
torch.load(buffer)
torch.quantile
torch.quantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) -> Tensor
Computes the q-th quantiles of each row of the "input" tensor along
   the dimension "dim".
To compute the quantile, we map q in [0, 1] to the range of indices
   [0, n] to find the location of the quantile in the sorted input. If
   the quantile lies between two data points "a < b" with indices "i"
   and "j" in the sorted order, result is computed according to the
   given "interpolation" method as follows:


"linear": "a + (b - a) * fraction", where "fraction" is the
     fractional part of the computed quantile index.


"lower": "a".


"higher": "b".


"nearest": "a" or "b", whichever's index is closer to the
     computed quantile index (rounding down for .5 fractions).


"midpoint": "(a + b) / 2".


If "q" is a 1D tensor, the first dimension of the output represents
   the quantiles and has size equal to the size of "q", the remaining
dimensions are what remains from the reduction.
Note:
 By default "dim" is "None" resulting in the "input" tensor being
 flattened before computation.

Parameters:
      * input (Tensor) -- the input tensor.
  * **q** (*float** or **Tensor*) -- a scalar or 1D tensor of
    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:
      * interpolation (str) -- interpolation method to use when
        the desired quantile lies between two data points. Can be
        "linear", "lower", "higher", "midpoint" and "nearest". Default
        is "linear".
  * **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])
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])
  >>> a = torch.arange(4.)
  >>> a
  tensor([0., 1., 2., 3.])
  >>> torch.quantile(a, 0.6, interpolation='linear')
  tensor(1.8000)
  >>> torch.quantile(a, 0.6, interpolation='lower')
  tensor(1.)
  >>> torch.quantile(a, 0.6, interpolation='higher')
  tensor(2.)
  >>> torch.quantile(a, 0.6, interpolation='midpoint')
  tensor(1.5000)
  >>> torch.quantile(a, 0.6, interpolation='nearest')
  tensor(2.)
  >>> torch.quantile(a, 0.4, interpolation='nearest')
  tensor(1.)
torch.Tensor.to
Tensor.to(args, *kwargs) -> Tensor
Performs Tensor dtype and/or device conversion. A "torch.dtype" and
   "torch.device" are inferred from the arguments of "self.to(args,
   *kwargs)".
Note:
 If the "self" Tensor already has the correct "torch.dtype" and
 "torch.device", then "self" is returned. Otherwise, the returned
 tensor is a copy of "self" with the desired "torch.dtype" and
 "torch.device".

Here are the ways to call "to":
to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
     Returns a Tensor with the specified "dtype"

     Args:
        memory_format ("torch.memory_format", optional): the
        desired memory format of returned Tensor. Default:
        "torch.preserve_format".

torch.to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) -> Tensor
     Returns a Tensor with the specified "device" and (optional)
"dtype". If "dtype" is "None" it is inferred to be
         "self.dtype". When "non_blocking", tries to convert
         asynchronously with respect to the host if possible, e.g.,
         converting a CPU Tensor with pinned memory to a CUDA Tensor.
         When "copy" is set, a new Tensor is created even when the
         Tensor already matches the desired conversion.
     Args:
        memory_format ("torch.memory_format", optional): the
        desired memory format of returned Tensor. Default:
        "torch.preserve_format".

torch.to(other, non_blocking=False, copy=False) -> Tensor
     Returns a Tensor with same "torch.dtype" and "torch.device"
     as the Tensor "other". When "non_blocking", tries to convert
     asynchronously with respect to the host if possible, e.g.,
     converting a CPU Tensor with pinned memory to a CUDA Tensor.
     When "copy" is set, a new Tensor is created even when the
Tensor already matches the desired conversion.
Example:
  >>> tensor = torch.randn(2, 2)  # Initially dtype=float32, device=cpu
  >>> tensor.to(torch.float64)
  tensor([[-0.5044,  0.0005],
          [ 0.3310, -0.0584]], dtype=torch.float64)

  >>> cuda0 = torch.device('cuda:0')
  >>> tensor.to(cuda0)
  tensor([[-0.5044,  0.0005],
          [ 0.3310, -0.0584]], device='cuda:0')

  >>> tensor.to(cuda0, dtype=torch.float64)
  tensor([[-0.5044,  0.0005],
          [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')

  >>> other = torch.randn((), dtype=torch.float64, device=cuda0)
  >>> tensor.to(other, non_blocking=True)
  tensor([[-0.5044,  0.0005],
          [ 0.3310, -0.0584]], dtype=torch.float64, device='cuda:0')
add_quant_dequant
class torch.quantization.add_quant_dequant(module)
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
  * **quantize** (*that we want to*) --

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.
RecordingObserver
class torch.quantization.observer.RecordingObserver(dtype=torch.quint8, **kwargs)
The module is mainly for debug and records the tensor values during
   runtime.
Parameters:
      * dtype -- Quantized data type
  * **qscheme** -- Quantization scheme to be used

  * **reduce_range** -- Reduces the range of the quantized data
    type by 1 bit
torch.broadcast_to
torch.broadcast_to(input, shape) -> Tensor
Broadcasts "input" to the shape "shape". Equivalent to calling
   "input.expand(shape)". See "expand()" for details.
Parameters:
      * input (Tensor) -- the input tensor.
  * **shape** (list, tuple, or "torch.Size") -- the new shape.

Example:
  >>> x = torch.tensor([1, 2, 3])
  >>> torch.broadcast_to(x, (3, 3))
  tensor([[1, 2, 3],
          [1, 2, 3],
          [1, 2, 3]])
Hardswish
class torch.nn.Hardswish(inplace=False)
Applies the Hardswish function, element-wise, as described in the
   paper: Searching for MobileNetV3.
Hardswish is defined as:
  \text{Hardswish}(x) = \begin{cases}     0 & \text{if~} x \le -3,
  \\     x & \text{if~} x \ge +3, \\     x \cdot (x + 3) /6 &
  \text{otherwise} \end{cases}

Parameters:
      inplace (bool) -- can optionally do the operation in-
      place. Default: "False"
Shape:
      * Input: (*), where * means any number of dimensions.
  * Output: (*), same shape as the input.

[image]
Examples:
  >>> m = nn.Hardswish()
  >>> input = torch.randn(2)
  >>> output = m(input)
ReduceLROnPlateau
class torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='min', factor=0.1, patience=10, threshold=0.0001, threshold_mode='rel', cooldown=0, min_lr=0, eps=1e-08, verbose=False)
Reduce learning rate when a metric has stopped improving. Models
   often benefit from reducing the learning rate by a factor of 2-10
   once learning stagnates. This scheduler reads a metrics quantity
   and if no improvement is seen for a 'patience' number of epochs,
   the learning rate is reduced.
Parameters:
      * optimizer (Optimizer) -- Wrapped optimizer.
  * **mode** (*str*) -- One of *min*, *max*. In *min* mode, lr
    will be reduced when the quantity monitored has stopped
    decreasing; in *max* mode it will be reduced when the quantity
    monitored has stopped increasing. Default: 'min'.

  * **factor** (*float*) -- Factor by which the learning rate will
    be reduced. new_lr = lr * factor. Default: 0.1.
patience (int) -- Number of epochs with no improvement
        after which learning rate will be reduced. For example, if
        patience = 2, then we will ignore the first 2 epochs with no
        improvement, and will only decrease the LR after the 3rd epoch
        if the loss still hasn't improved then. Default: 10.


threshold (float) -- Threshold for measuring the new
    optimum, to only focus on significant changes. Default: 1e-4.


threshold_mode (str) -- One of rel, abs. In rel
    mode, dynamic_threshold = best * ( 1 + threshold ) in 'max'
    mode or best * ( 1 - threshold ) in min mode. In abs mode,
    dynamic_threshold = best + threshold in max mode or best -
    threshold in min mode. Default: 'rel'.


cooldown (int) -- Number of epochs to wait before
    resuming normal operation after lr has been reduced. Default:
    0.


min_lr (float or list) -- A scalar or a list of
scalars. A lower bound on the learning rate of all param
        groups or each group respectively. Default: 0.
  * **eps** (*float*) -- Minimal decay applied to lr. If the
    difference between new and old lr is smaller than eps, the
    update is ignored. Default: 1e-8.

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

-[ Example ]-



optimizer = torch.optim.SGD(model.parameters(), lr=0.1, momentum=0.9)
scheduler = ReduceLROnPlateau(optimizer, 'min')
for epoch in range(10):
    train(...)
    val_loss = validate(...)
    # Note that step should be called after validate()
    scheduler.step(val_loss)
UninitializedBuffer
class torch.nn.parameter.UninitializedBuffer(requires_grad=False, device=None, dtype=None)
A buffer that is not initialized.
Uninitialized Buffer is a a special case of "torch.Tensor" where
   the shape of the data is still unknown.
Unlike a "torch.Tensor", 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.Tensor".
The default device or dtype to use when the buffer is materialized
   can be set during construction using e.g. "device='cuda'".
ConvTranspose3d
class torch.ao.nn.quantized.ConvTranspose3d(in_channels, out_channels, kernel_size, stride=1, padding=0, output_padding=0, groups=1, bias=True, dilation=1, padding_mode='zeros', device=None, dtype=None)
Applies a 3D transposed convolution operator over an input image
   composed of several input planes. For details on input arguments,
   parameters, and implementation see "ConvTranspose3d".
Note:
 Currently only the FBGEMM engine is implemented. Please, set the
 *torch.backends.quantized.engine = 'fbgemm'*

For special notes, please, see "Conv3d"
Variables:
      * weight (Tensor) -- packed tensor derived from the
        learnable weight parameter.
  * **scale** (*Tensor*) -- scalar for the output scale

  * **zero_point** (*Tensor*) -- scalar for the output zero point

See "ConvTranspose3d" for other attributes.
Examples:
  >>> torch.backends.quantized.engine = 'fbgemm'
  >>> from torch.nn import quantized as nnq
from torch.nn import quantized as nnq
      >>> # With cubic kernels and equal stride
      >>> m = nnq.ConvTranspose3d(16, 33, 3, stride=2)
      >>> # non-cubic kernels and unequal stride and with padding
      >>> m = nnq.ConvTranspose3d(16, 33, (3, 3, 5), stride=(2, 1, 1), padding=(4, 2, 2))
      >>> input = torch.randn(20, 16, 50, 100, 100)
      >>> q_input = torch.quantize_per_tensor(input, scale=1.0, zero_point=0, dtype=torch.quint8)
      >>> output = m(q_input)
      >>> # exact output size can be also specified as an argument
      >>> input = torch.randn(1, 16, 12, 12, 12)
      >>> q_input = torch.quantize_per_tensor(input, scale=1.0, zero_point=0, dtype=torch.quint8)
      >>> downsample = nnq.Conv3d(16, 16, 3, stride=2, padding=1)
      >>> upsample = nnq.ConvTranspose3d(16, 16, 3, stride=2, padding=1)
      >>> h = downsample(q_input)
      >>> h.size()
      torch.Size([1, 16, 6, 6, 6])
      >>> output = upsample(h, output_size=input.size())
      >>> output.size()
torch.autograd.function.FunctionCtx.mark_dirty
FunctionCtx.mark_dirty(*args)
Marks given tensors as modified in an in-place operation.
This should be called at most once, only from inside the
   "forward()" method, and all arguments should be inputs.
Every tensor that's been modified in-place in a call to "forward()"
   should be given to this function, to ensure correctness of our
   checks. It doesn't matter whether the function is called before or
   after modification.
Examples::
      >>> class Inplace(Function):
      >>>     @staticmethod
      >>>     def forward(ctx, x):
      >>>         x_npy = x.numpy() # x_npy shares storage with x
      >>>         x_npy += 1
      >>>         ctx.mark_dirty(x)
      >>>         return x
      >>>
      >>>     @staticmethod
      >>>     @once_differentiable
      >>>     def backward(ctx, grad_output):
      >>>         return grad_output
      >>>
return grad_output
  >>>
  >>> a = torch.tensor(1., requires_grad=True, dtype=torch.double).clone()
  >>> b = a * a
  >>> Inplace.apply(a)  # This would lead to wrong gradients!
  >>>                   # but the engine would not know unless we mark_dirty
  >>> b.backward() # RuntimeError: one of the variables needed for gradient
  >>>              # computation has been modified by an inplace operation
torch.quantize_per_tensor
torch.quantize_per_tensor(input, scale, zero_point, dtype) -> Tensor
Converts a float tensor to a quantized tensor with given scale and
   zero point.
Parameters:
      * input (Tensor) -- float tensor or list of tensors to
        quantize
  * **scale** (*float** or **Tensor*) -- scale to apply in
    quantization formula

  * **zero_point** (*int** or **Tensor*) -- offset in integer
    value that maps to float zero

  * **dtype** ("torch.dtype") -- the desired data type of returned
    tensor. Has to be one of the quantized dtypes: "torch.quint8",
    "torch.qint8", "torch.qint32"

Returns:
      A newly quantized tensor or list of quantized tensors.
Return type:
      Tensor
Example:
  >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8)
  tensor([-1.,  0.,  1.,  2.], size=(4,), dtype=torch.quint8,
quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10)
      >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8).int_repr()
      tensor([ 0, 10, 20, 30], dtype=torch.uint8)
      >>> torch.quantize_per_tensor([torch.tensor([-1.0, 0.0]), torch.tensor([-2.0, 2.0])],
      >>> torch.tensor([0.1, 0.2]), torch.tensor([10, 20]), torch.quint8)
      (tensor([-1.,  0.], size=(2,), dtype=torch.quint8,
          quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10),
          tensor([-2.,  2.], size=(2,), dtype=torch.quint8,
          quantization_scheme=torch.per_tensor_affine, scale=0.2, zero_point=20))
      >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), torch.tensor(0.1), torch.tensor(10), torch.quint8)
      tensor([-1.,  0.,  1.,  2.], size=(4,), dtype=torch.quint8,
         quantization_scheme=torch.per_tensor_affine, scale=0.10, zero_point=10)
torch.svd_lowrank
torch.svd_lowrank(A, q=6, niter=2, M=None)
Return the singular value decomposition "(U, S, V)" of a matrix,
   batches of matrices, or a sparse matrix A such that A \approx U
   diag(S) V^T. In case M is given, then SVD is computed for the
   matrix A - M.
Note:
 The implementation is based on the Algorithm 5.1 from Halko et
 al, 2009.

Note:
 To obtain repeatable results, reset the seed for the pseudorandom
 number generator

Note:
 The input is assumed to be a low-rank matrix.

Note:
 In general, use the full-rank SVD implementation
 "torch.linalg.svd()" for dense matrices due to its 10-fold higher
 performance characteristics. The low-rank SVD will be useful for
 huge sparse matrices that "torch.linalg.svd()" cannot handle.

Args::
      A (Tensor): the input tensor of size (*, m, n)
  q (int, optional): a slightly overestimated rank of A.

  niter (int, optional): the number of subspace iterations to
conduct; niter must be a nonnegative integer, and defaults to
         2
  M (Tensor, optional): the input tensor's mean of size
     (*, 1, n).

References::
      * Nathan Halko, Per-Gunnar Martinsson, and Joel Tropp, Finding
        structure with randomness: probabilistic algorithms for
        constructing approximate matrix decompositions,
        arXiv:0909.4061 [math.NA; math.PR], 2009 (available at arXiv).
Return type:
      Tuple[Tensor, Tensor, Tensor]
torch.allclose
torch.allclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False) -> bool
This function checks if "input" and "other" satisfy the condition:
  \lvert \text{input} - \text{other} \rvert \leq \texttt{atol} +
  \texttt{rtol} \times \lvert \text{other} \rvert

elementwise, for all elements of "input" and "other". The behaviour
   of this function is analogous to numpy.allclose
Parameters:
      * input (Tensor) -- first tensor to compare
  * **other** (*Tensor*) -- second tensor to compare

  * **atol** (*float**, **optional*) -- absolute tolerance.
    Default: 1e-08

  * **rtol** (*float**, **optional*) -- relative tolerance.
    Default: 1e-05

  * **equal_nan** (*bool**, **optional*) -- if "True", then two
    "NaN" s will be considered equal. Default: "False"

Example:
  >>> torch.allclose(torch.tensor([10000., 1e-07]), torch.tensor([10000.1, 1e-08]))
  False