shrinath-suresh/blogs-docs-splitted huggingface dataset:
torch.fft.fft2
torch.fft.fft2(input, s=None, dim=(- 2, - 1), norm=None, *, out=None) -> Tensor
Computes the 2 dimensional discrete Fourier transform of "input".
   Equivalent to "fftn()" but FFTs only the last two dimensions by
   default.
Note:
 The Fourier domain representation of any real signal satisfies
 the Hermitian property: "X[i, j] = conj(X[-i, -j])". This
 function always returns all positive and negative frequency terms
 even though, for real inputs, half of these values are redundant.
 "rfft2()" returns the more compact one-sided representation where
 only the positive frequencies of the last dimension are returned.

Note:
 Supports torch.half and torch.chalf on CUDA with GPU Architecture
 SM53 or greater. However it only supports powers of 2 signal
 length in every transformed dimensions.

Parameters:
      * input (Tensor) -- the input tensor
  * **s** (*Tuple**[**int**]**, **optional*) -- Signal size in the
transformed dimensions. If given, each dimension "dim[i]" will
        either be zero-padded or trimmed to the length "s[i]" before
        computing the FFT. If a length "-1" is specified, no padding
        is done in that dimension. Default: "s = [input.size(d) for d
        in dim]"
  * **dim** (*Tuple**[**int**]**, **optional*) -- Dimensions to be
    transformed. Default: last two dimensions.

  * **norm** (*str**, **optional*) --

    Normalization mode. For the forward transform ("fft2()"),
    these correspond to:

    * ""forward"" - normalize by "1/n"

    * ""backward"" - no normalization

    * ""ortho"" - normalize by "1/sqrt(n)" (making the FFT
      orthonormal)

    Where "n = prod(s)" is the logical FFT size. Calling the
    backward transform ("ifft2()") with the same normalization
    mode will apply an overall normalization of "1/n" between the
    two transforms. This is required to make "ifft2()" the exact
    inverse.
inverse.
    Default is ""backward"" (no normalization).

Keyword Arguments:
      out (Tensor, optional) -- the output tensor.
-[ Example ]-



x = torch.rand(10, 10, dtype=torch.complex64)
fft2 = torch.fft.fft2(x)



The discrete Fourier transform is separable, so "fft2()" here is
   equivalent to two one-dimensional "fft()" calls:



two_ffts = torch.fft.fft(torch.fft.fft(x, dim=0), dim=1)
torch.testing.assert_close(fft2, two_ffts, check_stride=False)
LazyConvTranspose2d
class torch.nn.LazyConvTranspose2d(out_channels, kernel_size, stride=1, padding=0, output_padding=0, groups=1, bias=True, dilation=1, padding_mode='zeros', device=None, dtype=None)
A "torch.nn.ConvTranspose2d" module with lazy initialization of the
   "in_channels" argument of the "ConvTranspose2d" that is inferred
   from the "input.size(1)". The attributes that will be lazily
   initialized are weight and bias.
Check the "torch.nn.modules.lazy.LazyModuleMixin" for further
   documentation on lazy modules and their limitations.
Parameters:
      * out_channels (int) -- Number of channels produced by the
        convolution
  * **kernel_size** (*int** or **tuple*) -- Size of the convolving
    kernel

  * **stride** (*int** or **tuple**, **optional*) -- Stride of the
    convolution. Default: 1

  * **padding** (*int** or **tuple**, **optional*) -- "dilation *
    (kernel_size - 1) - padding" zero-padding will be added to
both sides of each dimension in the input. Default: 0
  * **output_padding** (*int** or **tuple**, **optional*) --
    Additional size added to one side of each dimension in the
    output shape. Default: 0

  * **groups** (*int**, **optional*) -- Number of blocked
    connections from input channels to output channels. Default: 1

  * **bias** (*bool**, **optional*) -- If "True", adds a learnable
    bias to the output. Default: "True"

  * **dilation** (*int** or **tuple**, **optional*) -- Spacing
    between kernel elements. Default: 1

See also:
 "torch.nn.ConvTranspose2d" and
 "torch.nn.modules.lazy.LazyModuleMixin"

cls_to_become
  alias of "ConvTranspose2d"
torch.jit.freeze
torch.jit.freeze(mod, preserved_attrs=None, optimize_numerics=True)
Freezing a "ScriptModule" will clone it and attempt to inline the
   cloned module's submodules, parameters, and attributes as constants
   in the TorchScript IR Graph. By default, forward will be
   preserved, as well as attributes & methods specified in
   preserved_attrs. Additionally, any attribute that is modified
   within a preserved method will be preserved.
Freezing currently only accepts ScriptModules that are in eval
   mode.
Freezing applies generic optimization that will speed up your model
   regardless of machine. To further optimize using server-specific
   settings, run optimize_for_inference after freezing.
Parameters:
      * mod ("ScriptModule") -- a module to be frozen
  * **preserved_attrs** (*Optional**[**List**[**str**]**]*) -- a
    list of attributes to preserve in addition to the forward
method. Attributes modified in preserved methods will also be
        preserved.
  * **optimize_numerics** (*bool*) -- If "True", a set of
    optimization passes will be run that does not strictly
    preserve numerics. Full details of optimization can be found
    at *torch.jit.run_frozen_optimizations*.

Returns:
      Frozen "ScriptModule".
Example (Freezing a simple module with a Parameter):
      def forward(self, input):
          output = self.weight.mm(input)
          output = self.linear(output)
          return output

  scripted_module = torch.jit.script(MyModule(2, 3).eval())
  frozen_module = torch.jit.freeze(scripted_module)
  # parameters have been removed and inlined into the Graph as constants
  assert len(list(frozen_module.named_parameters())) == 0
  # See the compiled graph as Python code
  print(frozen_module.code)

Example (Freezing a module with preserved attributes)
      def forward(self, input):
def forward(self, input):
              self.modified_tensor += 1
              return input + self.modified_tensor
  scripted_module = torch.jit.script(MyModule2().eval())
  frozen_module = torch.jit.freeze(scripted_module, preserved_attrs=["version"])
  # we've manually preserved `version`, so it still exists on the frozen module and can be modified
  assert frozen_module.version == 1
  frozen_module.version = 2
  # `modified_tensor` is detected as being mutated in the forward, so freezing preserves
  # it to retain model semantics
  assert frozen_module(torch.tensor(1)) == torch.tensor(12)
  # now that we've run it once, the next result will be incremented by one
  assert frozen_module(torch.tensor(1)) == torch.tensor(13)

Note:
 Freezing submodule attributes is also supported: frozen_module =
 torch.jit.freeze(scripted_module,
 preserved_attrs=["submodule.version"])

Note:
Note:
 If you're not sure why an attribute is not being inlined as a
 constant, you can run *dump_alias_db* on
 frozen_module.forward.graph to see if freezing has detected the
 attribute is being modified.

Note:
 Because freezing makes weights constants and removes module
 hierarchy, *to* and other nn.Module methods to manipulate device
 or dtype no longer work. As a workaround, You can remap devices
 by specifying *map_location* in *torch.jit.load*, however device-
 specific logic may have been baked into the model.
torch.cuda.comm.gather
torch.cuda.comm.gather(tensors, dim=0, destination=None, *, out=None)
Gathers tensors from multiple GPU devices.
Parameters:
      * tensors (Iterable[Tensor]) -- an iterable of
        tensors to gather. Tensor sizes in all dimensions other than
        "dim" have to match.
  * **dim** (*int**, **optional*) -- a dimension along which the
    tensors will be concatenated. Default: "0".

  * **destination** (*torch.device**, **str**, or **int**,
    **optional*) -- the output device. Can be CPU or CUDA.
    Default: the current CUDA device.

  * **out** (*Tensor**, **optional**, **keyword-only*) -- the
    tensor to store gather result. Its sizes must match those of
    "tensors", except for "dim", where the size must equal
    "sum(tensor.size(dim) for tensor in tensors)". Can be on CPU
    or CUDA.

Note:
 "destination" must not be specified when "out" is specified.

Returns:
GraphInfo
class torch.onnx.verification.GraphInfo(graph, input_args, params_dict, export_options=, id='', _EXCLUDED_NODE_KINDS=frozenset({'aten::ScalarImplicit', 'prim::Constant', 'prim::ListConstruct'}))
GraphInfo contains validation information of a TorchScript graph
   and its converted ONNX graph.
all_mismatch_leaf_graph_info()
  Return a list of all leaf *GraphInfo* objects that have
  mismatch.

  Return type:
     *List*[*GraphInfo*]

clear()
  Clear states and results of previous verification.

essential_node_count()
  Return the number of nodes in the subgraph excluding those in
  *_EXCLUDED_NODE_KINDS*.

  Return type:
     int

essential_node_kinds()
  Return the set of node kinds in the subgraph excluding those in
  *_EXCLUDED_NODE_KINDS*.

  Return type:
     *Set*[str]

export_repro(repro_dir=None, name=None)
  Export the subgraph to ONNX along with the input/output data for
  repro.
repro.
  The repro directory will contain the following files:

     dir
     âââ test_<name>
     â   âââ model.onnx
     â   âââ test_data_set_0
     â       âââ input_0.pb
     â       âââ input_1.pb
     â       âââ output_0.pb
     â       âââ output_1.pb

  Parameters:
     * **repro_dir** (*Optional**[**str**]*) -- The directory to
       export the repro files to. Defaults to current working
       directory if None.

     * **name** (*Optional**[**str**]*) -- An optional name for
       the test case folder: "test_{name}".

  Returns:
     The path to the exported repro directory.

  Return type:
     str

find_mismatch(options=None)
  Find all mismatches between the TorchScript IR graph and the
  exported onnx model.

  Binary searches the model graph to find the minimal subgraph
  that exhibits the mismatch. A *GraphInfo* object is created for
each subgraph, recording the test inputs and export options, as
      well as the validation results.
  Parameters:
     **options** (*Optional**[**VerificationOptions**]*) -- The
     verification options.

find_partition(id)
  Find the *GraphInfo* object with the given id.

  Return type:
     *Optional*[*GraphInfo*]

has_mismatch()
  Return True if the subgraph has output mismatch between torch
  and ONNX.

  Return type:
     bool

pretty_print_mismatch(graph=False)
  Pretty print details of the mismatch between torch and ONNX.

  Parameters:
     **graph** (*bool*) -- If True, print the ATen JIT graph and
     ONNX graph.

pretty_print_tree()
  Pretty print *GraphInfo* tree.

  Each node represents a subgraph, showing the number of nodes in
  the subgraph and a check mark if the subgraph has output
  mismatch between torch and ONNX.

  The id of the subgraph is shown under the node. The *GraphInfo*
object for any subgraph can be retrieved by calling
      graph_info.find_partition(id).
  Example:

     ==================================== Tree: =====================================
     5 X   __2 X    __1 â
     id:  |  id: 0 |  id: 00
          |        |
          |        |__1 X (aten::relu)
          |           id: 01
          |
          |__3 X    __1 â
             id: 1 |  id: 10
                   |
                   |__2 X     __1 X (aten::relu)
                      id: 11 |  id: 110
                             |
                             |__1 â
                                id: 111
     =========================== Mismatch leaf subgraphs: ===========================
     ['01', '110']
     ============================= Mismatch node kinds: =============================
     {'aten::relu': 2}

verify_export(options)
  Verify the export from TorchScript IR graph to ONNX.
Export the TorchScript IR graph to ONNX, with the inputs,
      parameters and export options recorded in this object. Then
      verify the exported ONNX graph against the original TorchScript
      IR graph under the provided verification options.
  Parameters:
     **options** (*VerificationOptions*) -- The verification
     options.

  Returns:
     The AssertionError raised during the verification. Returns
     None if no error is raised. onnx_graph: The exported ONNX
     graph in TorchScript IR format. onnx_outs: The outputs from
     running exported ONNX model under the onnx backend in
     *options*. pt_outs: The outputs from running the TorchScript
     IR graph.

  Return type:
     error
Threshold
class torch.nn.Threshold(threshold, value, inplace=False)
Thresholds each element of the input Tensor.
Threshold is defined as:
  y = \begin{cases} x, &\text{ if } x > \text{threshold} \\
  \text{value}, &\text{ otherwise } \end{cases}

Parameters:
      * threshold (float) -- The value to threshold at
  * **value** (*float*) -- The value to replace with

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

Examples:
  >>> m = nn.Threshold(0.1, 20)
  >>> input = torch.randn(2)
  >>> output = m(input)
torch.addmv
torch.addmv(input, mat, vec, *, beta=1, alpha=1, out=None) -> Tensor
Performs a matrix-vector product of the matrix "mat" and the vector
   "vec". The vector "input" is added to the final result.
If "mat" is a (n \times m) tensor, "vec" is a 1-D tensor of size
   m, then "input" must be broadcastable with a 1-D tensor of size
   n and "out" will be 1-D tensor of size n.
"alpha" and "beta" are scaling factors on matrix-vector product
   between "mat" and "vec" and the added tensor "input" respectively.
  \text{out} = \beta\ \text{input} + \alpha\ (\text{mat}
  \mathbin{@} \text{vec})

If "beta" is 0, then "input" will be ignored, and nan and inf
   in it will not be propagated.
For inputs of type FloatTensor or DoubleTensor, arguments
   "beta" and "alpha" must be real numbers, otherwise they should be
   integers.
Parameters:
      * input (Tensor) -- vector to be added
  * **mat** (*Tensor*) -- matrix to be matrix multiplied
vec (Tensor) -- vector to be matrix multiplied

Keyword Arguments:
      * beta (Number, optional) -- multiplier for "input"
        (\beta)
  * **alpha** (*Number**, **optional*) -- multiplier for mat @ vec
    (\alpha)

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

Example:
  >>> M = torch.randn(2)
  >>> mat = torch.randn(2, 3)
  >>> vec = torch.randn(3)
  >>> torch.addmv(M, mat, vec)
  tensor([-0.3768, -5.5565])
torch.lu_unpack
torch.lu_unpack(LU_data, LU_pivots, unpack_data=True, unpack_pivots=True, *, out=None)
Unpacks the LU decomposition returned by "lu_factor()" into the P,
   L, U matrices.
See also:
 "lu()" returns the matrices from the LU decomposition. Its
 gradient formula is more efficient than that of doing
 "lu_factor()" followed by "lu_unpack()".

Parameters:
      * LU_data (Tensor) -- the packed LU factorization data
  * **LU_pivots** (*Tensor*) -- the packed LU factorization pivots

  * **unpack_data** (*bool*) -- flag indicating if the data should
    be unpacked. If "False", then the returned "L" and "U" are
    empty tensors. Default: "True"

  * **unpack_pivots** (*bool*) -- flag indicating if the pivots
    should be unpacked into a permutation matrix "P". If "False",
    then the returned "P" is  an empty tensor. Default: "True"

Keyword Arguments:
      out (tuple, optional) -- output tuple of three
tensors. Ignored if None.
Returns:
      A namedtuple "(P, L, U)"
Examples:
  >>> A = torch.randn(2, 3, 3)
  >>> LU, pivots = torch.linalg.lu_factor(A)
  >>> P, L, U = torch.lu_unpack(LU, pivots)
  >>> # We can recover A from the factorization
  >>> A_ = P @ L @ U
  >>> torch.allclose(A, A_)
  True

  >>> # LU factorization of a rectangular matrix:
  >>> A = torch.randn(2, 3, 2)
  >>> LU, pivots = torch.linalg.lu_factor(A)
  >>> P, L, U = torch.lu_unpack(LU, pivots)
  >>> # P, L, U are the same as returned by linalg.lu
  >>> P_, L_, U_ = torch.linalg.lu(A)
  >>> torch.allclose(P, P_) and torch.allclose(L, L_) and torch.allclose(U, U_)
  True
LayerNorm
class torch.nn.LayerNorm(normalized_shape, eps=1e-05, elementwise_affine=True, device=None, dtype=None)
Applies Layer Normalization over a mini-batch of inputs as
   described in the paper Layer Normalization
  y = \frac{x - \mathrm{E}[x]}{ \sqrt{\mathrm{Var}[x] + \epsilon}}
  * \gamma + \beta

The mean and standard-deviation are calculated over the last D
   dimensions, where D is the dimension of "normalized_shape". For
   example, if "normalized_shape" is "(3, 5)" (a 2-dimensional shape),
   the mean and standard-deviation are computed over the last 2
   dimensions of the input (i.e. "input.mean((-2, -1))"). \gamma and
   \beta are learnable affine transform parameters of
   "normalized_shape" if "elementwise_affine" is "True". The standard-
   deviation is calculated via the biased estimator, equivalent to
   torch.var(input, unbiased=False).
Note:
 Unlike Batch Normalization and Instance Normalization, which
applies scalar scale and bias for each entire channel/plane with
     the "affine" option, Layer Normalization applies per-element
     scale and bias with "elementwise_affine".
This layer uses statistics computed from input data in both
   training and evaluation modes.
Parameters:
      * normalized_shape (int or list or torch.Size) --
    input shape from an expected input of size

       [* \times \text{normalized\_shape}[0] \times
       \text{normalized\_shape}[1]     \times \ldots \times
       \text{normalized\_shape}[-1]]

    If a single integer is used, it is treated as a singleton
    list, and this module will normalize over the last dimension
    which is expected to be of that specific size.

  * **eps** (*float*) -- a value added to the denominator for
    numerical stability. Default: 1e-5

  * **elementwise_affine** (*bool*) -- a boolean value that when
    set to "True", this module has learnable per-element affine
parameters initialized to ones (for weights) and zeros (for
        biases). Default: "True".
Variables:
      * weight -- the learnable weights of the module of shape
        \text{normalized_shape} when "elementwise_affine" is set to
        "True". The values are initialized to 1.
  * **bias** -- the learnable bias of the module of shape
    \text{normalized\_shape} when "elementwise_affine" is set to
    "True". The values are initialized to 0.

Shape:
      * Input: (N, *)
  * Output: (N, *) (same shape as input)

Examples:
  >>> # NLP Example
  >>> batch, sentence_length, embedding_dim = 20, 5, 10
  >>> embedding = torch.randn(batch, sentence_length, embedding_dim)
  >>> layer_norm = nn.LayerNorm(embedding_dim)
  >>> # Activate module
  >>> layer_norm(embedding)
  >>>
  >>> # Image Example
  >>> N, C, H, W = 20, 5, 10, 10
  >>> input = torch.randn(N, C, H, W)
torch.autograd.forward_ad.make_dual
torch.autograd.forward_ad.make_dual(tensor, tangent, *, level=None)
Associates a tensor value with a forward gradient, the tangent, to
   create a "dual tensor", which is used to compute forward AD
   gradients. The result is a new tensor aliased to "tensor" with
   "tangent" embedded as an attribute as-is if it has the same storage
   layout or copied otherwise. The tangent attribute can be recovered
   with "unpack_dual()".
This function is backward differentiable.
Given a function f whose jacobian is J, it allows one to
   compute the Jacobian-vector product (jvp) between J and a given
   vector v as follows.
Example:
  >>> with dual_level():
  ...     inp = make_dual(x, v)
  ...     out = f(inp)
  ...     y, jvp = unpack_dual(out)

Please see the forward-mode AD tutorial for detailed steps on how
   to use this API.
AdaptiveAvgPool1d
class torch.nn.AdaptiveAvgPool1d(output_size)
Applies a 1D adaptive average pooling over an input signal composed
   of several input planes.
The output size is L_{out}, for any input size. The number of
   output features is equal to the number of input planes.
Parameters:
      output_size (Union[int, Tuple[int]]) --
      the target output size L_{out}.
Shape:
      * Input: (N, C, L_{in}) or (C, L_{in}).
  * Output: (N, C, L_{out}) or (C, L_{out}), where
    L_{out}=\text{output\_size}.

-[ Examples ]-



target output size of 5
m = nn.AdaptiveAvgPool1d(5)
input = torch.randn(1, 64, 8)
output = m(input)
torch.fft.ihfft2
torch.fft.ihfft2(input, s=None, dim=(- 2, - 1), norm=None, *, out=None) -> Tensor
Computes the 2-dimensional inverse discrete Fourier transform of
   real "input". Equivalent to "ihfftn()" but transforms only the two
   last dimensions by default.
Note:
 Supports torch.half on CUDA with GPU Architecture SM53 or
 greater. However it only supports powers of 2 signal length in
 every transformed dimensions.

Parameters:
      * input (Tensor) -- the input tensor
  * **s** (*Tuple**[**int**]**, **optional*) -- Signal size in the
    transformed dimensions. If given, each dimension "dim[i]" will
    either be zero-padded or trimmed to the length "s[i]" before
    computing the Hermitian IFFT. If a length "-1" is specified,
    no padding is done in that dimension. Default: "s =
    [input.size(d) for d in dim]"

  * **dim** (*Tuple**[**int**]**, **optional*) -- Dimensions to be
transformed. Default: last two dimensions.
  * **norm** (*str**, **optional*) --

    Normalization mode. For the backward transform ("ihfft2()"),
    these correspond to:

    * ""forward"" - no normalization

    * ""backward"" - normalize by "1/n"

    * ""ortho"" - normalize by "1/sqrt(n)" (making the Hermitian
      IFFT orthonormal)

    Where "n = prod(s)" is the logical IFFT size. Calling the
    forward transform ("hfft2()") with the same normalization mode
    will apply an overall normalization of "1/n" between the two
    transforms. This is required to make "ihfft2()" the exact
    inverse.

    Default is ""backward"" (normalize by "1/n").

Keyword Arguments:
      out (Tensor, optional) -- the output tensor.
-[ Example ]-



T = torch.rand(10, 10)
t = torch.fft.ihfft2(t)
t.size()
   torch.Size([10, 6])



Compared against the full output from "ifft2()", the Hermitian
time-space signal takes up only half the space.



fftn = torch.fft.ifft2(t)
torch.allclose(fftn[..., :6], rfftn)
   True



The discrete Fourier transform is separable, so "ihfft2()" here is
   equivalent to a combination of "ifft()" and "ihfft()":



two_ffts = torch.fft.ifft(torch.fft.ihfft(t, dim=1), dim=0)
torch.allclose(t, two_ffts)
   True
LazyConv1d
class torch.nn.LazyConv1d(out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros', device=None, dtype=None)
A "torch.nn.Conv1d" module with lazy initialization of the
   "in_channels" argument of the "Conv1d" that is inferred from the
   "input.size(1)". The attributes that will be lazily initialized are
   weight and bias.
Check the "torch.nn.modules.lazy.LazyModuleMixin" for further
   documentation on lazy modules and their limitations.
Parameters:
      * out_channels (int) -- Number of channels produced by the
        convolution
  * **kernel_size** (*int** or **tuple*) -- Size of the convolving
    kernel

  * **stride** (*int** or **tuple**, **optional*) -- Stride of the
    convolution. Default: 1

  * **padding** (*int** or **tuple**, **optional*) -- Zero-padding
    added to both sides of the input. Default: 0

  * **padding_mode** (*str**, **optional*) -- "'zeros'",
"'reflect'", "'replicate'" or "'circular'". Default: "'zeros'"
  * **dilation** (*int** or **tuple**, **optional*) -- Spacing
    between kernel elements. Default: 1

  * **groups** (*int**, **optional*) -- Number of blocked
    connections from input channels to output channels. Default: 1

  * **bias** (*bool**, **optional*) -- If "True", adds a learnable
    bias to the output. Default: "True"

See also:
 "torch.nn.Conv1d" and "torch.nn.modules.lazy.LazyModuleMixin"

cls_to_become
  alias of "Conv1d"