shrinath-suresh/blogs-docs-splitted huggingface dataset:
DTypeWithConstraints
class torch.ao.quantization.backend_config.DTypeWithConstraints(dtype=None, quant_min_lower_bound=None, quant_max_upper_bound=None, scale_min_lower_bound=None, scale_max_upper_bound=None, scale_exact_match=None, zero_point_exact_match=None)
Config for specifying additional constraints for a given dtype,
   such as quantization value ranges, scale value ranges, and fixed
   quantization params, to be used in "DTypeConfig".
The constraints currently supported are:


quant_min_lower_bound and quant_max_upper_bound: Lower and
     upper bounds for the minimum and maximum quantized values
     respectively. If the QConfigâs quant_min and quant_max fall
     outside this range, then the QConfig will be ignored.


scale_min_lower_bound and scale_max_upper_bound: Lower and
     upper bounds for the minimum and maximum scale values
     respectively. If the QConfigâs minimum scale value (currently
exposed as eps) falls below the lower bound, then the QConfig
     will be ignored. Note that the upper bound is currently not
     enforced.

scale_exact_match and zero_point_exact_match: Exact match
     requirements for scale and zero point, to be used for operators
     with fixed quantization parameters such as sigmoid and tanh. If
     the observer specified in the QConfig is neither
     FixedQParamsObserver nor FixedQParamsFakeQuantize, or if the
     quantization parameters don't match, then the QConfig will be
     ignored.
Hardtanh
class torch.nn.Hardtanh(min_val=- 1.0, max_val=1.0, inplace=False, min_value=None, max_value=None)
Applies the HardTanh function element-wise.
HardTanh is defined as:
  \text{HardTanh}(x) = \begin{cases}     \text{max\_val} & \text{
  if } x > \text{ max\_val } \\     \text{min\_val} & \text{ if }
  x < \text{ min\_val } \\     x & \text{ otherwise } \\
  \end{cases}

Parameters:
      * min_val (float) -- minimum value of the linear region
        range. Default: -1
  * **max_val** (*float*) -- maximum value of the linear region
    range. Default: 1

  * **inplace** (*bool*) -- can optionally do the operation in-
    place. Default: "False"

Keyword arguments "min_value" and "max_value" have been deprecated
   in favor of "min_val" and "max_val".
Shape:
      * Input: (*), where * means any number of dimensions.
  * Output: (*), same shape as the input.

[image]
Examples:
  >>> m = nn.Hardtanh(-2, 2)
ConvBn2d
class torch.ao.nn.intrinsic.qat.ConvBn2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=None, padding_mode='zeros', eps=1e-05, momentum=0.1, freeze_bn=False, qconfig=None)
A ConvBn2d module is a module fused from Conv2d and BatchNorm2d,
   attached with FakeQuantize modules for weight, used in quantization
   aware training.
We combined the interface of "torch.nn.Conv2d" and
   "torch.nn.BatchNorm2d".
Similar to "torch.nn.Conv2d", with FakeQuantize modules initialized
   to default.
Variables:
      * freeze_bn --
  * **weight_fake_quant** -- fake quant module for weight
torch.where
torch.where(condition, input, other, *, out=None) -> Tensor
Return a tensor of elements selected from either "input" or
   "other", depending on "condition".
The operation is defined as:
  \text{out}_i = \begin{cases}     \text{input}_i & \text{if }
  \text{condition}_i \\     \text{other}_i & \text{otherwise} \\
  \end{cases}

Note:
 The tensors "condition", "input", "other" must be broadcastable.

Parameters:
      * condition (BoolTensor) -- When True (nonzero), yield
        input, otherwise yield other
  * **input** (*Tensor** or **Scalar*) -- value (if "input" is a
    scalar) or values selected at indices where "condition" is
    "True"

  * **other** (*Tensor** or **Scalar*) -- value (if "other" is a
    scalar) or values selected at indices where "condition" is
    "False"

Keyword Arguments:
      out (Tensor, optional) -- the output tensor.
Returns:
Returns:
      A tensor of shape equal to the broadcasted shape of "condition",
      "input", "other"
Return type:
      Tensor
Example:
  >>> x = torch.randn(3, 2)
  >>> y = torch.ones(3, 2)
  >>> x
  tensor([[-0.4620,  0.3139],
          [ 0.3898, -0.7197],
          [ 0.0478, -0.1657]])
  >>> torch.where(x > 0, x, y)
  tensor([[ 1.0000,  0.3139],
          [ 0.3898,  1.0000],
          [ 0.0478,  1.0000]])
  >>> x = torch.randn(2, 2, dtype=torch.double)
  >>> x
  tensor([[ 1.0779,  0.0383],
          [-0.8785, -1.1089]], dtype=torch.float64)
  >>> torch.where(x > 0, x, 0.)
  tensor([[1.0779, 0.0383],
          [0.0000, 0.0000]], dtype=torch.float64)

torch.where(condition) -> tuple of LongTensor
"torch.where(condition)" is identical to "torch.nonzero(condition,
   as_tuple=True)".
Note:
 See also "torch.nonzero()".
GRUCell
class torch.ao.nn.quantized.dynamic.GRUCell(input_size, hidden_size, bias=True, dtype=torch.qint8)
A gated recurrent unit (GRU) cell
A dynamic quantized GRUCell module with floating point tensor as
   inputs and outputs. Weights are quantized to 8 bits. We adopt the
   same interface as torch.nn.GRUCell, please see
   https://pytorch.org/docs/stable/nn.html#torch.nn.GRUCell for
   documentation.
Examples:
  >>> rnn = nn.GRUCell(10, 20)
  >>> input = torch.randn(6, 3, 10)
  >>> hx = torch.randn(3, 20)
  >>> output = []
  >>> for i in range(6):
  ...     hx = rnn(input[i], hx)
  ...     output.append(hx)
PerChannelMinMaxObserver
class torch.quantization.observer.PerChannelMinMaxObserver(ch_axis=0, dtype=torch.quint8, qscheme=torch.per_channel_affine, reduce_range=False, quant_min=None, quant_max=None, factory_kwargs=None, eps=1.1920928955078125e-07)
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:
      * ch_axis -- Channel axis
  * **dtype** -- dtype argument to the *quantize* node needed to
    implement the reference model spec.

  * **qscheme** -- Quantization scheme to be used

  * **reduce_range** -- Reduces the range of the quantized data
    type by 1 bit
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.

  * **eps** (*Tensor*) -- Epsilon value for float32, Defaults to
    *torch.finfo(torch.float32).eps*.

The quantization parameters are computed the same way as in
   "MinMaxObserver", 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.

reset_min_max_vals()
  Resets the min/max values.
torch.blackman_window
torch.blackman_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Blackman window function.
  w[n] = 0.42 - 0.5 \cos \left( \frac{2 \pi n}{N - 1} \right) +
  0.08 \cos \left( \frac{4 \pi n}{N - 1} \right)

where N is the full window size.
The input "window_length" is a positive integer controlling the
   returned window size. "periodic" flag determines whether the
   returned window trims off the last duplicate value from the
   symmetric window and is ready to be used as a periodic window with
   functions like "torch.stft()". Therefore, if "periodic" is true,
   the N in above formula is in fact \text{window_length} + 1. Also,
   we always have "torch.blackman_window(L, periodic=True)" equal to
   "torch.blackman_window(L + 1, periodic=False)[:-1])".
Note:
 If "window_length" =1, the returned window contains a single
 value 1.

Parameters:
value 1.
Parameters:
      * window_length (int) -- the size of returned window
  * **periodic** (*bool**, **optional*) -- If True, returns a
    window to be used as periodic function. If False, return a
    symmetric 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()"). Only floating point
        types are supported.
  * **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.
torch.cuda.stream
torch.cuda.stream(stream)
Wrapper around the Context-manager StreamContext that selects a
   given stream.
Parameters:
      stream (Stream) -- selected stream. This manager is a no-
      op if it's "None".
Return type:
      StreamContext
..Note:: In eager mode stream is of type Stream class while in JIT
   it is an object of the custom class "torch.classes.cuda.Stream".
torch.histogram
torch.histogram(input, bins, *, range=None, weight=None, density=False, out=None)
Computes a histogram of the values in a tensor.
"bins" can be an integer or a 1D tensor.
If "bins" is an int, it specifies the number of equal-width bins.
   By default, the lower and upper range of the bins is determined by
   the minimum and maximum elements of the input tensor. The "range"
   argument can be provided to specify a range for the bins.
If "bins" is a 1D tensor, it specifies the sequence of bin edges
   including the rightmost edge. It should contain at least 2 elements
   and its elements should be increasing.
Parameters:
      * input (Tensor) -- the input tensor.
  * **bins** -- int or 1D Tensor. If int, defines the number of
    equal-width bins. If tensor, defines the sequence of bin edges
    including the rightmost edge.

Keyword Arguments:
      * range (tuple of python:float) -- Defines the range of
        the bins.
the bins.
  * **weight** (*Tensor*) -- If provided, weight should have the
    same shape as input. Each value in input contributes its
    associated weight towards its bin's result.

  * **density** (*bool*) -- If False, the result will contain the
    count (or total weight) in each bin. If True, the result is
    the value of the probability density function over the bins,
    normalized such that the integral over the range of the bins
    is 1.

  * **out** (*Tensor**, **optional*) -- the output tensor. (tuple,
    optional): The result tuple of two output tensors (hist,
    bin_edges).

Returns:
      1D Tensor containing the values of the histogram.
      bin_edges(Tensor): 1D Tensor containing the edges of the
      histogram bins.
Return type:
      hist (Tensor)
Example:
  >>> torch.histogram(torch.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=torch.tensor([1., 2., 4.]))
(tensor([ 0.,  5.,  2.,  0.]), tensor([0., 0.75, 1.5, 2.25, 3.]))
      >>> torch.histogram(torch.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=torch.tensor([1., 2., 4.]), density=True)
      (tensor([ 0.,  0.9524,  0.3810,  0.]), tensor([0., 0.75, 1.5, 2.25, 3.]))
torch.cuda.comm.broadcast_coalesced
torch.cuda.comm.broadcast_coalesced(tensors, devices, buffer_size=10485760)
Broadcasts a sequence tensors to the specified GPUs. Small tensors
   are first coalesced into a buffer to reduce the number of
   synchronizations.
Parameters:
      * tensors (sequence) -- tensors to broadcast. Must be on
        the same device, either CPU or GPU.
  * **devices** (*Iterable**[**torch.device**, **str** or
    **int**]*) -- an iterable of GPU devices, among which to
    broadcast.

  * **buffer_size** (*int*) -- maximum size of the buffer used for
    coalescing

Returns:
      A tuple containing copies of "tensor", placed on "devices".
torch.neg
torch.neg(input, *, out=None) -> Tensor
Returns a new tensor with the negative of the elements of "input".
  \text{out} = -1 \times \text{input}

Parameters:
      input (Tensor) -- the input tensor.
Keyword Arguments:
      out (Tensor, optional) -- the output tensor.
Example:
  >>> a = torch.randn(5)
  >>> a
  tensor([ 0.0090, -0.2262, -0.0682, -0.2866,  0.3940])
  >>> torch.neg(a)
  tensor([-0.0090,  0.2262,  0.0682,  0.2866, -0.3940])
torch.Tensor.scatter_add_
Tensor.scatter_add_(dim, index, src) -> Tensor
Adds all values from the tensor "src" into "self" at the indices
   specified in the "index" tensor in a similar fashion as
   "scatter_()". For each value in "src", it is added to an index in
   "self" which is specified by its index in "src" for "dimension !=
   dim" and by the corresponding value in "index" for "dimension =
   dim".
For a 3-D tensor, "self" is updated as:
  self[index[i][j][k]][j][k] += src[i][j][k]  # if dim == 0
  self[i][index[i][j][k]][k] += src[i][j][k]  # if dim == 1
  self[i][j][index[i][j][k]] += src[i][j][k]  # if dim == 2

"self", "index" and "src" should have same number of dimensions. It
   is also required that "index.size(d) <= src.size(d)" for all
   dimensions "d", and that "index.size(d) <= self.size(d)" for all
   dimensions "d != dim". Note that "index" and "src" do not
   broadcast.
Note:
broadcast.
Note:
 This operation may behave nondeterministically when given tensors
 on a CUDA device. See Reproducibility for more information.

Note:
 The backward pass is implemented only for "src.shape ==
 index.shape".

Parameters:
      * dim (int) -- the axis along which to index
  * **index** (*LongTensor*) -- the indices of elements to scatter
    and add, can be either empty or of the same dimensionality as
    "src". When empty, the operation returns "self" unchanged.

  * **src** (*Tensor*) -- the source elements to scatter and add

Example:
  >>> src = torch.ones((2, 5))
  >>> index = torch.tensor([[0, 1, 2, 0, 0]])
  >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
  tensor([[1., 0., 0., 1., 1.],
          [0., 1., 0., 0., 0.],
          [0., 0., 1., 0., 0.]])
  >>> index = torch.tensor([[0, 1, 2, 0, 0], [0, 1, 2, 2, 2]])
  >>> torch.zeros(3, 5, dtype=src.dtype).scatter_add_(0, index, src)
torch.jit.optimize_for_inference
torch.jit.optimize_for_inference(mod, other_methods=None)
Performs a set of optimization passes to optimize a model for the
   purposes of inference. If the model is not already frozen,
   optimize_for_inference will invoke torch.jit.freeze
   automatically.
In addition to generic optimizations that should speed up your
   model regardless of environment, prepare for inference will also
   bake in build specific settings such as the presence of CUDNN or
   MKLDNN, and may in the future make transformations which speed
   things up on one machine but slow things down on another.
   Accordingly, serialization is not implemented following invoking
   optimize_for_inference and is not guaranteed.
This is still in prototype, and may have the potential to slow down
   your model. Primary use cases that have been targeted so far have
   been vision models on cpu and gpu to a lesser extent.
Example (optimizing a module with Conv->Batchnorm):
  import torch
  in_channels, out_channels = 3, 32
  conv = torch.nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=2, bias=True)
  bn = torch.nn.BatchNorm2d(out_channels, eps=.001)
  mod = torch.nn.Sequential(conv, bn)
  frozen_mod = torch.jit.optimize_for_inference(torch.jit.script(mod.eval()))
  assert "batch_norm" not in str(frozen_mod.graph)
  # if built with MKLDNN, convolution will be run with MKLDNN weights
  assert "MKLDNN" in frozen_mod.graph

Return type:
      ScriptModule
upsample
class torch.ao.nn.quantized.functional.upsample(input, size=None, scale_factor=None, mode='nearest', align_corners=None)
Upsamples the input to either the given "size" or the given
   "scale_factor"
Warning:
 This function is deprecated in favor of
 "torch.nn.quantized.functional.interpolate()". This is equivalent
 with "nn.quantized.functional.interpolate(...)".

See "torch.nn.functional.interpolate()" for implementation details.
The input dimensions are interpreted in the form: mini-batch x
   channels x [optional depth] x [optional height] x width.
Note:
 The input quantization parameters propagate to the output.

Note:
 Only 2D input is supported for quantized inputs

Note:
 Only the following modes are supported for the quantized inputs:

 * *bilinear*

 * *nearest*

Parameters:
      * input (Tensor) -- quantized input tensor
  * **size** (*int** or **Tuple**[**int**] or **Tuple**[**int**,
int] or Tuple[int, int, int]*) -- output
        spatial size.
  * **scale_factor** (*float** or **Tuple**[**float**]*) --
    multiplier for spatial size. Has to be an integer.

  * **mode** (*str*) -- algorithm used for upsampling: "'nearest'"
    | "'bilinear'"

  * **align_corners** (*bool**, **optional*) -- Geometrically, we
    consider the pixels of the input and output as squares rather
    than points. If set to "True", the input and output tensors
    are aligned by the center points of their corner pixels,
    preserving the values at the corner pixels. If set to "False",
    the input and output tensors are aligned by the corner points
    of their corner pixels, and the interpolation uses edge value
    padding for out-of-boundary values, making this operation
    *independent* of input size when "scale_factor" is kept the
    same. This only has an effect when "mode" is "'bilinear'".
    Default: "False"
Default: "False"
Warning:
 With "align_corners = True", the linearly interpolating modes
 (*bilinear*) don't proportionally align the output and input
 pixels, and thus the output values can depend on the input size.
 This was the default behavior for these modes up to version
 0.3.1. Since then, the default behavior is "align_corners =
 False". See "Upsample" for concrete examples on how this affects
 the outputs.
torch.isclose
torch.isclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False) -> Tensor
Returns a new tensor with boolean elements representing if each
   element of "input" is "close" to the corresponding element of
   "other". Closeness is defined as:
  \lvert \text{input} - \text{other} \rvert \leq \texttt{atol} +
  \texttt{rtol} \times \lvert \text{other} \rvert

where "input" and "other" are finite. Where "input" and/or "other"
   are nonfinite they are close if and only if they are equal, with
   NaNs being considered equal to each other when "equal_nan" is True.
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"
Examples:
  >>> torch.isclose(torch.tensor((1., 2, 3)), torch.tensor((1 + 1e-10, 3, 4)))
  tensor([ True, False, False])
  >>> torch.isclose(torch.tensor((float('inf'), 4)), torch.tensor((float('inf'), 6)), rtol=.5)
  tensor([True, True])
torch.nn.functional.kl_div
torch.nn.functional.kl_div(input, target, size_average=None, reduce=None, reduction='mean', log_target=False)
The Kullback-Leibler divergence Loss
See "KLDivLoss" for details.
Parameters:
      * input (Tensor) -- Tensor of arbitrary shape in log-
        probabilities.
  * **target** (*Tensor*) -- Tensor of the same shape as input.
    See "log_target" for the target's interpretation.

  * **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
    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'" | "'batchmean'" | "'sum'" |
    "'mean'". "'none'": no reduction will be applied
    "'batchmean'": the sum of the output will be divided by the
    batchsize "'sum'": the output will be summed "'mean'": the
    output will be divided by the number of elements in the output
    Default: "'mean'"

  * **log_target** (*bool*) -- A flag indicating whether "target"
    is passed in the log space. It is recommended to pass certain
    distributions (like "softmax") in the log space to avoid
    numerical issues caused by explicit "log". Default: "False"

Return type:
      Tensor
Note:
 "size_average" and "reduce" are in the process of being
torch.ravel
torch.ravel(input) -> Tensor
Return a contiguous flattened tensor. A copy is made only if
   needed.
Parameters:
      input (Tensor) -- the input tensor.
Example:
  >>> t = torch.tensor([[[1, 2],
  ...                    [3, 4]],
  ...                   [[5, 6],
  ...                    [7, 8]]])
  >>> torch.ravel(t)
  tensor([1, 2, 3, 4, 5, 6, 7, 8])
torch.get_default_dtype
torch.get_default_dtype() -> torch.dtype
Get the current default floating point "torch.dtype".
Example:
  >>> torch.get_default_dtype()  # initial default for floating point is torch.float32
  torch.float32
  >>> torch.set_default_dtype(torch.float64)
  >>> torch.get_default_dtype()  # default is now changed to torch.float64
  torch.float64
  >>> torch.set_default_tensor_type(torch.FloatTensor)  # setting tensor type also affects this
  >>> torch.get_default_dtype()  # changed to torch.float32, the dtype for torch.FloatTensor
  torch.float32
torch.autograd.backward
torch.autograd.backward(tensors, grad_tensors=None, retain_graph=None, create_graph=False, grad_variables=None, inputs=None)
Computes the sum of gradients of given tensors with respect to
   graph leaves.
The graph is differentiated using the chain rule. If any of
   "tensors" are non-scalar (i.e. their data has more than one
   element) and require gradient, then the Jacobian-vector product
   would be computed, in this case the function additionally requires
   specifying "grad_tensors". It should be a sequence of matching
   length, that contains the "vector" in the Jacobian-vector product,
   usually the gradient of the differentiated function w.r.t.
   corresponding tensors ("None" is an acceptable value for all
   tensors that don't need gradient tensors).
This function accumulates gradients in the leaves - you might need
   to zero ".grad" attributes or set them to "None" before calling it.
See Default gradient layouts for details on the memory layout of
   accumulated gradients.
Note:
 Using this method with "create_graph=True" will create a
 reference cycle between the parameter and its gradient which can
 cause a memory leak. We recommend using "autograd.grad" when
 creating the graph to avoid this. If you have to use this
 function, make sure to reset the ".grad" fields of your
 parameters to "None" after use to break the cycle and avoid the
 leak.

Note:
 If you run any forward ops, create "grad_tensors", and/or call
 "backward" in a user-specified CUDA stream context, see Stream
 semantics of backward passes.

Note:
 When "inputs" are provided and a given input is not a leaf, the
 current implementation will call its grad_fn (even though it is
 not strictly needed to get this gradients). It is an
 implementation detail on which the user should not rely. See htt