diff --git a/docs/stable/.buildinfo b/docs/stable/.buildinfo index 84cdbd6ab202..3449402f7a16 100644 --- a/docs/stable/.buildinfo +++ b/docs/stable/.buildinfo @@ -1,4 +1,4 @@ # Sphinx build info version 1 # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. -config: 93625c989914b71802289037a0f16437 +config: 892a2ec27a03fe01b7f360c8920a2882 tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/docs/stable/_images/add_histogram.png b/docs/stable/_images/add_histogram.png deleted file mode 100644 index d9185e4b10b5..000000000000 Binary files a/docs/stable/_images/add_histogram.png and /dev/null differ diff --git a/docs/stable/_images/add_hparam.png b/docs/stable/_images/add_hparam.png deleted file mode 100644 index 5cebef5b5889..000000000000 Binary files a/docs/stable/_images/add_hparam.png and /dev/null differ diff --git a/docs/stable/_images/add_image.png b/docs/stable/_images/add_image.png deleted file mode 100644 index 0b675524b459..000000000000 Binary files a/docs/stable/_images/add_image.png and /dev/null differ diff --git a/docs/stable/_images/add_images.png b/docs/stable/_images/add_images.png deleted file mode 100644 index 5fcbf36580b7..000000000000 Binary files a/docs/stable/_images/add_images.png and /dev/null differ diff --git a/docs/stable/_images/add_scalar.png b/docs/stable/_images/add_scalar.png deleted file mode 100644 index a872b93eca32..000000000000 Binary files a/docs/stable/_images/add_scalar.png and /dev/null differ diff --git a/docs/stable/_images/add_scalars.png b/docs/stable/_images/add_scalars.png deleted file mode 100644 index 2a31a4b76cf9..000000000000 Binary files a/docs/stable/_images/add_scalars.png and /dev/null differ diff --git a/docs/stable/_modules/index.html b/docs/stable/_modules/index.html index dbd0a4b2c340..24ba1abb638e 100644 --- a/docs/stable/_modules/index.html +++ b/docs/stable/_modules/index.html @@ -494,7 +494,6 @@
del _torch_docs, _tensor_docs, _storage_docs
-[docs]def compiled_with_cxx11_abi():
+def compiled_with_cxx11_abi():
r"""Returns whether PyTorch was built with _GLIBCXX_USE_CXX11_ABI=1"""
- return _C._GLIBCXX_USE_CXX11_ABI
+ return _C._GLIBCXX_USE_CXX11_ABI
# Import the ops "namespace"
diff --git a/docs/stable/_modules/torch/_jit_internal.html b/docs/stable/_modules/torch/_jit_internal.html
index c387da189a52..2f78d151ecd9 100644
--- a/docs/stable/_modules/torch/_jit_internal.html
+++ b/docs/stable/_modules/torch/_jit_internal.html
@@ -710,7 +710,7 @@ Source code for torch._jit_internal
fn._torchscript_modifier = FunctionModifiers.UNUSED
return fn
-def ignore(drop=False, **kwargs):
+[docs]def ignore(drop=False, **kwargs):
"""
This decorator indicates to the compiler that a function or method should
be ignored and left as a Python function. This allows you to leave code in
@@ -801,7 +801,7 @@ Source code for torch._jit_internal
else:
fn._torchscript_modifier = FunctionModifiers.IGNORE
return fn
- return decorator
+ return decorator
def _copy_to_script_wrapper(fn):
diff --git a/docs/stable/_modules/torch/_lowrank.html b/docs/stable/_modules/torch/_lowrank.html
index 40498c24ce7f..34972f7ace7a 100644
--- a/docs/stable/_modules/torch/_lowrank.html
+++ b/docs/stable/_modules/torch/_lowrank.html
@@ -419,7 +419,7 @@ Source code for torch._lowrank
return Q
-def svd_lowrank(A, q=6, niter=2, M=None):
+[docs]def svd_lowrank(A, q=6, niter=2, M=None):
# type: (Tensor, Optional[int], Optional[int], Optional[Tensor]) -> Tuple[Tensor, Tensor, Tensor]
r"""Return the singular value decomposition ``(U, S, V)`` of a matrix,
batches of matrices, or a sparse matrix :math:`A` such that
@@ -464,7 +464,7 @@ Source code for torch._lowrank
tensor_ops = (A, M)
if (not set(map(type, tensor_ops)).issubset((torch.Tensor, type(None))) and has_torch_function(tensor_ops)):
return handle_torch_function(svd_lowrank, tensor_ops, A, q=q, niter=niter, M=M)
- return _svd_lowrank(A, q=q, niter=niter, M=M)
+ return _svd_lowrank(A, q=q, niter=niter, M=M)
def _svd_lowrank(A, q=6, niter=2, M=None):
diff --git a/docs/stable/_modules/torch/autograd/grad_mode.html b/docs/stable/_modules/torch/autograd/grad_mode.html
index 75e0bc5ccf97..22e5db5109a7 100644
--- a/docs/stable/_modules/torch/autograd/grad_mode.html
+++ b/docs/stable/_modules/torch/autograd/grad_mode.html
@@ -369,7 +369,7 @@ Source code for torch.autograd.grad_mode
return generator_context
-class no_grad(_DecoratorContextManager):
+[docs]class no_grad(_DecoratorContextManager):
r"""Context-manager that disabled gradient calculation.
Disabling gradient calculation is useful for inference, when you are sure
@@ -406,10 +406,10 @@ Source code for torch.autograd.grad_mode
torch._C.set_grad_enabled(False)
def __exit__(self, *args):
- torch.set_grad_enabled(self.prev)
+ torch.set_grad_enabled(self.prev)
-[docs]class enable_grad(_DecoratorContextManager):
+[docs]class enable_grad(_DecoratorContextManager):
r"""Context-manager that enables gradient calculation.
Enables gradient calculation, if it has been disabled via :class:`~no_grad`
@@ -448,7 +448,7 @@ Source code for torch.autograd.grad_mode
torch.set_grad_enabled(self.prev)
-class set_grad_enabled(object):
+[docs]class set_grad_enabled(object):
r"""Context-manager that sets gradient calculation to on or off.
``set_grad_enabled`` will enable or disable grads based on its argument :attr:`mode`.
@@ -493,7 +493,7 @@ Source code for torch.autograd.grad_mode
pass
def __exit__(self, *args):
- torch.set_grad_enabled(self.prev)
+ torch.set_grad_enabled(self.prev)
diff --git a/docs/stable/_modules/torch/functional.html b/docs/stable/_modules/torch/functional.html
index 7aad23570614..ec4b116dde0e 100644
--- a/docs/stable/_modules/torch/functional.html
+++ b/docs/stable/_modules/torch/functional.html
@@ -402,7 +402,7 @@ Source code for torch.functional
return _VF.broadcast_tensors(tensors)
-def split(tensor, split_size_or_sections, dim=0):
+[docs]def split(tensor, split_size_or_sections, dim=0):
r"""Splits the tensor into chunks. Each chunk is a view of the original tensor.
If :attr:`split_size_or_sections` is an integer type, then :attr:`tensor` will
@@ -449,7 +449,7 @@ Source code for torch.functional
# This dispatches to two ATen functions depending on the type of
# split_size_or_sections. The branching code is in tensor.py, which we
# call here.
- return tensor.split(split_size_or_sections, dim)
+ return tensor.split(split_size_or_sections, dim)
# equivalent to itertools.product(indices)
def _indices_product(indices):
@@ -702,7 +702,7 @@ Source code for torch.functional
return _VF.meshgrid(tensors)
-def stft(input, n_fft, hop_length=None, win_length=None, window=None,
+[docs]def stft(input, n_fft, hop_length=None, win_length=None, window=None,
center=True, pad_mode='reflect', normalized=False, onesided=True):
# type: (Tensor, int, Optional[int], Optional[int], Optional[Tensor], bool, str, bool, bool) -> Tensor
r"""Short-time Fourier transform (STFT).
@@ -799,10 +799,10 @@ Source code for torch.functional
pad = int(n_fft // 2)
input = F.pad(input.view(extended_shape), (pad, pad), pad_mode)
input = input.view(input.shape[-signal_dim:])
- return _VF.stft(input, n_fft, hop_length, win_length, window, normalized, onesided)
+ return _VF.stft(input, n_fft, hop_length, win_length, window, normalized, onesided)
-def istft(input, n_fft, hop_length=None, win_length=None, window=None,
+[docs]def istft(input, n_fft, hop_length=None, win_length=None, window=None,
center=True, normalized=False, onesided=True, length=None):
# type: (Tensor, int, Optional[int], Optional[int], Optional[Tensor], bool, bool, bool, Optional[int]) -> Tensor
r"""Inverse short time Fourier Transform. This is expected to be the inverse of :func:`~torch.stft`.
@@ -861,7 +861,7 @@ Source code for torch.functional
length=length)
return _VF.istft(
- input, n_fft, hop_length, win_length, window, center, normalized, onesided, length)
+ input, n_fft, hop_length, win_length, window, center, normalized, onesided, length)
del torch.unique_dim
@@ -1136,7 +1136,7 @@ Source code for torch.functional
unique_consecutive.__doc__ = _unique_consecutive_impl.__doc__
-def tensordot(a, b, dims=2):
+[docs]def tensordot(a, b, dims=2):
r"""Returns a contraction of a and b over multiple dimensions.
:attr:`tensordot` implements a generalized matrix product.
@@ -1193,7 +1193,7 @@ Source code for torch.functional
raise RuntimeError("tensordot expects dims >= 0, but got dims={}".format(dims))
dims_a = list(range(-dims, 0))
dims_b = list(range(dims))
- return _VF.tensordot(a, b, dims_a, dims_b)
+ return _VF.tensordot(a, b, dims_a, dims_b)
def cartesian_prod(*tensors):
"""Do cartesian product of the given sequence of tensors. The behavior is similar to
@@ -1339,7 +1339,7 @@ Source code for torch.functional
# type: (Tensor, str, Optional[int], bool, Optional[Tensor], Optional[int]) -> Tensor
pass
-def norm(input, p="fro", dim=None, keepdim=False, out=None, dtype=None): # noqa: 749
+[docs]def norm(input, p="fro", dim=None, keepdim=False, out=None, dtype=None): # noqa: 749
r"""Returns the matrix norm or vector norm of a given tensor.
Args:
@@ -1464,7 +1464,7 @@ Source code for torch.functional
if dtype is None:
return _VF.norm(input, p, _dim, keepdim=keepdim, out=out)
else:
- return _VF.norm(input, p, _dim, keepdim=keepdim, dtype=dtype, out=out)
+ return _VF.norm(input, p, _dim, keepdim=keepdim, dtype=dtype, out=out)
def chain_matmul(*matrices):
r"""Returns the matrix product of the :math:`N` 2-D tensors. This product is efficiently computed
diff --git a/docs/stable/_modules/torch/hub.html b/docs/stable/_modules/torch/hub.html
index 9af33c148526..e25278c652b8 100644
--- a/docs/stable/_modules/torch/hub.html
+++ b/docs/stable/_modules/torch/hub.html
@@ -560,7 +560,7 @@ Source code for torch.hub
return func
-def get_dir():
+[docs]def get_dir():
r"""
Get the Torch Hub cache directory used for storing downloaded models & weights.
@@ -576,10 +576,10 @@ Source code for torch.hub
if _hub_dir is not None:
return _hub_dir
- return os.path.join(_get_torch_home(), 'hub')
+ return os.path.join(_get_torch_home(), 'hub')
-def set_dir(d):
+[docs]def set_dir(d):
r"""
Optionally set the Torch Hub directory used to save downloaded models & weights.
@@ -587,10 +587,10 @@ Source code for torch.hub
d (string): path to a local folder to save downloaded models & weights.
"""
global _hub_dir
- _hub_dir = d
+ _hub_dir = d
-def list(github, force_reload=False):
+[docs]def list(github, force_reload=False):
r"""
List all entrypoints available in `github` hubconf.
@@ -617,10 +617,10 @@ Source code for torch.hub
# We take functions starts with '_' as internal helper functions
entrypoints = [f for f in dir(hub_module) if callable(getattr(hub_module, f)) and not f.startswith('_')]
- return entrypoints
+ return entrypoints
-def help(github, model, force_reload=False):
+[docs]def help(github, model, force_reload=False):
r"""
Show the docstring of entrypoint `model`.
@@ -644,14 +644,14 @@ Source code for torch.hub
entry = _load_entry_from_hubconf(hub_module, model)
- return entry.__doc__
+ return entry.__doc__
# Ideally this should be `def load(github, model, *args, forece_reload=False, **kwargs):`,
# but Python2 complains syntax error for it. We have to skip force_reload in function
# signature here but detect it in kwargs instead.
# TODO: fix it after Python2 EOL
-def load(github, model, *args, **kwargs):
+[docs]def load(github, model, *args, **kwargs):
r"""
Load a model from a github repo, with pretrained weights.
@@ -691,10 +691,10 @@ Source code for torch.hub
sys.path.remove(repo_dir)
- return model
+ return model
-def download_url_to_file(url, dst, hash_prefix=None, progress=True):
+[docs]def download_url_to_file(url, dst, hash_prefix=None, progress=True):
r"""Download object at the given URL to a local path.
Args:
@@ -753,7 +753,7 @@ Source code for torch.hub
finally:
f.close()
if os.path.exists(f.name):
- os.remove(f.name)
+ os.remove(f.name)
def _download_url_to_file(url, dst, hash_prefix=None, progress=True):
warnings.warn('torch.hub._download_url_to_file has been renamed to\
@@ -761,7 +761,7 @@ Source code for torch.hub
_download_url_to_file will be removed in after 1.3 release')
download_url_to_file(url, dst, hash_prefix, progress)
-def load_state_dict_from_url(url, model_dir=None, map_location=None, progress=True, check_hash=False, file_name=None):
+[docs]def load_state_dict_from_url(url, model_dir=None, map_location=None, progress=True, check_hash=False, file_name=None):
r"""Loads the Torch serialized object at the given URL.
If downloaded file is a zip file, it will be automatically
@@ -829,7 +829,7 @@ Source code for torch.hub
extraced_name = members[0].filename
cached_file = os.path.join(model_dir, extraced_name)
- return torch.load(cached_file, map_location=map_location)
+ return torch.load(cached_file, map_location=map_location)
diff --git a/docs/stable/_modules/torch/jit.html b/docs/stable/_modules/torch/jit.html
index b03a5de7880d..17f36b5fd7f7 100644
--- a/docs/stable/_modules/torch/jit.html
+++ b/docs/stable/_modules/torch/jit.html
@@ -470,7 +470,7 @@ Source code for torch.jit
DEFAULT_EXTRA_FILES_MAP = torch._C.ExtraFilesMap()
-def save(m, f, _extra_files=DEFAULT_EXTRA_FILES_MAP):
+[docs]def save(m, f, _extra_files=DEFAULT_EXTRA_FILES_MAP):
r"""
Save an offline version of this module for use in a separate process. The
saved module serializes all of the methods, submodules, parameters, and
@@ -534,9 +534,9 @@ Source code for torch.jit
m.save(f, _extra_files=_extra_files)
else:
ret = m.save_to_buffer(_extra_files=_extra_files)
- f.write(ret)
+ f.write(ret)
-def load(f, map_location=None, _extra_files=DEFAULT_EXTRA_FILES_MAP):
+[docs]def load(f, map_location=None, _extra_files=DEFAULT_EXTRA_FILES_MAP):
r"""
Load a :class:`ScriptModule` or :class:`ScriptFunction` previously
saved with :func:`torch.jit.save <torch.jit.save>`
@@ -614,7 +614,7 @@ Source code for torch.jit
cpp_module = torch._C.import_ir_module_from_buffer(cu, f.read(), map_location, _extra_files)
# TODO: Pretty sure this approach loses ConstSequential status and such
- return torch.jit._recursive.wrap_cpp_module(cpp_module)
+ return torch.jit._recursive.wrap_cpp_module(cpp_module)
def validate_map_location(map_location=None):
if isinstance(map_location, str):
@@ -1460,7 +1460,7 @@ Source code for torch.jit
return module
-def fork(func, *args, **kwargs):
+[docs]def fork(func, *args, **kwargs):
"""
Creates an asynchronous task executing `func` and a reference to the value
of the result of this execution. `fork` will return immediately,
@@ -1517,7 +1517,7 @@ Source code for torch.jit
mod = Mod()
assert mod(input) == torch.jit.script(mod).forward(input)
"""
- return torch._C.fork(func, *args, **kwargs)
+ return torch._C.fork(func, *args, **kwargs)
[docs]def wait(future):
@@ -1532,7 +1532,7 @@ Source code for torch.jit
return torch._C.wait(future)
-def freeze(mod, preserved_attrs : Optional[List[str]] = None):
+[docs]def freeze(mod, preserved_attrs : Optional[List[str]] = None):
r"""
Freezing a :class:`ScriptModule` will clone it and attempt to inline the cloned
module's submodules, parameters, and attributes as constants in the TorchScript IR Graph.
@@ -1614,7 +1614,7 @@ Source code for torch.jit
out = RecursiveScriptModule(torch._C._freeze_module(mod._c, preserved_attrs))
RecursiveScriptModule._finalize_scriptmodule(out)
- return out
+ return out
class CompilationUnit(object):
@@ -1700,7 +1700,7 @@ Source code for torch.jit
_jit_script_class_compile(qualified_name, ast, rcb)
_add_script_class(obj, qualified_name)
-def script(obj, optimize=None, _frames_up=0, _rcb=None):
+[docs]def script(obj, optimize=None, _frames_up=0, _rcb=None):
r"""
Scripting a function or ``nn.Module`` will inspect the source code, compile
it as TorchScript code using the TorchScript compiler, and return a :class:`ScriptModule` or
@@ -1888,7 +1888,7 @@ Source code for torch.jit
# Forward docstrings
fn.__doc__ = obj.__doc__
_set_jit_function_cache(obj, fn)
- return fn
+ return fn
def interface(obj):
if not inspect.isclass(obj):
@@ -2518,9 +2518,9 @@ Source code for torch.jit
else:
# TODO MAKE SURE THAT DISABLING WORKS
- class ScriptModule(torch.nn.Module):
+[docs] class ScriptModule(torch.nn.Module):
def __init__(self):
- super(ScriptModule, self).__init__()
+ super(ScriptModule, self).__init__()
class TracedModule(ScriptModule):
diff --git a/docs/stable/_modules/torch/nn/modules/activation.html b/docs/stable/_modules/torch/nn/modules/activation.html
index f7123592d60c..1ec6a88b9ea8 100644
--- a/docs/stable/_modules/torch/nn/modules/activation.html
+++ b/docs/stable/_modules/torch/nn/modules/activation.html
@@ -507,7 +507,7 @@ Source code for torch.nn.modules.activation
return 'lower={}, upper={}{}'.format(self.lower, self.upper, inplace_str)
-class Hardtanh(Module):
+[docs]class Hardtanh(Module):
r"""Applies the HardTanh function element-wise
HardTanh is defined as:
@@ -577,7 +577,7 @@ Source code for torch.nn.modules.activation
inplace_str = ', inplace=True' if self.inplace else ''
return 'min_val={}, max_val={}{}'.format(
self.min_val, self.max_val, inplace_str
- )
+ )
class ReLU6(Hardtanh):
@@ -636,7 +636,7 @@ Source code for torch.nn.modules.activation
return torch.sigmoid(input)
-class Hardsigmoid(Module):
+[docs]class Hardsigmoid(Module):
r"""Applies the element-wise function:
.. math::
@@ -660,7 +660,7 @@ Source code for torch.nn.modules.activation
"""
def forward(self, input: Tensor) -> Tensor:
- return F.hardsigmoid(input)
+ return F.hardsigmoid(input)
class Tanh(Module):
@@ -687,7 +687,7 @@ Source code for torch.nn.modules.activation
return torch.tanh(input)
-class Hardswish(Module):
+[docs]class Hardswish(Module):
r"""Applies the hardswish function, element-wise, as described in the paper:
`Searching for MobileNetV3`_.
@@ -715,10 +715,10 @@ Source code for torch.nn.modules.activation
"""
def forward(self, input: Tensor) -> Tensor:
- return F.hardswish(input)
+ return F.hardswish(input)
-[docs]class ELU(Module):
+class ELU(Module):
r"""Applies the element-wise function:
.. math::
@@ -755,7 +755,7 @@ Source code for torch.nn.modules.activation
def extra_repr(self) -> str:
inplace_str = ', inplace=True' if self.inplace else ''
- return 'alpha={}{}'.format(self.alpha, inplace_str)
+ return 'alpha={}{}'.format(self.alpha, inplace_str)
class CELU(Module):
@@ -945,7 +945,7 @@ Source code for torch.nn.modules.activation
return '{}'.format(self.lambd)
-class LeakyReLU(Module):
+[docs]class LeakyReLU(Module):
r"""Applies the element-wise function:
.. math::
@@ -992,10 +992,10 @@ Source code for torch.nn.modules.activation
def extra_repr(self) -> str:
inplace_str = ', inplace=True' if self.inplace else ''
- return 'negative_slope={}{}'.format(self.negative_slope, inplace_str)
+ return 'negative_slope={}{}'.format(self.negative_slope, inplace_str)
-class LogSigmoid(Module):
+[docs]class LogSigmoid(Module):
r"""Applies the element-wise function:
.. math::
@@ -1016,7 +1016,7 @@ Source code for torch.nn.modules.activation
"""
def forward(self, input: Tensor) -> Tensor:
- return F.logsigmoid(input)
+ return F.logsigmoid(input)
class Softplus(Module):
@@ -1105,7 +1105,7 @@ Source code for torch.nn.modules.activation
return str(self.lambd)
-class MultiheadAttention(Module):
+[docs]class MultiheadAttention(Module):
r"""Allows the model to jointly attend to information
from different representation subspaces.
See reference: Attention Is All You Need
@@ -1200,7 +1200,7 @@ Source code for torch.nn.modules.activation
super(MultiheadAttention, self).__setstate__(state)
- def forward(self, query, key, value, key_padding_mask=None,
+[docs] def forward(self, query, key, value, key_padding_mask=None,
need_weights=True, attn_mask=None):
# type: (Tensor, Tensor, Tensor, Optional[Tensor], bool, Optional[Tensor]) -> Tuple[Tensor, Optional[Tensor]]
r"""
@@ -1261,7 +1261,7 @@ Source code for torch.nn.modules.activation
self.dropout, self.out_proj.weight, self.out_proj.bias,
training=self.training,
key_padding_mask=key_padding_mask, need_weights=need_weights,
- attn_mask=attn_mask)
+ attn_mask=attn_mask)
class PReLU(Module):
@@ -1507,7 +1507,7 @@ Source code for torch.nn.modules.activation
return F.softmax(input, 1, _stacklevel=5)
-class LogSoftmax(Module):
+[docs]class LogSoftmax(Module):
r"""Applies the :math:`\log(\text{Softmax}(x))` function to an n-dimensional
input Tensor. The LogSoftmax formulation can be simplified as:
@@ -1548,7 +1548,7 @@ Source code for torch.nn.modules.activation
return F.log_softmax(input, self.dim, _stacklevel=5)
def extra_repr(self):
- return 'dim={dim}'.format(dim=self.dim)
+ return 'dim={dim}'.format(dim=self.dim)
diff --git a/docs/stable/_modules/torch/nn/modules/batchnorm.html b/docs/stable/_modules/torch/nn/modules/batchnorm.html
index d6f3e4670a92..8801d57e2749 100644
--- a/docs/stable/_modules/torch/nn/modules/batchnorm.html
+++ b/docs/stable/_modules/torch/nn/modules/batchnorm.html
@@ -473,7 +473,7 @@ Source code for torch.nn.modules.batchnorm
self.weight, self.bias, bn_training, exponential_average_factor, self.eps)
-[docs]class BatchNorm1d(_BatchNorm):
+class BatchNorm1d(_BatchNorm):
r"""Applies Batch Normalization over a 2D or 3D input (a mini-batch of 1D
inputs with optional additional channel dimension) as described in the paper
`Batch Normalization: Accelerating Deep Network Training by Reducing
@@ -541,10 +541,10 @@ Source code for torch.nn.modules.batchnorm
def _check_input_dim(self, input):
if input.dim() != 2 and input.dim() != 3:
raise ValueError('expected 2D or 3D input (got {}D input)'
- .format(input.dim()))
+ .format(input.dim()))
-[docs]class BatchNorm2d(_BatchNorm):
+class BatchNorm2d(_BatchNorm):
r"""Applies Batch Normalization over a 4D input (a mini-batch of 2D inputs
with additional channel dimension) as described in the paper
`Batch Normalization: Accelerating Deep Network Training by Reducing
@@ -612,10 +612,10 @@ Source code for torch.nn.modules.batchnorm
def _check_input_dim(self, input):
if input.dim() != 4:
raise ValueError('expected 4D input (got {}D input)'
- .format(input.dim()))
+ .format(input.dim()))
-[docs]class BatchNorm3d(_BatchNorm):
+class BatchNorm3d(_BatchNorm):
r"""Applies Batch Normalization over a 5D input (a mini-batch of 3D inputs
with additional channel dimension) as described in the paper
`Batch Normalization: Accelerating Deep Network Training by Reducing
@@ -684,10 +684,10 @@ Source code for torch.nn.modules.batchnorm
def _check_input_dim(self, input):
if input.dim() != 5:
raise ValueError('expected 5D input (got {}D input)'
- .format(input.dim()))
+ .format(input.dim()))
-class SyncBatchNorm(_BatchNorm):
+[docs]class SyncBatchNorm(_BatchNorm):
r"""Applies Batch Normalization over a N-Dimensional input (a mini-batch of [N-2]D inputs
with additional channel dimension) as described in the paper
`Batch Normalization: Accelerating Deep Network Training by Reducing
@@ -844,7 +844,7 @@ Source code for torch.nn.modules.batchnorm
input, self.weight, self.bias, self.running_mean, self.running_var,
self.eps, exponential_average_factor, process_group, world_size)
- @classmethod
+[docs] @classmethod
def convert_sync_batchnorm(cls, module, process_group=None):
r"""Helper function to convert all :attr:`BatchNorm*D` layers in the model to
:class:`torch.nn.SyncBatchNorm` layers.
@@ -890,7 +890,7 @@ Source code for torch.nn.modules.batchnorm
for name, child in module.named_children():
module_output.add_module(name, cls.convert_sync_batchnorm(child, process_group))
del module
- return module_output
+ return module_output
diff --git a/docs/stable/_modules/torch/nn/modules/container.html b/docs/stable/_modules/torch/nn/modules/container.html
index 3557d0e3b04c..c60fd1f7ad72 100644
--- a/docs/stable/_modules/torch/nn/modules/container.html
+++ b/docs/stable/_modules/torch/nn/modules/container.html
@@ -362,7 +362,7 @@ Source code for torch.nn.modules.container
self.add_module(key, value)
-[docs]class Sequential(Module):
+class Sequential(Module):
r"""A sequential container.
Modules will be added to it in the order they are passed in the constructor.
Alternatively, an ordered dict of modules can also be passed in.
@@ -452,10 +452,10 @@ Source code for torch.nn.modules.container
def forward(self, input):
for module in self:
input = module(input)
- return input
+ return input
-class ModuleList(Module):
+[docs]class ModuleList(Module):
r"""Holds submodules in a list.
:class:`~torch.nn.ModuleList` can be indexed like a regular Python list, but
@@ -531,7 +531,7 @@ Source code for torch.nn.modules.container
keys = [key for key in keys if not key.isdigit()]
return keys
- def insert(self, index: int, module: Module) -> None:
+[docs] def insert(self, index: int, module: Module) -> None:
r"""Insert a given module before a given index in the list.
Arguments:
@@ -540,18 +540,18 @@ Source code for torch.nn.modules.container
"""
for i in range(len(self._modules), index, -1):
self._modules[str(i)] = self._modules[str(i - 1)]
- self._modules[str(index)] = module
+ self._modules[str(index)] = module
- def append(self: T, module: Module) -> T:
+[docs] def append(self: T, module: Module) -> T:
r"""Appends a given module to the end of the list.
Arguments:
module (nn.Module): module to append
"""
self.add_module(str(len(self)), module)
- return self
+ return self
- def extend(self: T, modules: Iterable[Module]) -> T:
+[docs] def extend(self: T, modules: Iterable[Module]) -> T:
r"""Appends modules from a Python iterable to the end of the list.
Arguments:
@@ -563,13 +563,13 @@ Source code for torch.nn.modules.container
offset = len(self)
for i, module in enumerate(modules):
self.add_module(str(offset + i), module)
- return self
+ return self
def forward(self):
- raise NotImplementedError()
+ raise NotImplementedError()
-class ModuleDict(Module):
+[docs]class ModuleDict(Module):
r"""Holds submodules in a dictionary.
:class:`~torch.nn.ModuleDict` can be indexed like a regular Python dictionary,
@@ -638,12 +638,12 @@ Source code for torch.nn.modules.container
def __contains__(self, key: str) -> bool:
return key in self._modules
- def clear(self) -> None:
+[docs] def clear(self) -> None:
"""Remove all items from the ModuleDict.
"""
- self._modules.clear()
+ self._modules.clear()
- def pop(self, key: str) -> Module:
+[docs] def pop(self, key: str) -> Module:
r"""Remove key from the ModuleDict and return its module.
Arguments:
@@ -651,27 +651,27 @@ Source code for torch.nn.modules.container
"""
v = self[key]
del self[key]
- return v
+ return v
- @_copy_to_script_wrapper
+[docs] @_copy_to_script_wrapper
def keys(self) -> Iterable[str]:
r"""Return an iterable of the ModuleDict keys.
"""
- return self._modules.keys()
+ return self._modules.keys()
- @_copy_to_script_wrapper
+[docs] @_copy_to_script_wrapper
def items(self) -> Iterable[Tuple[str, Module]]:
r"""Return an iterable of the ModuleDict key/value pairs.
"""
- return self._modules.items()
+ return self._modules.items()
- @_copy_to_script_wrapper
+[docs] @_copy_to_script_wrapper
def values(self) -> Iterable[Module]:
r"""Return an iterable of the ModuleDict values.
"""
- return self._modules.values()
+ return self._modules.values()
- def update(self, modules: Mapping[str, Module]) -> None:
+[docs] def update(self, modules: Mapping[str, Module]) -> None:
r"""Update the :class:`~torch.nn.ModuleDict` with the key-value pairs from a
mapping or an iterable, overwriting existing keys.
@@ -704,10 +704,10 @@ Source code for torch.nn.modules.container
raise ValueError("ModuleDict update sequence element "
"#" + str(j) + " has length " + str(len(m)) +
"; 2 is required")
- self[m[0]] = m[1]
+ self[m[0]] = m[1]
def forward(self):
- raise NotImplementedError()
+ raise NotImplementedError()
class ParameterList(Module):
diff --git a/docs/stable/_modules/torch/nn/modules/conv.html b/docs/stable/_modules/torch/nn/modules/conv.html
index bc80ef42c898..9ee2f7fccfa6 100644
--- a/docs/stable/_modules/torch/nn/modules/conv.html
+++ b/docs/stable/_modules/torch/nn/modules/conv.html
@@ -449,7 +449,7 @@ Source code for torch.nn.modules.conv
self.padding_mode = 'zeros'
-class Conv1d(_ConvNd):
+[docs]class Conv1d(_ConvNd):
r"""Applies a 1D convolution over an input signal composed of several input
planes.
@@ -591,7 +591,7 @@ Source code for torch.nn.modules.conv
self.weight, self.bias, self.stride,
_single(0), self.dilation, self.groups)
return F.conv1d(input, self.weight, self.bias, self.stride,
- self.padding, self.dilation, self.groups)
+ self.padding, self.dilation, self.groups)
[docs]class Conv2d(_ConvNd):
diff --git a/docs/stable/_modules/torch/nn/modules/distance.html b/docs/stable/_modules/torch/nn/modules/distance.html
index 6dc27a616f07..d6914cf2d86f 100644
--- a/docs/stable/_modules/torch/nn/modules/distance.html
+++ b/docs/stable/_modules/torch/nn/modules/distance.html
@@ -341,7 +341,7 @@ Source code for torch.nn.modules.distance
from torch import Tensor
-class PairwiseDistance(Module):
+[docs]class PairwiseDistance(Module):
r"""
Computes the batchwise pairwise distance between vectors :math:`v_1`, :math:`v_2` using the p-norm:
@@ -376,10 +376,10 @@ Source code for torch.nn.modules.distance
self.keepdim = keepdim
def forward(self, x1: Tensor, x2: Tensor) -> Tensor:
- return F.pairwise_distance(x1, x2, self.norm, self.eps, self.keepdim)
+ return F.pairwise_distance(x1, x2, self.norm, self.eps, self.keepdim)
-[docs]class CosineSimilarity(Module):
+class CosineSimilarity(Module):
r"""Returns cosine similarity between :math:`x_1` and :math:`x_2`, computed along dim.
.. math ::
@@ -409,7 +409,7 @@ Source code for torch.nn.modules.distance
self.eps = eps
def forward(self, x1: Tensor, x2: Tensor) -> Tensor:
- return F.cosine_similarity(x1, x2, self.dim, self.eps)
+ return F.cosine_similarity(x1, x2, self.dim, self.eps)
diff --git a/docs/stable/_modules/torch/nn/modules/dropout.html b/docs/stable/_modules/torch/nn/modules/dropout.html
index 9385e2dd3817..8f1d1a623938 100644
--- a/docs/stable/_modules/torch/nn/modules/dropout.html
+++ b/docs/stable/_modules/torch/nn/modules/dropout.html
@@ -358,7 +358,7 @@ Source code for torch.nn.modules.dropout
return 'p={}, inplace={}'.format(self.p, self.inplace)
-[docs]class Dropout(_DropoutNd):
+class Dropout(_DropoutNd):
r"""During training, randomly zeroes some of the elements of the input
tensor with probability :attr:`p` using samples from a Bernoulli
distribution. Each channel will be zeroed out independently on every forward
@@ -392,10 +392,10 @@ Source code for torch.nn.modules.dropout
"""
def forward(self, input: Tensor) -> Tensor:
- return F.dropout(input, self.p, self.training, self.inplace)
+ return F.dropout(input, self.p, self.training, self.inplace)
-[docs]class Dropout2d(_DropoutNd):
+class Dropout2d(_DropoutNd):
r"""Randomly zero out entire channels (a channel is a 2D feature map,
e.g., the :math:`j`-th channel of the :math:`i`-th sample in the
batched input is a 2D tensor :math:`\text{input}[i, j]`).
@@ -434,10 +434,10 @@ Source code for torch.nn.modules.dropout
"""
def forward(self, input: Tensor) -> Tensor:
- return F.dropout2d(input, self.p, self.training, self.inplace)
+ return F.dropout2d(input, self.p, self.training, self.inplace)
-[docs]class Dropout3d(_DropoutNd):
+class Dropout3d(_DropoutNd):
r"""Randomly zero out entire channels (a channel is a 3D feature map,
e.g., the :math:`j`-th channel of the :math:`i`-th sample in the
batched input is a 3D tensor :math:`\text{input}[i, j]`).
@@ -476,10 +476,10 @@ Source code for torch.nn.modules.dropout
"""
def forward(self, input: Tensor) -> Tensor:
- return F.dropout3d(input, self.p, self.training, self.inplace)
+ return F.dropout3d(input, self.p, self.training, self.inplace)
-class AlphaDropout(_DropoutNd):
+[docs]class AlphaDropout(_DropoutNd):
r"""Applies Alpha Dropout over the input.
Alpha Dropout is a type of Dropout that maintains the self-normalizing
@@ -518,7 +518,7 @@ Source code for torch.nn.modules.dropout
"""
def forward(self, input: Tensor) -> Tensor:
- return F.alpha_dropout(input, self.p, self.training)
+ return F.alpha_dropout(input, self.p, self.training)
class FeatureAlphaDropout(_DropoutNd):
diff --git a/docs/stable/_modules/torch/nn/modules/fold.html b/docs/stable/_modules/torch/nn/modules/fold.html
index a4344a8aebe1..5027366d086f 100644
--- a/docs/stable/_modules/torch/nn/modules/fold.html
+++ b/docs/stable/_modules/torch/nn/modules/fold.html
@@ -343,7 +343,7 @@ Source code for torch.nn.modules.fold
from ..common_types import _size_any_t
-[docs]class Fold(Module):
+class Fold(Module):
r"""Combines an array of sliding local blocks into a large containing
tensor.
@@ -485,7 +485,7 @@ Source code for torch.nn.modules.fold
return 'output_size={output_size}, kernel_size={kernel_size}, ' \
'dilation={dilation}, padding={padding}, stride={stride}'.format(
**self.__dict__
- )
+ )
[docs]class Unfold(Module):
diff --git a/docs/stable/_modules/torch/nn/modules/instancenorm.html b/docs/stable/_modules/torch/nn/modules/instancenorm.html
index b291becfd26e..083310962935 100644
--- a/docs/stable/_modules/torch/nn/modules/instancenorm.html
+++ b/docs/stable/_modules/torch/nn/modules/instancenorm.html
@@ -394,7 +394,7 @@ Source code for torch.nn.modules.instancenorm
self.training or not self.track_running_stats, self.momentum, self.eps)
-class InstanceNorm1d(_InstanceNorm):
+[docs]class InstanceNorm1d(_InstanceNorm):
r"""Applies Instance Normalization over a 3D input (a mini-batch of 1D
inputs with optional additional channel dimension) as described in the paper
`Instance Normalization: The Missing Ingredient for Fast Stylization
@@ -472,10 +472,10 @@ Source code for torch.nn.modules.instancenorm
)
if input.dim() != 3:
raise ValueError('expected 3D input (got {}D input)'
- .format(input.dim()))
+ .format(input.dim()))
-class InstanceNorm2d(_InstanceNorm):
+[docs]class InstanceNorm2d(_InstanceNorm):
r"""Applies Instance Normalization over a 4D input (a mini-batch of 2D inputs
with additional channel dimension) as described in the paper
`Instance Normalization: The Missing Ingredient for Fast Stylization
@@ -546,7 +546,7 @@ Source code for torch.nn.modules.instancenorm
def _check_input_dim(self, input):
if input.dim() != 4:
raise ValueError('expected 4D input (got {}D input)'
- .format(input.dim()))
+ .format(input.dim()))
[docs]class InstanceNorm3d(_InstanceNorm):
diff --git a/docs/stable/_modules/torch/nn/modules/linear.html b/docs/stable/_modules/torch/nn/modules/linear.html
index 946022a7b73f..9542e5ae4d88 100644
--- a/docs/stable/_modules/torch/nn/modules/linear.html
+++ b/docs/stable/_modules/torch/nn/modules/linear.html
@@ -345,7 +345,7 @@ Source code for torch.nn.modules.linear
from .module import Module
-class Identity(Module):
+[docs]class Identity(Module):
r"""A placeholder identity operator that is argument-insensitive.
Args:
@@ -365,10 +365,10 @@ Source code for torch.nn.modules.linear
super(Identity, self).__init__()
def forward(self, input: Tensor) -> Tensor:
- return input
+ return input
-class Linear(Module):
+[docs]class Linear(Module):
r"""Applies a linear transformation to the incoming data: :math:`y = xA^T + b`
Args:
@@ -430,7 +430,7 @@ Source code for torch.nn.modules.linear
def extra_repr(self) -> str:
return 'in_features={}, out_features={}, bias={}'.format(
self.in_features, self.out_features, self.bias is not None
- )
+ )
# This class exists soley for Transformer; it has an annotation stating
@@ -442,7 +442,7 @@ Source code for torch.nn.modules.linear
super().__init__(in_features, out_features, bias=True)
-[docs]class Bilinear(Module):
+class Bilinear(Module):
r"""Applies a bilinear transformation to the incoming data:
:math:`y = x_1^T A x_2 + b`
@@ -511,7 +511,7 @@ Source code for torch.nn.modules.linear
def extra_repr(self) -> str:
return 'in1_features={}, in2_features={}, out_features={}, bias={}'.format(
self.in1_features, self.in2_features, self.out_features, self.bias is not None
- )
+ )
# TODO: PartialLinear - maybe in sparse?
diff --git a/docs/stable/_modules/torch/nn/modules/loss.html b/docs/stable/_modules/torch/nn/modules/loss.html
index aa82db3289db..5dfac6d8a612 100644
--- a/docs/stable/_modules/torch/nn/modules/loss.html
+++ b/docs/stable/_modules/torch/nn/modules/loss.html
@@ -362,7 +362,7 @@ Source code for torch.nn.modules.loss
self.register_buffer('weight', weight)
-class L1Loss(_Loss):
+[docs]class L1Loss(_Loss):
r"""Creates a criterion that measures the mean absolute error (MAE) between each element in
the input :math:`x` and target :math:`y`.
@@ -427,7 +427,7 @@ Source code for torch.nn.modules.loss
super(L1Loss, self).__init__(size_average, reduce, reduction)
def forward(self, input: Tensor, target: Tensor) -> Tensor:
- return F.l1_loss(input, target, reduction=self.reduction)
+ return F.l1_loss(input, target, reduction=self.reduction)
class NLLLoss(_WeightedLoss):
@@ -631,7 +631,7 @@ Source code for torch.nn.modules.loss
eps=self.eps, reduction=self.reduction)
-class KLDivLoss(_Loss):
+[docs]class KLDivLoss(_Loss):
r"""The `Kullback-Leibler divergence`_ Loss
KL divergence is a useful distance measure for continuous distributions
@@ -713,10 +713,10 @@ Source code for torch.nn.modules.loss
self.log_target = log_target
def forward(self, input: Tensor, target: Tensor) -> Tensor:
- return F.kl_div(input, target, reduction=self.reduction, log_target=self.log_target)
+ return F.kl_div(input, target, reduction=self.reduction, log_target=self.log_target)
-class MSELoss(_Loss):
+[docs]class MSELoss(_Loss):
r"""Creates a criterion that measures the mean squared error (squared L2 norm) between
each element in the input :math:`x` and target :math:`y`.
@@ -779,7 +779,7 @@ Source code for torch.nn.modules.loss
super(MSELoss, self).__init__(size_average, reduce, reduction)
def forward(self, input: Tensor, target: Tensor) -> Tensor:
- return F.mse_loss(input, target, reduction=self.reduction)
+ return F.mse_loss(input, target, reduction=self.reduction)
class BCELoss(_WeightedLoss):
@@ -968,7 +968,7 @@ Source code for torch.nn.modules.loss
reduction=self.reduction)
-class HingeEmbeddingLoss(_Loss):
+[docs]class HingeEmbeddingLoss(_Loss):
r"""Measures the loss given an input tensor :math:`x` and a labels tensor :math:`y`
(containing 1 or -1).
This is usually used for measuring whether two inputs are similar or
@@ -1025,10 +1025,10 @@ Source code for torch.nn.modules.loss
self.margin = margin
def forward(self, input: Tensor, target: Tensor) -> Tensor:
- return F.hinge_embedding_loss(input, target, margin=self.margin, reduction=self.reduction)
+ return F.hinge_embedding_loss(input, target, margin=self.margin, reduction=self.reduction)
-class MultiLabelMarginLoss(_Loss):
+[docs]class MultiLabelMarginLoss(_Loss):
r"""Creates a criterion that optimizes a multi-class multi-classification
hinge loss (margin-based loss) between input :math:`x` (a 2D mini-batch `Tensor`)
and output :math:`y` (which is a 2D `Tensor` of target class indices).
@@ -1089,7 +1089,7 @@ Source code for torch.nn.modules.loss
super(MultiLabelMarginLoss, self).__init__(size_average, reduce, reduction)
def forward(self, input: Tensor, target: Tensor) -> Tensor:
- return F.multilabel_margin_loss(input, target, reduction=self.reduction)
+ return F.multilabel_margin_loss(input, target, reduction=self.reduction)
class SmoothL1Loss(_Loss):
@@ -1191,7 +1191,7 @@ Source code for torch.nn.modules.loss
return F.soft_margin_loss(input, target, reduction=self.reduction)
-[docs]class CrossEntropyLoss(_WeightedLoss):
+class CrossEntropyLoss(_WeightedLoss):
r"""This criterion combines :func:`nn.LogSoftmax` and :func:`nn.NLLLoss` in one single class.
It is useful when training a classification problem with `C` classes.
@@ -1282,10 +1282,10 @@ Source code for torch.nn.modules.loss
def forward(self, input: Tensor, target: Tensor) -> Tensor:
return F.cross_entropy(input, target, weight=self.weight,
- ignore_index=self.ignore_index, reduction=self.reduction)
+ ignore_index=self.ignore_index, reduction=self.reduction)
-class MultiLabelSoftMarginLoss(_WeightedLoss):
+[docs]class MultiLabelSoftMarginLoss(_WeightedLoss):
r"""Creates a criterion that optimizes a multi-label one-versus-all
loss based on max-entropy, between input :math:`x` and target :math:`y` of size
:math:`(N, C)`.
@@ -1329,7 +1329,7 @@ Source code for torch.nn.modules.loss
super(MultiLabelSoftMarginLoss, self).__init__(weight, size_average, reduce, reduction)
def forward(self, input: Tensor, target: Tensor) -> Tensor:
- return F.multilabel_soft_margin_loss(input, target, weight=self.weight, reduction=self.reduction)
+ return F.multilabel_soft_margin_loss(input, target, weight=self.weight, reduction=self.reduction)
class CosineEmbeddingLoss(_Loss):
@@ -1379,7 +1379,7 @@ Source code for torch.nn.modules.loss
return F.cosine_embedding_loss(input1, input2, target, margin=self.margin, reduction=self.reduction)
-class MarginRankingLoss(_Loss):
+[docs]class MarginRankingLoss(_Loss):
r"""Creates a criterion that measures the loss given
inputs :math:`x1`, :math:`x2`, two 1D mini-batch `Tensors`,
and a label 1D mini-batch tensor :math:`y` (containing 1 or -1).
@@ -1423,10 +1423,10 @@ Source code for torch.nn.modules.loss
self.margin = margin
def forward(self, input1: Tensor, input2: Tensor, target: Tensor) -> Tensor:
- return F.margin_ranking_loss(input1, input2, target, margin=self.margin, reduction=self.reduction)
+ return F.margin_ranking_loss(input1, input2, target, margin=self.margin, reduction=self.reduction)
-class MultiMarginLoss(_WeightedLoss):
+[docs]class MultiMarginLoss(_WeightedLoss):
r"""Creates a criterion that optimizes a multi-class classification hinge
loss (margin-based loss) between input :math:`x` (a 2D mini-batch `Tensor`) and
output :math:`y` (which is a 1D tensor of target class indices,
@@ -1487,7 +1487,7 @@ Source code for torch.nn.modules.loss
def forward(self, input: Tensor, target: Tensor) -> Tensor:
return F.multi_margin_loss(input, target, p=self.p, margin=self.margin,
- weight=self.weight, reduction=self.reduction)
+ weight=self.weight, reduction=self.reduction)
[docs]class TripletMarginLoss(_Loss):
diff --git a/docs/stable/_modules/torch/nn/modules/module.html b/docs/stable/_modules/torch/nn/modules/module.html
index 06987a5fc4d3..eef19b781c4d 100644
--- a/docs/stable/_modules/torch/nn/modules/module.html
+++ b/docs/stable/_modules/torch/nn/modules/module.html
@@ -495,7 +495,7 @@ Source code for torch.nn.modules.module
return handle
-class Module:
+[docs]class Module:
r"""Base class for all neural network modules.
Your models should also subclass this class.
@@ -571,7 +571,7 @@ Source code for torch.nn.modules.module
"""
forward: Callable[..., Any] = _forward_unimplemented
- def register_buffer(self, name: str, tensor: Tensor, persistent: bool = True) -> None:
+[docs] def register_buffer(self, name: str, tensor: Tensor, persistent: bool = True) -> None:
r"""Adds a buffer to the module.
This is typically used to register a buffer that should not to be
@@ -621,9 +621,9 @@ Source code for torch.nn.modules.module
if persistent:
self._non_persistent_buffers_set.discard(name)
else:
- self._non_persistent_buffers_set.add(name)
+ self._non_persistent_buffers_set.add(name)
- def register_parameter(self, name: str, param: Parameter) -> None:
+[docs] def register_parameter(self, name: str, param: Parameter) -> None:
r"""Adds a parameter to the module.
The parameter can be accessed as an attribute using given name.
@@ -660,9 +660,9 @@ Source code for torch.nn.modules.module
"as a function of another Tensor, compute the value in "
"the forward() method.".format(name))
else:
- self._parameters[name] = param
+ self._parameters[name] = param
- def add_module(self, name: str, module: 'Module') -> None:
+[docs] def add_module(self, name: str, module: 'Module') -> None:
r"""Adds a child module to the current module.
The module can be accessed as an attribute using the given name.
@@ -684,7 +684,7 @@ Source code for torch.nn.modules.module
raise KeyError("module name can't contain \".\"")
elif name == '':
raise KeyError("module name can't be empty string \"\"")
- self._modules[name] = module
+ self._modules[name] = module
def _apply(self, fn):
for module in self.children():
@@ -735,7 +735,7 @@ Source code for torch.nn.modules.module
return self
- def apply(self: T, fn: Callable[['Module'], None]) -> T:
+[docs] def apply(self: T, fn: Callable[['Module'], None]) -> T:
r"""Applies ``fn`` recursively to every submodule (as returned by ``.children()``)
as well as self. Typical use includes initializing the parameters of a model
(see also :ref:`nn-init-doc`).
@@ -776,9 +776,9 @@ Source code for torch.nn.modules.module
for module in self.children():
module.apply(fn)
fn(self)
- return self
+ return self
- def cuda(self: T, device: Optional[Union[int, device]] = None) -> T:
+[docs] def cuda(self: T, device: Optional[Union[int, device]] = None) -> T:
r"""Moves all model parameters and buffers to the GPU.
This also makes associated parameters and buffers different objects. So
@@ -792,17 +792,17 @@ Source code for torch.nn.modules.module
Returns:
Module: self
"""
- return self._apply(lambda t: t.cuda(device))
+ return self._apply(lambda t: t.cuda(device))
- def cpu(self: T) -> T:
+[docs] def cpu(self: T) -> T:
r"""Moves all model parameters and buffers to the CPU.
Returns:
Module: self
"""
- return self._apply(lambda t: t.cpu())
+ return self._apply(lambda t: t.cpu())
- def type(self: T, dst_type: Union[dtype, str]) -> T:
+[docs] def type(self: T, dst_type: Union[dtype, str]) -> T:
r"""Casts all parameters and buffers to :attr:`dst_type`.
Arguments:
@@ -811,39 +811,39 @@ Source code for torch.nn.modules.module
Returns:
Module: self
"""
- return self._apply(lambda t: t.type(dst_type))
+ return self._apply(lambda t: t.type(dst_type))
- def float(self: T) -> T:
+[docs] def float(self: T) -> T:
r"""Casts all floating point parameters and buffers to float datatype.
Returns:
Module: self
"""
- return self._apply(lambda t: t.float() if t.is_floating_point() else t)
+ return self._apply(lambda t: t.float() if t.is_floating_point() else t)
- def double(self: T) -> T:
+[docs] def double(self: T) -> T:
r"""Casts all floating point parameters and buffers to ``double`` datatype.
Returns:
Module: self
"""
- return self._apply(lambda t: t.double() if t.is_floating_point() else t)
+ return self._apply(lambda t: t.double() if t.is_floating_point() else t)
- def half(self: T) -> T:
+[docs] def half(self: T) -> T:
r"""Casts all floating point parameters and buffers to ``half`` datatype.
Returns:
Module: self
"""
- return self._apply(lambda t: t.half() if t.is_floating_point() else t)
+ return self._apply(lambda t: t.half() if t.is_floating_point() else t)
- def bfloat16(self: T) -> T:
+[docs] def bfloat16(self: T) -> T:
r"""Casts all floating point parameters and buffers to ``bfloat16`` datatype.
Returns:
Module: self
"""
- return self._apply(lambda t: t.bfloat16() if t.is_floating_point() else t)
+ return self._apply(lambda t: t.bfloat16() if t.is_floating_point() else t)
@overload
def to(self: T, device: Optional[Union[int, device]] = ..., dtype: Optional[Union[dtype, str]] = ...,
@@ -858,7 +858,7 @@ Source code for torch.nn.modules.module
def to(self: T, tensor: Tensor, non_blocking: bool = ...) -> T:
...
- def to(self, *args, **kwargs):
+[docs] def to(self, *args, **kwargs):
r"""Moves and/or casts the parameters and buffers.
This can be called as
@@ -941,9 +941,9 @@ Source code for torch.nn.modules.module
return t.to(device, dtype if t.is_floating_point() else None, non_blocking, memory_format=convert_to_format)
return t.to(device, dtype if t.is_floating_point() else None, non_blocking)
- return self._apply(convert)
+ return self._apply(convert)
- def register_backward_hook(
+[docs] def register_backward_hook(
self, hook: Callable[['Module', _grad_t, _grad_t], Union[None, Tensor]]
) -> RemovableHandle:
r"""Registers a backward hook on the module.
@@ -977,9 +977,9 @@ Source code for torch.nn.modules.module
"""
handle = hooks.RemovableHandle(self._backward_hooks)
self._backward_hooks[handle.id] = hook
- return handle
+ return handle
- def register_forward_pre_hook(self, hook: Callable[..., None]) -> RemovableHandle:
+[docs] def register_forward_pre_hook(self, hook: Callable[..., None]) -> RemovableHandle:
r"""Registers a forward pre-hook on the module.
The hook will be called every time before :func:`forward` is invoked.
@@ -1000,9 +1000,9 @@ Source code for torch.nn.modules.module
"""
handle = hooks.RemovableHandle(self._forward_pre_hooks)
self._forward_pre_hooks[handle.id] = hook
- return handle
+ return handle
- def register_forward_hook(self, hook: Callable[..., None]) -> RemovableHandle:
+[docs] def register_forward_hook(self, hook: Callable[..., None]) -> RemovableHandle:
r"""Registers a forward hook on the module.
The hook will be called every time after :func:`forward` has computed an output.
@@ -1023,7 +1023,7 @@ Source code for torch.nn.modules.module
"""
handle = hooks.RemovableHandle(self._forward_hooks)
self._forward_hooks[handle.id] = hook
- return handle
+ return handle
def _slow_forward(self, *input, **kwargs):
tracing_state = torch._C._get_tracing_state()
@@ -1211,7 +1211,7 @@ Source code for torch.nn.modules.module
def state_dict(self, prefix: str = ..., keep_vars: bool = ...) -> Dict[str, Tensor]:
...
- def state_dict(self, destination=None, prefix='', keep_vars=False):
+[docs] def state_dict(self, destination=None, prefix='', keep_vars=False):
r"""Returns a dictionary containing a whole state of the module.
Both parameters and persistent buffers (e.g. running averages) are
@@ -1239,7 +1239,7 @@ Source code for torch.nn.modules.module
hook_result = hook(self, destination, prefix, local_metadata)
if hook_result is not None:
destination = hook_result
- return destination
+ return destination
def _register_load_state_dict_pre_hook(self, hook):
r"""These hooks will be called with arguments: `state_dict`, `prefix`,
@@ -1327,7 +1327,7 @@ Source code for torch.nn.modules.module
if input_name not in self._modules and input_name not in local_state:
unexpected_keys.append(key)
- def load_state_dict(self, state_dict: Union[Dict[str, Tensor], Dict[str, Tensor]],
+[docs] def load_state_dict(self, state_dict: Union[Dict[str, Tensor], Dict[str, Tensor]],
strict: bool = True):
r"""Copies parameters and buffers from :attr:`state_dict` into
this module and its descendants. If :attr:`strict` is ``True``, then
@@ -1380,7 +1380,7 @@ Source code for torch.nn.modules.module
if len(error_msgs) > 0:
raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
self.__class__.__name__, "\n\t".join(error_msgs)))
- return _IncompatibleKeys(missing_keys, unexpected_keys)
+ return _IncompatibleKeys(missing_keys, unexpected_keys)
def _named_members(self, get_members_fn, prefix='', recurse=True):
r"""Helper method for yielding various names + members of modules."""
@@ -1395,7 +1395,7 @@ Source code for torch.nn.modules.module
name = module_prefix + ('.' if module_prefix else '') + k
yield name, v
- def parameters(self, recurse: bool = True) -> Iterator[Parameter]:
+[docs] def parameters(self, recurse: bool = True) -> Iterator[Parameter]:
r"""Returns an iterator over module parameters.
This is typically passed to an optimizer.
@@ -1417,9 +1417,9 @@ Source code for torch.nn.modules.module
"""
for name, param in self.named_parameters(recurse=recurse):
- yield param
+ yield param
- def named_parameters(self, prefix: str = '', recurse: bool = True) -> Iterator[Tuple[str, Tensor]]:
+[docs] def named_parameters(self, prefix: str = '', recurse: bool = True) -> Iterator[Tuple[str, Tensor]]:
r"""Returns an iterator over module parameters, yielding both the
name of the parameter as well as the parameter itself.
@@ -1443,9 +1443,9 @@ Source code for torch.nn.modules.module
lambda module: module._parameters.items(),
prefix=prefix, recurse=recurse)
for elem in gen:
- yield elem
+ yield elem
- def buffers(self, recurse: bool = True) -> Iterator[Tensor]:
+[docs] def buffers(self, recurse: bool = True) -> Iterator[Tensor]:
r"""Returns an iterator over module buffers.
Args:
@@ -1465,9 +1465,9 @@ Source code for torch.nn.modules.module
"""
for name, buf in self.named_buffers(recurse=recurse):
- yield buf
+ yield buf
- def named_buffers(self, prefix: str = '', recurse: bool = True) -> Iterator[Tuple[str, Tensor]]:
+[docs] def named_buffers(self, prefix: str = '', recurse: bool = True) -> Iterator[Tuple[str, Tensor]]:
r"""Returns an iterator over module buffers, yielding both the
name of the buffer as well as the buffer itself.
@@ -1491,18 +1491,18 @@ Source code for torch.nn.modules.module
lambda module: module._buffers.items(),
prefix=prefix, recurse=recurse)
for elem in gen:
- yield elem
+ yield elem
- def children(self) -> Iterator['Module']:
+[docs] def children(self) -> Iterator['Module']:
r"""Returns an iterator over immediate children modules.
Yields:
Module: a child module
"""
for name, module in self.named_children():
- yield module
+ yield module
- def named_children(self) -> Iterator[Tuple[str, 'Module']]:
+[docs] def named_children(self) -> Iterator[Tuple[str, 'Module']]:
r"""Returns an iterator over immediate children modules, yielding both
the name of the module as well as the module itself.
@@ -1520,9 +1520,9 @@ Source code for torch.nn.modules.module
for name, module in self._modules.items():
if module is not None and module not in memo:
memo.add(module)
- yield name, module
+ yield name, module
- def modules(self) -> Iterator['Module']:
+[docs] def modules(self) -> Iterator['Module']:
r"""Returns an iterator over all modules in the network.
Yields:
@@ -1547,9 +1547,9 @@ Source code for torch.nn.modules.module
"""
for name, module in self.named_modules():
- yield module
+ yield module
- def named_modules(self, memo: Optional[Set['Module']] = None, prefix: str = ''):
+[docs] def named_modules(self, memo: Optional[Set['Module']] = None, prefix: str = ''):
r"""Returns an iterator over all modules in the network, yielding
both the name of the module as well as the module itself.
@@ -1585,9 +1585,9 @@ Source code for torch.nn.modules.module
continue
submodule_prefix = prefix + ('.' if prefix else '') + name
for m in module.named_modules(memo, submodule_prefix):
- yield m
+ yield m
- def train(self: T, mode: bool = True) -> T:
+[docs] def train(self: T, mode: bool = True) -> T:
r"""Sets the module in training mode.
This has any effect only on certain modules. See documentations of
@@ -1605,9 +1605,9 @@ Source code for torch.nn.modules.module
self.training = mode
for module in self.children():
module.train(mode)
- return self
+ return self
- def eval(self: T) -> T:
+[docs] def eval(self: T) -> T:
r"""Sets the module in evaluation mode.
This has any effect only on certain modules. See documentations of
@@ -1620,9 +1620,9 @@ Source code for torch.nn.modules.module
Returns:
Module: self
"""
- return self.train(False)
+ return self.train(False)
- def requires_grad_(self: T, requires_grad: bool = True) -> T:
+[docs] def requires_grad_(self: T, requires_grad: bool = True) -> T:
r"""Change if autograd should record operations on parameters in this
module.
@@ -1641,9 +1641,9 @@ Source code for torch.nn.modules.module
"""
for p in self.parameters():
p.requires_grad_(requires_grad)
- return self
+ return self
- def zero_grad(self) -> None:
+[docs] def zero_grad(self) -> None:
r"""Sets gradients of all model parameters to zero."""
if getattr(self, '_is_replica', False):
warnings.warn(
@@ -1655,7 +1655,7 @@ Source code for torch.nn.modules.module
for p in self.parameters():
if p.grad is not None:
p.grad.detach_()
- p.grad.zero_()
+ p.grad.zero_()
def share_memory(self: T) -> T:
return self._apply(lambda t: t.share_memory_())
@@ -1663,14 +1663,14 @@ Source code for torch.nn.modules.module
def _get_name(self):
return self.__class__.__name__
- def extra_repr(self) -> str:
+[docs] def extra_repr(self) -> str:
r"""Set the extra representation of the module
To print customized extra information, you should reimplement
this method in your own modules. Both single-line and multi-line
strings are acceptable.
"""
- return ''
+ return ''
def __repr__(self):
# We treat the extra repr like the sub-module, one item per line
@@ -1721,7 +1721,7 @@ Source code for torch.nn.modules.module
replica._modules = replica._modules.copy()
replica._is_replica = True
- return replica
+ return replica
diff --git a/docs/stable/_modules/torch/nn/modules/padding.html b/docs/stable/_modules/torch/nn/modules/padding.html
index 3677724e4116..13501ea0f4d2 100644
--- a/docs/stable/_modules/torch/nn/modules/padding.html
+++ b/docs/stable/_modules/torch/nn/modules/padding.html
@@ -361,7 +361,7 @@ Source code for torch.nn.modules.padding
return 'padding={}, value={}'.format(self.padding, self.value)
-[docs]class ConstantPad1d(_ConstantPadNd):
+class ConstantPad1d(_ConstantPadNd):
r"""Pads the input tensor boundaries with a constant value.
For `N`-dimensional padding, use :func:`torch.nn.functional.pad()`.
@@ -408,10 +408,10 @@ Source code for torch.nn.modules.padding
def __init__(self, padding: _size_2_t, value: float):
super(ConstantPad1d, self).__init__(value)
- self.padding = _pair(padding)
+ self.padding = _pair(padding)
-[docs]class ConstantPad2d(_ConstantPadNd):
+class ConstantPad2d(_ConstantPadNd):
r"""Pads the input tensor boundaries with a constant value.
For `N`-dimensional padding, use :func:`torch.nn.functional.pad()`.
@@ -458,10 +458,10 @@ Source code for torch.nn.modules.padding
def __init__(self, padding: _size_4_t, value: float) -> None:
super(ConstantPad2d, self).__init__(value)
- self.padding = _quadruple(padding)
+ self.padding = _quadruple(padding)
-[docs]class ConstantPad3d(_ConstantPadNd):
+class ConstantPad3d(_ConstantPadNd):
r"""Pads the input tensor boundaries with a constant value.
For `N`-dimensional padding, use :func:`torch.nn.functional.pad()`.
@@ -497,7 +497,7 @@ Source code for torch.nn.modules.padding
def __init__(self, padding: _size_6_t, value: float) -> None:
super(ConstantPad3d, self).__init__(value)
- self.padding = _ntuple(6)(padding)
+ self.padding = _ntuple(6)(padding)
class _ReflectionPadNd(Module):
diff --git a/docs/stable/_modules/torch/nn/modules/pooling.html b/docs/stable/_modules/torch/nn/modules/pooling.html
index 15f33e8f019a..027dac6e752c 100644
--- a/docs/stable/_modules/torch/nn/modules/pooling.html
+++ b/docs/stable/_modules/torch/nn/modules/pooling.html
@@ -372,7 +372,7 @@ Source code for torch.nn.modules.pooling
', dilation={dilation}, ceil_mode={ceil_mode}'.format(**self.__dict__)
-class MaxPool1d(_MaxPoolNd):
+[docs]class MaxPool1d(_MaxPoolNd):
r"""Applies a 1D max pooling over an input signal composed of several input
planes.
@@ -423,10 +423,10 @@ Source code for torch.nn.modules.pooling
def forward(self, input: Tensor) -> Tensor:
return F.max_pool1d(input, self.kernel_size, self.stride,
self.padding, self.dilation, self.ceil_mode,
- self.return_indices)
+ self.return_indices)
-class MaxPool2d(_MaxPoolNd):
+[docs]class MaxPool2d(_MaxPoolNd):
r"""Applies a 2D max pooling over an input signal composed of several input
planes.
@@ -493,10 +493,10 @@ Source code for torch.nn.modules.pooling
def forward(self, input: Tensor) -> Tensor:
return F.max_pool2d(input, self.kernel_size, self.stride,
self.padding, self.dilation, self.ceil_mode,
- self.return_indices)
+ self.return_indices)
-class MaxPool3d(_MaxPoolNd):
+[docs]class MaxPool3d(_MaxPoolNd):
r"""Applies a 3D max pooling over an input signal composed of several input
planes.
@@ -567,7 +567,7 @@ Source code for torch.nn.modules.pooling
def forward(self, input: Tensor) -> Tensor:
return F.max_pool3d(input, self.kernel_size, self.stride,
self.padding, self.dilation, self.ceil_mode,
- self.return_indices)
+ self.return_indices)
class _MaxUnpoolNd(Module):
@@ -578,7 +578,7 @@ Source code for torch.nn.modules.pooling
)
-class MaxUnpool1d(_MaxUnpoolNd):
+[docs]class MaxUnpool1d(_MaxUnpoolNd):
r"""Computes a partial inverse of :class:`MaxPool1d`.
:class:`MaxPool1d` is not fully invertible, since the non-maximal values are lost.
@@ -644,10 +644,10 @@ Source code for torch.nn.modules.pooling
def forward(self, input: Tensor, indices: Tensor, output_size: Optional[List[int]] = None) -> Tensor:
return F.max_unpool1d(input, indices, self.kernel_size, self.stride,
- self.padding, output_size)
+ self.padding, output_size)
-class MaxUnpool2d(_MaxUnpoolNd):
+[docs]class MaxUnpool2d(_MaxUnpoolNd):
r"""Computes a partial inverse of :class:`MaxPool2d`.
:class:`MaxPool2d` is not fully invertible, since the non-maximal values are lost.
@@ -721,10 +721,10 @@ Source code for torch.nn.modules.pooling
def forward(self, input: Tensor, indices: Tensor, output_size: Optional[List[int]] = None) -> Tensor:
return F.max_unpool2d(input, indices, self.kernel_size, self.stride,
- self.padding, output_size)
+ self.padding, output_size)
-class MaxUnpool3d(_MaxUnpoolNd):
+[docs]class MaxUnpool3d(_MaxUnpoolNd):
r"""Computes a partial inverse of :class:`MaxPool3d`.
:class:`MaxPool3d` is not fully invertible, since the non-maximal values are lost.
@@ -787,7 +787,7 @@ Source code for torch.nn.modules.pooling
def forward(self, input: Tensor, indices: Tensor, output_size: Optional[List[int]] = None) -> Tensor:
return F.max_unpool3d(input, indices, self.kernel_size, self.stride,
- self.padding, output_size)
+ self.padding, output_size)
class _AvgPoolNd(Module):
@@ -1023,7 +1023,7 @@ Source code for torch.nn.modules.pooling
self.__dict__.setdefault('count_include_pad', True)
-[docs]class FractionalMaxPool2d(Module):
+class FractionalMaxPool2d(Module):
r"""Applies a 2D fractional max pooling over an input signal composed of several input planes.
Fractional MaxPooling is described in detail in the paper `Fractional MaxPooling`_ by Ben Graham
@@ -1084,7 +1084,7 @@ Source code for torch.nn.modules.pooling
return F.fractional_max_pool2d(
input, self.kernel_size, self.output_size, self.output_ratio,
self.return_indices,
- _random_samples=self._random_samples)
+ _random_samples=self._random_samples)
class FractionalMaxPool3d(Module):
@@ -1169,7 +1169,7 @@ Source code for torch.nn.modules.pooling
'ceil_mode={ceil_mode}'.format(**self.__dict__)
-class LPPool1d(_LPPoolNd):
+[docs]class LPPool1d(_LPPoolNd):
r"""Applies a 1D power-average pooling over an input signal composed of several input
planes.
@@ -1208,10 +1208,10 @@ Source code for torch.nn.modules.pooling
def forward(self, input: Tensor) -> Tensor:
return F.lp_pool1d(input, float(self.norm_type), self.kernel_size,
- self.stride, self.ceil_mode)
+ self.stride, self.ceil_mode)
-class LPPool2d(_LPPoolNd):
+[docs]class LPPool2d(_LPPoolNd):
r"""Applies a 2D power-average pooling over an input signal composed of several input
planes.
@@ -1263,7 +1263,7 @@ Source code for torch.nn.modules.pooling
def forward(self, input: Tensor) -> Tensor:
return F.lp_pool2d(input, float(self.norm_type), self.kernel_size,
- self.stride, self.ceil_mode)
+ self.stride, self.ceil_mode)
class _AdaptiveMaxPoolNd(Module):
diff --git a/docs/stable/_modules/torch/nn/modules/rnn.html b/docs/stable/_modules/torch/nn/modules/rnn.html
index c8156b9fc466..82d9321c8ef6 100644
--- a/docs/stable/_modules/torch/nn/modules/rnn.html
+++ b/docs/stable/_modules/torch/nn/modules/rnn.html
@@ -358,7 +358,7 @@ Source code for torch.nn.modules.rnn
return tensor.index_select(dim, permutation)
-[docs]class RNNBase(Module):
+class RNNBase(Module):
__constants__ = ['mode', 'input_size', 'hidden_size', 'num_layers', 'bias',
'batch_first', 'dropout', 'bidirectional']
@@ -443,7 +443,7 @@ Source code for torch.nn.modules.rnn
self._flat_weights[idx] = value
super(RNNBase, self).__setattr__(attr, value)
-[docs] def flatten_parameters(self) -> None:
+ def flatten_parameters(self) -> None:
"""Resets parameter data pointer so that they can use faster code paths.
Right now, this works only if the module is on the GPU and cuDNN is enabled.
@@ -485,7 +485,7 @@ Source code for torch.nn.modules.rnn
torch._cudnn_rnn_flatten_weight(
self._flat_weights, (4 if self.bias else 2),
self.input_size, rnn.get_cudnn_mode(self.mode), self.hidden_size, self.num_layers,
- self.batch_first, bool(self.bidirectional))
+ self.batch_first, bool(self.bidirectional))
def _apply(self, fn):
ret = super(RNNBase, self)._apply(fn)
@@ -627,7 +627,7 @@ Source code for torch.nn.modules.rnn
# flat weights list.
replica._flat_weights = replica._flat_weights[:]
replica._flat_weights_names = replica._flat_weights_names[:]
- return replica
+ return replica
class RNN(RNNBase):
@@ -750,7 +750,7 @@ Source code for torch.nn.modules.rnn
#
# TODO: remove the overriding implementations for LSTM and GRU when TorchScript
# support expressing these two modules generally.
-class LSTM(RNNBase):
+[docs]class LSTM(RNNBase):
r"""Applies a multi-layer long short-term memory (LSTM) RNN to an input
sequence.
@@ -922,7 +922,7 @@ Source code for torch.nn.modules.rnn
output_packed = PackedSequence(output, batch_sizes, sorted_indices, unsorted_indices)
return output_packed, self.permute_hidden(hidden, unsorted_indices)
else:
- return output, self.permute_hidden(hidden, unsorted_indices)
+ return output, self.permute_hidden(hidden, unsorted_indices)
class GRU(RNNBase):
@@ -1141,7 +1141,7 @@ Source code for torch.nn.modules.rnn
init.uniform_(weight, -stdv, stdv)
-[docs]class RNNCell(RNNCellBase):
+class RNNCell(RNNCellBase):
r"""An Elman RNN cell with tanh or ReLU non-linearity.
.. math::
@@ -1226,10 +1226,10 @@ Source code for torch.nn.modules.rnn
ret = input # TODO: remove when jit supports exception flow
raise RuntimeError(
"Unknown nonlinearity: {}".format(self.nonlinearity))
- return ret
+ return ret
-class LSTMCell(RNNCellBase):
+[docs]class LSTMCell(RNNCellBase):
r"""A long short-term memory (LSTM) cell.
.. math::
@@ -1304,7 +1304,7 @@ Source code for torch.nn.modules.rnn
input, hx,
self.weight_ih, self.weight_hh,
self.bias_ih, self.bias_hh,
- )
+ )
class GRUCell(RNNCellBase):
diff --git a/docs/stable/_modules/torch/nn/modules/transformer.html b/docs/stable/_modules/torch/nn/modules/transformer.html
index b168e16dc545..63aab3365a42 100644
--- a/docs/stable/_modules/torch/nn/modules/transformer.html
+++ b/docs/stable/_modules/torch/nn/modules/transformer.html
@@ -350,7 +350,7 @@ Source code for torch.nn.modules.transformer
from .normalization import LayerNorm
-[docs]class Transformer(Module):
+class Transformer(Module):
r"""A transformer model. User is able to modify the attributes as needed. The architecture
is based on the paper "Attention Is All You Need". Ashish Vaswani, Noam Shazeer,
Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Lukasz Kaiser, and
@@ -403,7 +403,7 @@ Source code for torch.nn.modules.transformer
self.d_model = d_model
self.nhead = nhead
-[docs] def forward(self, src: Tensor, tgt: Tensor, src_mask: Optional[Tensor] = None, tgt_mask: Optional[Tensor] = None,
+ def forward(self, src: Tensor, tgt: Tensor, src_mask: Optional[Tensor] = None, tgt_mask: Optional[Tensor] = None,
memory_mask: Optional[Tensor] = None, src_key_padding_mask: Optional[Tensor] = None,
tgt_key_padding_mask: Optional[Tensor] = None, memory_key_padding_mask: Optional[Tensor] = None) -> Tensor:
r"""Take in and process masked source/target sequences.
@@ -461,22 +461,22 @@ Source code for torch.nn.modules.transformer
output = self.decoder(tgt, memory, tgt_mask=tgt_mask, memory_mask=memory_mask,
tgt_key_padding_mask=tgt_key_padding_mask,
memory_key_padding_mask=memory_key_padding_mask)
- return output
+ return output
-[docs] def generate_square_subsequent_mask(self, sz: int) -> Tensor:
+ def generate_square_subsequent_mask(self, sz: int) -> Tensor:
r"""Generate a square mask for the sequence. The masked positions are filled with float('-inf').
Unmasked positions are filled with float(0.0).
"""
mask = (torch.triu(torch.ones(sz, sz)) == 1).transpose(0, 1)
mask = mask.float().masked_fill(mask == 0, float('-inf')).masked_fill(mask == 1, float(0.0))
- return mask
+ return mask
def _reset_parameters(self):
r"""Initiate parameters in the transformer model."""
for p in self.parameters():
if p.dim() > 1:
- xavier_uniform_(p)
+ xavier_uniform_(p)
[docs]class TransformerEncoder(Module):
@@ -523,7 +523,7 @@ Source code for torch.nn.modules.transformer
return output
-[docs]class TransformerDecoder(Module):
+class TransformerDecoder(Module):
r"""TransformerDecoder is a stack of N decoder layers
Args:
@@ -546,7 +546,7 @@ Source code for torch.nn.modules.transformer
self.num_layers = num_layers
self.norm = norm
-[docs] def forward(self, tgt: Tensor, memory: Tensor, tgt_mask: Optional[Tensor] = None,
+ def forward(self, tgt: Tensor, memory: Tensor, tgt_mask: Optional[Tensor] = None,
memory_mask: Optional[Tensor] = None, tgt_key_padding_mask: Optional[Tensor] = None,
memory_key_padding_mask: Optional[Tensor] = None) -> Tensor:
r"""Pass the inputs (and mask) through the decoder layer in turn.
@@ -573,7 +573,7 @@ Source code for torch.nn.modules.transformer
if self.norm is not None:
output = self.norm(output)
- return output
+ return output
[docs]class TransformerEncoderLayer(Module):
r"""TransformerEncoderLayer is made up of self-attn and feedforward network.
diff --git a/docs/stable/_modules/torch/nn/utils/convert_parameters.html b/docs/stable/_modules/torch/nn/utils/convert_parameters.html
index 5af721f05778..0e800305b71d 100644
--- a/docs/stable/_modules/torch/nn/utils/convert_parameters.html
+++ b/docs/stable/_modules/torch/nn/utils/convert_parameters.html
@@ -338,7 +338,7 @@ Source code for torch.nn.utils.convert_parameters
import torch
-def parameters_to_vector(parameters):
+[docs]def parameters_to_vector(parameters):
r"""Convert parameters to one vector
Arguments:
@@ -357,7 +357,7 @@ Source code for torch.nn.utils.convert_parameters
param_device = _check_param_device(param, param_device)
vec.append(param.view(-1))
- return torch.cat(vec)
+ return torch.cat(vec)
[docs]def vector_to_parameters(vec, parameters):
diff --git a/docs/stable/_modules/torch/nn/utils/prune.html b/docs/stable/_modules/torch/nn/utils/prune.html
index cc22134fa29c..098e089b462d 100644
--- a/docs/stable/_modules/torch/nn/utils/prune.html
+++ b/docs/stable/_modules/torch/nn/utils/prune.html
@@ -350,7 +350,7 @@ Source code for torch.nn.utils.prune
ABC = ABCMeta('ABC', (), {})
from collections import Iterable
-class BasePruningMethod(ABC):
+[docs]class BasePruningMethod(ABC):
r"""Abstract base class for creation of new pruning techniques.
Provides a skeleton for customization requiring the overriding of methods
@@ -371,7 +371,7 @@ Source code for torch.nn.utils.prune
"""
setattr(module, self._tensor_name, self.apply_mask(module))
- @abstractmethod
+[docs] @abstractmethod
def compute_mask(self, t, default_mask):
r"""Computes and returns a mask for the input tensor ``t``.
Starting from a base ``default_mask`` (which should be a mask of ones
@@ -388,9 +388,9 @@ Source code for torch.nn.utils.prune
Returns:
mask (torch.Tensor): mask to apply to ``t``, of same dims as ``t``
"""
- pass
+ pass
- def apply_mask(self, module):
+[docs] def apply_mask(self, module):
r"""Simply handles the multiplication between the parameter being
pruned and the generated mask.
Fetches the mask and the original tensor from the module
@@ -412,9 +412,9 @@ Source code for torch.nn.utils.prune
mask = getattr(module, self._tensor_name + "_mask")
orig = getattr(module, self._tensor_name + "_orig")
pruned_tensor = mask.to(dtype=orig.dtype) * orig
- return pruned_tensor
+ return pruned_tensor
- @classmethod
+[docs] @classmethod
def apply(cls, module, name, *args, **kwargs):
r"""Adds the forward pre-hook that enables pruning on the fly and
the reparametrization of a tensor in terms of the original tensor
@@ -528,9 +528,9 @@ Source code for torch.nn.utils.prune
del module._parameters[name + "_orig"]
raise e
- return method
+ return method
- def prune(self, t, default_mask=None):
+[docs] def prune(self, t, default_mask=None):
r"""Computes and returns a pruned version of input tensor ``t``
according to the pruning rule specified in :meth:`compute_mask`.
@@ -547,9 +547,9 @@ Source code for torch.nn.utils.prune
"""
if default_mask is None:
default_mask = torch.ones_like(t)
- return t * self.compute_mask(t, default_mask=default_mask)
+ return t * self.compute_mask(t, default_mask=default_mask)
- def remove(self, module):
+[docs] def remove(self, module):
r"""Removes the pruning reparameterization from a module. The pruned
parameter named ``name`` remains permanently pruned, and the parameter
named ``name+'_orig'`` is removed from the parameter list. Similarly,
@@ -575,10 +575,10 @@ Source code for torch.nn.utils.prune
orig.data = weight.data
del module._parameters[self._tensor_name + "_orig"]
del module._buffers[self._tensor_name + "_mask"]
- setattr(module, self._tensor_name, orig)
+ setattr(module, self._tensor_name, orig)
-class PruningContainer(BasePruningMethod):
+[docs]class PruningContainer(BasePruningMethod):
"""Container holding a sequence of pruning methods for iterative pruning.
Keeps track of the order in which pruning methods are applied and handles
combining successive pruning calls.
@@ -599,7 +599,7 @@ Source code for torch.nn.utils.prune
for method in args:
self.add_pruning_method(method)
- def add_pruning_method(self, method):
+[docs] def add_pruning_method(self, method):
r"""Adds a child pruning ``method`` to the container.
Args:
@@ -620,7 +620,7 @@ Source code for torch.nn.utils.prune
+ " Found '{}'".format(method._tensor_name)
)
# if all checks passed, add to _pruning_methods tuple
- self._pruning_methods += (method,)
+ self._pruning_methods += (method,)
def __len__(self):
return len(self._pruning_methods)
@@ -631,7 +631,7 @@ Source code for torch.nn.utils.prune
def __getitem__(self, idx):
return self._pruning_methods[idx]
- def compute_mask(self, t, default_mask):
+[docs] def compute_mask(self, t, default_mask):
r"""Applies the latest ``method`` by computing the new partial masks
and returning its combination with the ``default_mask``.
The new partial mask should be computed on the entries or channels
@@ -726,10 +726,10 @@ Source code for torch.nn.utils.prune
method = self._pruning_methods[-1]
mask = _combine_masks(method, t, default_mask)
- return mask
+ return mask
-class Identity(BasePruningMethod):
+[docs]class Identity(BasePruningMethod):
r"""Utility pruning method that does not prune any units but generates the
pruning parametrization with a mask of ones.
"""
@@ -740,7 +740,7 @@ Source code for torch.nn.utils.prune
mask = default_mask
return mask
- @classmethod
+[docs] @classmethod
def apply(cls, module, name):
r"""Adds the forward pre-hook that enables pruning on the fly and
the reparametrization of a tensor in terms of the original tensor
@@ -751,10 +751,10 @@ Source code for torch.nn.utils.prune
name (str): parameter name within ``module`` on which pruning
will act.
"""
- return super(Identity, cls).apply(module, name)
+ return super(Identity, cls).apply(module, name)
-class RandomUnstructured(BasePruningMethod):
+[docs]class RandomUnstructured(BasePruningMethod):
r"""Prune (currently unpruned) units in a tensor at random.
Args:
@@ -793,7 +793,7 @@ Source code for torch.nn.utils.prune
return mask
- @classmethod
+[docs] @classmethod
def apply(cls, module, name, amount):
r"""Adds the forward pre-hook that enables pruning on the fly and
the reparametrization of a tensor in terms of the original tensor
@@ -810,10 +810,10 @@ Source code for torch.nn.utils.prune
"""
return super(RandomUnstructured, cls).apply(
module, name, amount=amount
- )
+ )
-class L1Unstructured(BasePruningMethod):
+[docs]class L1Unstructured(BasePruningMethod):
r"""Prune (currently unpruned) units in a tensor by zeroing out the ones
with the lowest L1-norm.
@@ -855,7 +855,7 @@ Source code for torch.nn.utils.prune
return mask
- @classmethod
+[docs] @classmethod
def apply(cls, module, name, amount):
r"""Adds the forward pre-hook that enables pruning on the fly and
the reparametrization of a tensor in terms of the original tensor
@@ -870,10 +870,10 @@ Source code for torch.nn.utils.prune
fraction of parameters to prune. If ``int``, it represents the
absolute number of parameters to prune.
"""
- return super(L1Unstructured, cls).apply(module, name, amount=amount)
+ return super(L1Unstructured, cls).apply(module, name, amount=amount)
-class RandomStructured(BasePruningMethod):
+[docs]class RandomStructured(BasePruningMethod):
r"""Prune entire (currently unpruned) channels in a tensor at random.
Args:
@@ -893,7 +893,7 @@ Source code for torch.nn.utils.prune
self.amount = amount
self.dim = dim
- def compute_mask(self, t, default_mask):
+[docs] def compute_mask(self, t, default_mask):
r"""Computes and returns a mask for the input tensor ``t``.
Starting from a base ``default_mask`` (which should be a mask of ones
if the tensor has not been pruned yet), generate a random mask to
@@ -954,9 +954,9 @@ Source code for torch.nn.utils.prune
# unstructured) mask
mask = make_mask(t, self.dim, tensor_size, nparams_toprune)
mask *= default_mask.to(dtype=mask.dtype)
- return mask
+ return mask
- @classmethod
+[docs] @classmethod
def apply(cls, module, name, amount, dim=-1):
r"""Adds the forward pre-hook that enables pruning on the fly and
the reparametrization of a tensor in terms of the original tensor
@@ -975,10 +975,10 @@ Source code for torch.nn.utils.prune
"""
return super(RandomStructured, cls).apply(
module, name, amount=amount, dim=dim
- )
+ )
-class LnStructured(BasePruningMethod):
+[docs]class LnStructured(BasePruningMethod):
r"""Prune entire (currently unpruned) channels in a tensor based on their
Ln-norm.
@@ -1002,7 +1002,7 @@ Source code for torch.nn.utils.prune
self.n = n
self.dim = dim
- def compute_mask(self, t, default_mask):
+[docs] def compute_mask(self, t, default_mask):
r"""Computes and returns a mask for the input tensor ``t``.
Starting from a base ``default_mask`` (which should be a mask of ones
if the tensor has not been pruned yet), generate a mask to apply on
@@ -1073,9 +1073,9 @@ Source code for torch.nn.utils.prune
mask = make_mask(t, self.dim, topk.indices)
mask *= default_mask.to(dtype=mask.dtype)
- return mask
+ return mask
- @classmethod
+[docs] @classmethod
def apply(cls, module, name, amount, n, dim):
r"""Adds the forward pre-hook that enables pruning on the fly and
the reparametrization of a tensor in terms of the original tensor
@@ -1096,10 +1096,10 @@ Source code for torch.nn.utils.prune
"""
return super(LnStructured, cls).apply(
module, name, amount=amount, n=n, dim=dim
- )
+ )
-class CustomFromMask(BasePruningMethod):
+[docs]class CustomFromMask(BasePruningMethod):
PRUNING_TYPE = "global"
@@ -1111,7 +1111,7 @@ Source code for torch.nn.utils.prune
mask = default_mask * self.mask.to(dtype=default_mask.dtype)
return mask
- @classmethod
+[docs] @classmethod
def apply(cls, module, name, mask):
r"""Adds the forward pre-hook that enables pruning on the fly and
the reparametrization of a tensor in terms of the original tensor
@@ -1124,10 +1124,10 @@ Source code for torch.nn.utils.prune