diff --git a/docs/build/html/.buildinfo b/docs/build/html/.buildinfo index 299fd67..78a50b8 100644 --- a/docs/build/html/.buildinfo +++ b/docs/build/html/.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: e4be416fe1fade80beef75b5aa42bfc9 +config: e005a9a01c1ee86b9ab7af5d4e430bec tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/docs/build/html/_autosummary/_autosummary_binning/netcal.binning.BBQ.html b/docs/build/html/_autosummary/_autosummary_binning/netcal.binning.BBQ.html index 7bc505e..fc3ae89 100644 --- a/docs/build/html/_autosummary/_autosummary_binning/netcal.binning.BBQ.html +++ b/docs/build/html/_autosummary/_autosummary_binning/netcal.binning.BBQ.html @@ -4,7 +4,7 @@
-float
()
Casts all floating point parameters and buffers to float datatype.
Casts all floating point parameters and buffers to float
datatype.
forward
(input)
Forward call.
named_children
()
Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
named_modules
([memo, prefix])
named_modules
([memo, prefix, remove_duplicate])
Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
named_parameters
([prefix, recurse])
register_backward_hook
(hook)
Registers a backward hook on the module.
register_buffer
(name, tensor)
Adds a persistent buffer to the module.
register_buffer
(name, tensor[, persistent])
Adds a buffer to the module.
register_forward_hook
(hook)
Registers a forward hook on the module.
share_memory
()
See torch.Tensor.share_memory_()
state_dict
([destination, prefix, keep_vars])
Returns a dictionary containing a whole state of the module.
type
(dst_type)
Casts all parameters and buffers to dst_type
.
zero_grad
()
zero_grad
([set_to_none])
Sets gradients of all model parameters to zero.
_get_backward_hooks
()¶Returns the backward hooks for use in the call function. +It returns two lists, one with the full backward hooks and one with the non-full +backward hooks.
+_load_from_state_dict
(state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs)¶add_module
(name, module)¶add_module
(name: str, module: Optional[Module]) → None¶
Adds a child module to the current module.
The module can be accessed as an attribute using the given name.
apply
(fn)¶apply
(fn: Callable[Module, None]) → T¶
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 nn-init-doc).
bfloat16
()¶bfloat16
() → T¶
Casts all floating point parameters and buffers to bfloat16
datatype.
Note
+This method modifies the module in-place.
+self
@@ -362,7 +374,7 @@buffers
(recurse=True)¶buffers
(recurse: bool = True) → Iterator[torch.Tensor]¶
Returns an iterator over module buffers.
children
()¶children
() → Iterator[torch.nn.modules.module.Module]¶
Returns an iterator over immediate children modules.
cpu
()¶cpu
() → T¶
Moves all model parameters and buffers to the CPU.
+Note
+This method modifies the module in-place.
+self
@@ -410,11 +426,15 @@cuda
(device=None)¶cuda
(device: Union[int, torch.device, None] = None) → T¶
Moves all model parameters and buffers to the GPU.
This also makes associated parameters and buffers different objects. So it should be called before constructing optimizer if the module will live on GPU while being optimized.
+Note
+This method modifies the module in-place.
+device (int, optional) – if specified, all parameters will be @@ -431,8 +451,12 @@
double
()¶double
() → T¶
Casts all floating point parameters and buffers to double
datatype.
Note
+This method modifies the module in-place.
+self
@@ -445,13 +469,15 @@eval
()¶eval
() → T¶
Sets the module in evaluation mode.
This has any effect only on certain modules. See documentations of
particular modules for details of their behaviors in training/evaluation
mode, if they are affected, e.g. Dropout
, BatchNorm
,
etc.
This is equivalent with self.train(False)
.
See locally-disable-grad-doc for a comparison between +.eval() and several similar mechanisms that may be confused with it.
self
@@ -464,17 +490,21 @@extra_repr
()¶extra_repr
() → str¶
Set the extra representation of the module
-To print customized extra information, you should reimplement +
To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.
float
()¶Casts all floating point parameters and buffers to float datatype.
+float
() → T¶
+Casts all floating point parameters and buffers to float
datatype.
Note
+This method modifies the module in-place.
+self
@@ -491,10 +521,110 @@get_buffer
(target: str) → torch.Tensor¶Returns the buffer given by target
if it exists,
+otherwise throws an error.
See the docstring for get_submodule
for a more detailed
+explanation of this method’s functionality as well as how to
+correctly specify target
.
target – The fully-qualified string name of the buffer
+to look for. (See get_submodule
for how to specify a
+fully-qualified string.)
The buffer referenced by target
torch.Tensor
+AttributeError – If the target string references an invalid + path or resolves to something that is not a + buffer
+get_parameter
(target: str) → torch.nn.parameter.Parameter¶Returns the parameter given by target
if it exists,
+otherwise throws an error.
See the docstring for get_submodule
for a more detailed
+explanation of this method’s functionality as well as how to
+correctly specify target
.
target – The fully-qualified string name of the Parameter
+to look for. (See get_submodule
for how to specify a
+fully-qualified string.)
The Parameter referenced by target
torch.nn.Parameter
+AttributeError – If the target string references an invalid
+ path or resolves to something that is not an
+ nn.Parameter
get_submodule
(target: str) → torch.nn.modules.module.Module¶Returns the submodule given by target
if it exists,
+otherwise throws an error.
For example, let’s say you have an nn.Module
A
that
+looks like this:
(The diagram shows an nn.Module
A
. A
has a nested
+submodule net_b
, which itself has two submodules net_c
+and linear
. net_c
then has a submodule conv
.)
To check whether or not we have the linear
submodule, we
+would call get_submodule("net_b.linear")
. To check whether
+we have the conv
submodule, we would call
+get_submodule("net_b.net_c.conv")
.
The runtime of get_submodule
is bounded by the degree
+of module nesting in target
. A query against
+named_modules
achieves the same result, but it is O(N) in
+the number of transitive modules. So, for a simple check to see
+if some submodule exists, get_submodule
should always be
+used.
target – The fully-qualified string name of the submodule +to look for. (See above example for how to specify a +fully-qualified string.)
+The submodule referenced by target
torch.nn.Module
+AttributeError – If the target string references an invalid
+ path or resolves to something that is not an
+ nn.Module
half
()¶half
() → T¶
Casts all floating point parameters and buffers to half
datatype.
Note
+This method modifies the module in-place.
+self
@@ -507,7 +637,7 @@load_state_dict
(state_dict, strict=True)¶load_state_dict
(state_dict: OrderedDict[str, Tensor], strict: bool = True)¶
Copies parameters and buffers from state_dict
into
this module and its descendants. If strict
is True
, then
the keys of state_dict
must exactly match the keys returned
@@ -537,7 +667,7 @@
modules
()¶modules
() → Iterator[torch.nn.modules.module.Module]¶
Returns an iterator over all modules in the network.
named_buffers
(prefix='', recurse=True)¶named_buffers
(prefix: str = '', recurse: bool = True) → Iterator[Tuple[str, torch.Tensor]]¶
Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
named_children
()¶named_children
() → Iterator[Tuple[str, torch.nn.modules.module.Module]]¶
Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
named_modules
(memo=None, prefix='')¶named_modules
(memo: Optional[Set[Module]] = None, prefix: str = '', remove_duplicate: bool = True)¶
Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
(string, Module) – Tuple of name and module
+memo – a memo to store the set of modules already added to the result
prefix – a prefix that will be added to the name of the module
remove_duplicate – whether to remove the duplicated module instances in the result
not (or) –
(string, Module) – Tuple of name and module
named_parameters
(prefix='', recurse=True)¶named_parameters
(prefix: str = '', recurse: bool = True) → Iterator[Tuple[str, torch.nn.parameter.Parameter]]¶
Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
parameters
(recurse=True)¶parameters
(recurse: bool = True) → Iterator[torch.nn.parameter.Parameter]¶
Returns an iterator over module parameters.
This is typically passed to an optimizer.
register_backward_hook
(hook)¶register_backward_hook
(hook: Callable[[Module, Union[Tuple[torch.Tensor, ...], torch.Tensor], Union[Tuple[torch.Tensor, ...], torch.Tensor]], Union[None, torch.Tensor]]) → torch.utils.hooks.RemovableHandle¶
Registers a backward hook on the module.
-The hook will be called every time the gradients with respect to module -inputs are computed. The hook should have the following signature:
-hook(module, grad_input, grad_output) -> Tensor or None
-
The grad_input
and grad_output
may be tuples if the
-module has multiple inputs or outputs. The hook should not modify its
-arguments, but it can optionally return a new gradient with respect to
-input that will be used in place of grad_input
in subsequent
-computations.
This function is deprecated in favor of nn.Module.register_full_backward_hook()
and
+the behavior of this function will change in future versions.
a handle that can be used to remove the added hook by calling @@ -711,24 +841,20 @@
torch.utils.hooks.RemovableHandle
Warning
-The current implementation will not have the presented behavior
-for complex Module
that perform many operations.
-In some failure cases, grad_input
and grad_output
will only
-contain the gradients for a subset of the inputs and outputs.
-For such Module
, you should use torch.Tensor.register_hook()
-directly on a specific input or output to get the required gradients.
register_buffer
(name, tensor)¶Adds a persistent buffer to the module.
+register_buffer
(name: str, tensor: Optional[torch.Tensor], persistent: bool = True) → None¶
+Adds a buffer to the module.
This is typically used to register a buffer that should not to be
considered a model parameter. For example, BatchNorm’s running_mean
-is not a parameter, but is part of the persistent state.
persistent
to False
. The
+only difference between a persistent buffer and a non-persistent buffer
+is that the latter will not be a part of this module’s
+state_dict
.
Buffers can be accessed as attributes using given names.
state_dict
.
register_forward_hook
(hook)¶register_forward_hook
(hook: Callable[..., None]) → torch.utils.hooks.RemovableHandle¶
Registers a forward hook on the module.
The hook will be called every time after forward()
has computed an output.
It should have the following signature:
hook(module, input, output) -> None or modified output
The hook can modify the output. It can modify the input inplace but +
The input contains only the positional arguments given to the module.
+Keyword arguments won’t be passed to the hooks and only to the forward
.
+The hook can modify the output. It can modify the input inplace but
it will not have effect on forward since this is called after
forward()
is called.
register_forward_pre_hook
(hook)¶register_forward_pre_hook
(hook: Callable[..., None]) → torch.utils.hooks.RemovableHandle¶
Registers a forward pre-hook on the module.
The hook will be called every time before forward()
is invoked.
It should have the following signature:
hook(module, input) -> None or modified input
The hook can modify the input. User can either return a tuple or a +
The input contains only the positional arguments given to the module.
+Keyword arguments won’t be passed to the hooks and only to the forward
.
+The hook can modify the input. User can either return a tuple or a
single modified value in the hook. We will wrap the value into a tuple
if a single value is returned(unless that value is already a tuple).
register_full_backward_hook
(hook: Callable[[Module, Union[Tuple[torch.Tensor, ...], torch.Tensor], Union[Tuple[torch.Tensor, ...], torch.Tensor]], Union[None, torch.Tensor]]) → torch.utils.hooks.RemovableHandle¶Registers a backward hook on the module.
+The hook will be called every time the gradients with respect to module +inputs are computed. The hook should have the following signature:
+hook(module, grad_input, grad_output) -> tuple(Tensor) or None
+
The grad_input
and grad_output
are tuples that contain the gradients
+with respect to the inputs and outputs respectively. The hook should
+not modify its arguments, but it can optionally return a new gradient with
+respect to the input that will be used in place of grad_input
in
+subsequent computations. grad_input
will only correspond to the inputs given
+as positional arguments and all kwarg arguments are ignored. Entries
+in grad_input
and grad_output
will be None
for all non-Tensor
+arguments.
Warning
+Modifying inputs or outputs inplace is not allowed when using backward hooks and +will raise an error.
+a handle that can be used to remove the added hook by calling
+handle.remove()
torch.utils.hooks.RemovableHandle
register_parameter
(name, param)¶register_parameter
(name: str, param: Optional[torch.nn.parameter.Parameter]) → None¶
Adds a parameter to the module.
The parameter can be accessed as an attribute using given name.
requires_grad_
(requires_grad=True)¶requires_grad_
(requires_grad: bool = True) → T¶
Change if autograd should record operations on parameters in this module.
This method sets the parameters’ requires_grad
attributes
in-place.
This method is helpful for freezing part of the module for finetuning or training parts of a model individually (e.g., GAN training).
+See locally-disable-grad-doc for a comparison between +.requires_grad_() and several similar mechanisms that may be confused with it.
requires_grad (bool) – whether autograd should record operations on @@ -830,6 +997,12 @@
See torch.Tensor.share_memory_()
state_dict
(destination=None, prefix='', keep_vars=False)¶dtype
s. In addition, this method will
-only cast the floating point parameters and buffers to dtype
+floating point or complex dtype`s. In addition, this method will
+only cast the floating point or complex parameters and buffers to :attr:`dtype
(if given). The integral parameters and buffers will be moved
device
, if that is given, but with dtypes unchanged. When
non_blocking
is set, it tries to convert/move asynchronously
@@ -894,8 +1067,8 @@ device (torch.device
) – the desired device of the parameters
and buffers in this module
dtype (torch.dtype
) – the desired floating point type of
-the floating point parameters and buffers in this module
dtype (torch.dtype
) – the desired floating point or complex dtype of
+the parameters and buffers in this module
tensor (torch.Tensor) – Tensor whose dtype and device are the desired dtype and device for all parameters and buffers in this module
memory_format (torch.memory_format
) – the desired memory
@@ -910,7 +1083,7 @@
Module
Example:
+Examples:
>>> linear = nn.Linear(2, 2)
>>> linear.weight
Parameter containing:
@@ -936,13 +1109,41 @@ netcal.regularization.ConfidencePenaltyParameter containing:
tensor([[ 0.1914, -0.3420],
[-0.5112, -0.2324]], dtype=torch.float16)
+
+>>> linear = nn.Linear(2, 2, bias=None).to(torch.cdouble)
+>>> linear.weight
+Parameter containing:
+tensor([[ 0.3741+0.j, 0.2382+0.j],
+ [ 0.5593+0.j, -0.4443+0.j]], dtype=torch.complex128)
+>>> linear(torch.ones(3, 2, dtype=torch.cdouble))
+tensor([[0.6122+0.j, 0.1150+0.j],
+ [0.6122+0.j, 0.1150+0.j],
+ [0.6122+0.j, 0.1150+0.j]], dtype=torch.complex128)
to_empty
(*, device: Union[str, torch.device]) → T¶Moves the parameters and buffers to the specified device without copying storage.
+device (torch.device
) – The desired device of the parameters
+and buffers in this module.
self
+Module
+train
(mode=True)¶train
(mode: bool = True) → T¶
Sets the module in training mode.
This has any effect only on certain modules. See documentations of particular modules for details of their behaviors in training/evaluation @@ -964,8 +1165,12 @@
type
(dst_type)¶type
(dst_type: Union[torch.dtype, str]) → T¶
Casts all parameters and buffers to dst_type
.
Note
+This method modifies the module in-place.
+dst_type (type or string) – the desired type
@@ -979,10 +1184,42 @@xpu
(device: Union[int, torch.device, None] = None) → T¶Moves all model parameters and buffers to the XPU.
+This also makes associated parameters and buffers different objects. So +it should be called before constructing optimizer if the module will +live on XPU while being optimized.
+Note
+This method modifies the module in-place.
+device (int, optional) – if specified, all parameters will be +copied to that device
+self
+Module
+zero_grad
()¶Sets gradients of all model parameters to zero.
+zero_grad
(set_to_none: bool = False) → None¶
+Sets gradients of all model parameters to zero. See similar function
+under torch.optim.Optimizer
for more context.
set_to_none (bool) – instead of setting to zero, set the grads to None.
+See torch.optim.Optimizer.zero_grad()
for details.
float
()
Casts all floating point parameters and buffers to float datatype.
Casts all floating point parameters and buffers to float
datatype.
forward
(input, target)
Forward call of module.
named_children
()
Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
named_modules
([memo, prefix])
named_modules
([memo, prefix, remove_duplicate])
Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
named_parameters
([prefix, recurse])
register_backward_hook
(hook)
Registers a backward hook on the module.
register_buffer
(name, tensor)
Adds a persistent buffer to the module.
register_buffer
(name, tensor[, persistent])
Adds a buffer to the module.
register_forward_hook
(hook)
Registers a forward hook on the module.
share_memory
()
See torch.Tensor.share_memory_()
state_dict
([destination, prefix, keep_vars])
Returns a dictionary containing a whole state of the module.
type
(dst_type)
Casts all parameters and buffers to dst_type
.
zero_grad
()
zero_grad
([set_to_none])
Sets gradients of all model parameters to zero.
_get_backward_hooks
()¶Returns the backward hooks for use in the call function. +It returns two lists, one with the full backward hooks and one with the non-full +backward hooks.
+_load_from_state_dict
(state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs)¶add_module
(name, module)¶add_module
(name: str, module: Optional[Module]) → None¶
Adds a child module to the current module.
The module can be accessed as an attribute using the given name.
apply
(fn)¶apply
(fn: Callable[Module, None]) → T¶
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 nn-init-doc).
bfloat16
()¶bfloat16
() → T¶
Casts all floating point parameters and buffers to bfloat16
datatype.
Note
+This method modifies the module in-place.
+self
@@ -354,7 +366,7 @@buffers
(recurse=True)¶buffers
(recurse: bool = True) → Iterator[torch.Tensor]¶
Returns an iterator over module buffers.
children
()¶children
() → Iterator[torch.nn.modules.module.Module]¶
Returns an iterator over immediate children modules.
cpu
()¶cpu
() → T¶
Moves all model parameters and buffers to the CPU.
+Note
+This method modifies the module in-place.
+self
@@ -402,11 +418,15 @@cuda
(device=None)¶cuda
(device: Union[int, torch.device, None] = None) → T¶
Moves all model parameters and buffers to the GPU.
This also makes associated parameters and buffers different objects. So it should be called before constructing optimizer if the module will live on GPU while being optimized.
+Note
+This method modifies the module in-place.
+device (int, optional) – if specified, all parameters will be @@ -423,8 +443,12 @@
double
()¶double
() → T¶
Casts all floating point parameters and buffers to double
datatype.
Note
+This method modifies the module in-place.
+self
@@ -437,13 +461,15 @@eval
()¶eval
() → T¶
Sets the module in evaluation mode.
This has any effect only on certain modules. See documentations of
particular modules for details of their behaviors in training/evaluation
mode, if they are affected, e.g. Dropout
, BatchNorm
,
etc.
This is equivalent with self.train(False)
.
See locally-disable-grad-doc for a comparison between +.eval() and several similar mechanisms that may be confused with it.
self
@@ -456,17 +482,21 @@extra_repr
()¶extra_repr
() → str¶
Set the extra representation of the module
-To print customized extra information, you should reimplement +
To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.
float
()¶Casts all floating point parameters and buffers to float datatype.
+float
() → T¶
+Casts all floating point parameters and buffers to float
datatype.
Note
+This method modifies the module in-place.
+self
@@ -483,10 +513,110 @@get_buffer
(target: str) → torch.Tensor¶Returns the buffer given by target
if it exists,
+otherwise throws an error.
See the docstring for get_submodule
for a more detailed
+explanation of this method’s functionality as well as how to
+correctly specify target
.
target – The fully-qualified string name of the buffer
+to look for. (See get_submodule
for how to specify a
+fully-qualified string.)
The buffer referenced by target
torch.Tensor
+AttributeError – If the target string references an invalid + path or resolves to something that is not a + buffer
+get_parameter
(target: str) → torch.nn.parameter.Parameter¶Returns the parameter given by target
if it exists,
+otherwise throws an error.
See the docstring for get_submodule
for a more detailed
+explanation of this method’s functionality as well as how to
+correctly specify target
.
target – The fully-qualified string name of the Parameter
+to look for. (See get_submodule
for how to specify a
+fully-qualified string.)
The Parameter referenced by target
torch.nn.Parameter
+AttributeError – If the target string references an invalid
+ path or resolves to something that is not an
+ nn.Parameter
get_submodule
(target: str) → torch.nn.modules.module.Module¶Returns the submodule given by target
if it exists,
+otherwise throws an error.
For example, let’s say you have an nn.Module
A
that
+looks like this:
(The diagram shows an nn.Module
A
. A
has a nested
+submodule net_b
, which itself has two submodules net_c
+and linear
. net_c
then has a submodule conv
.)
To check whether or not we have the linear
submodule, we
+would call get_submodule("net_b.linear")
. To check whether
+we have the conv
submodule, we would call
+get_submodule("net_b.net_c.conv")
.
The runtime of get_submodule
is bounded by the degree
+of module nesting in target
. A query against
+named_modules
achieves the same result, but it is O(N) in
+the number of transitive modules. So, for a simple check to see
+if some submodule exists, get_submodule
should always be
+used.
target – The fully-qualified string name of the submodule +to look for. (See above example for how to specify a +fully-qualified string.)
+The submodule referenced by target
torch.nn.Module
+AttributeError – If the target string references an invalid
+ path or resolves to something that is not an
+ nn.Module
half
()¶half
() → T¶
Casts all floating point parameters and buffers to half
datatype.
Note
+This method modifies the module in-place.
+self
@@ -499,7 +629,7 @@load_state_dict
(state_dict, strict=True)¶load_state_dict
(state_dict: OrderedDict[str, Tensor], strict: bool = True)¶
Copies parameters and buffers from state_dict
into
this module and its descendants. If strict
is True
, then
the keys of state_dict
must exactly match the keys returned
@@ -529,7 +659,7 @@
modules
()¶modules
() → Iterator[torch.nn.modules.module.Module]¶
Returns an iterator over all modules in the network.
named_buffers
(prefix='', recurse=True)¶named_buffers
(prefix: str = '', recurse: bool = True) → Iterator[Tuple[str, torch.Tensor]]¶
Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
named_children
()¶named_children
() → Iterator[Tuple[str, torch.nn.modules.module.Module]]¶
Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
named_modules
(memo=None, prefix='')¶named_modules
(memo: Optional[Set[Module]] = None, prefix: str = '', remove_duplicate: bool = True)¶
Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
(string, Module) – Tuple of name and module
+memo – a memo to store the set of modules already added to the result
prefix – a prefix that will be added to the name of the module
remove_duplicate – whether to remove the duplicated module instances in the result
not (or) –
(string, Module) – Tuple of name and module
named_parameters
(prefix='', recurse=True)¶named_parameters
(prefix: str = '', recurse: bool = True) → Iterator[Tuple[str, torch.nn.parameter.Parameter]]¶
Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
parameters
(recurse=True)¶parameters
(recurse: bool = True) → Iterator[torch.nn.parameter.Parameter]¶
Returns an iterator over module parameters.
This is typically passed to an optimizer.
register_backward_hook
(hook)¶register_backward_hook
(hook: Callable[[Module, Union[Tuple[torch.Tensor, ...], torch.Tensor], Union[Tuple[torch.Tensor, ...], torch.Tensor]], Union[None, torch.Tensor]]) → torch.utils.hooks.RemovableHandle¶
Registers a backward hook on the module.
-The hook will be called every time the gradients with respect to module -inputs are computed. The hook should have the following signature:
-hook(module, grad_input, grad_output) -> Tensor or None
-
The grad_input
and grad_output
may be tuples if the
-module has multiple inputs or outputs. The hook should not modify its
-arguments, but it can optionally return a new gradient with respect to
-input that will be used in place of grad_input
in subsequent
-computations.
This function is deprecated in favor of nn.Module.register_full_backward_hook()
and
+the behavior of this function will change in future versions.
a handle that can be used to remove the added hook by calling @@ -703,24 +833,20 @@
torch.utils.hooks.RemovableHandle
Warning
-The current implementation will not have the presented behavior
-for complex Module
that perform many operations.
-In some failure cases, grad_input
and grad_output
will only
-contain the gradients for a subset of the inputs and outputs.
-For such Module
, you should use torch.Tensor.register_hook()
-directly on a specific input or output to get the required gradients.
register_buffer
(name, tensor)¶Adds a persistent buffer to the module.
+register_buffer
(name: str, tensor: Optional[torch.Tensor], persistent: bool = True) → None¶
+Adds a buffer to the module.
This is typically used to register a buffer that should not to be
considered a model parameter. For example, BatchNorm’s running_mean
-is not a parameter, but is part of the persistent state.
persistent
to False
. The
+only difference between a persistent buffer and a non-persistent buffer
+is that the latter will not be a part of this module’s
+state_dict
.
Buffers can be accessed as attributes using given names.
state_dict
.
register_forward_hook
(hook)¶register_forward_hook
(hook: Callable[..., None]) → torch.utils.hooks.RemovableHandle¶
Registers a forward hook on the module.
The hook will be called every time after forward()
has computed an output.
It should have the following signature:
hook(module, input, output) -> None or modified output
The hook can modify the output. It can modify the input inplace but +
The input contains only the positional arguments given to the module.
+Keyword arguments won’t be passed to the hooks and only to the forward
.
+The hook can modify the output. It can modify the input inplace but
it will not have effect on forward since this is called after
forward()
is called.
register_forward_pre_hook
(hook)¶register_forward_pre_hook
(hook: Callable[..., None]) → torch.utils.hooks.RemovableHandle¶
Registers a forward pre-hook on the module.
The hook will be called every time before forward()
is invoked.
It should have the following signature:
hook(module, input) -> None or modified input
The hook can modify the input. User can either return a tuple or a +
The input contains only the positional arguments given to the module.
+Keyword arguments won’t be passed to the hooks and only to the forward
.
+The hook can modify the input. User can either return a tuple or a
single modified value in the hook. We will wrap the value into a tuple
if a single value is returned(unless that value is already a tuple).
register_full_backward_hook
(hook: Callable[[Module, Union[Tuple[torch.Tensor, ...], torch.Tensor], Union[Tuple[torch.Tensor, ...], torch.Tensor]], Union[None, torch.Tensor]]) → torch.utils.hooks.RemovableHandle¶Registers a backward hook on the module.
+The hook will be called every time the gradients with respect to module +inputs are computed. The hook should have the following signature:
+hook(module, grad_input, grad_output) -> tuple(Tensor) or None
+
The grad_input
and grad_output
are tuples that contain the gradients
+with respect to the inputs and outputs respectively. The hook should
+not modify its arguments, but it can optionally return a new gradient with
+respect to the input that will be used in place of grad_input
in
+subsequent computations. grad_input
will only correspond to the inputs given
+as positional arguments and all kwarg arguments are ignored. Entries
+in grad_input
and grad_output
will be None
for all non-Tensor
+arguments.
Warning
+Modifying inputs or outputs inplace is not allowed when using backward hooks and +will raise an error.
+a handle that can be used to remove the added hook by calling
+handle.remove()
torch.utils.hooks.RemovableHandle
register_parameter
(name, param)¶register_parameter
(name: str, param: Optional[torch.nn.parameter.Parameter]) → None¶
Adds a parameter to the module.
The parameter can be accessed as an attribute using given name.
requires_grad_
(requires_grad=True)¶requires_grad_
(requires_grad: bool = True) → T¶
Change if autograd should record operations on parameters in this module.
This method sets the parameters’ requires_grad
attributes
in-place.
This method is helpful for freezing part of the module for finetuning or training parts of a model individually (e.g., GAN training).
+See locally-disable-grad-doc for a comparison between +.requires_grad_() and several similar mechanisms that may be confused with it.
requires_grad (bool) – whether autograd should record operations on @@ -822,6 +989,12 @@
See torch.Tensor.share_memory_()
state_dict
(destination=None, prefix='', keep_vars=False)¶dtype
s. In addition, this method will
-only cast the floating point parameters and buffers to dtype
+floating point or complex dtype`s. In addition, this method will
+only cast the floating point or complex parameters and buffers to :attr:`dtype
(if given). The integral parameters and buffers will be moved
device
, if that is given, but with dtypes unchanged. When
non_blocking
is set, it tries to convert/move asynchronously
@@ -886,8 +1059,8 @@ device (torch.device
) – the desired device of the parameters
and buffers in this module
dtype (torch.dtype
) – the desired floating point type of
-the floating point parameters and buffers in this module
dtype (torch.dtype
) – the desired floating point or complex dtype of
+the parameters and buffers in this module
tensor (torch.Tensor) – Tensor whose dtype and device are the desired dtype and device for all parameters and buffers in this module
memory_format (torch.memory_format
) – the desired memory
@@ -902,7 +1075,7 @@
Module
Example:
+Examples:
>>> linear = nn.Linear(2, 2)
>>> linear.weight
Parameter containing:
@@ -928,13 +1101,41 @@ netcal.regularization.DCAPenaltyParameter containing:
tensor([[ 0.1914, -0.3420],
[-0.5112, -0.2324]], dtype=torch.float16)
+
+>>> linear = nn.Linear(2, 2, bias=None).to(torch.cdouble)
+>>> linear.weight
+Parameter containing:
+tensor([[ 0.3741+0.j, 0.2382+0.j],
+ [ 0.5593+0.j, -0.4443+0.j]], dtype=torch.complex128)
+>>> linear(torch.ones(3, 2, dtype=torch.cdouble))
+tensor([[0.6122+0.j, 0.1150+0.j],
+ [0.6122+0.j, 0.1150+0.j],
+ [0.6122+0.j, 0.1150+0.j]], dtype=torch.complex128)
to_empty
(*, device: Union[str, torch.device]) → T¶Moves the parameters and buffers to the specified device without copying storage.
+device (torch.device
) – The desired device of the parameters
+and buffers in this module.
self
+Module
+train
(mode=True)¶train
(mode: bool = True) → T¶
Sets the module in training mode.
This has any effect only on certain modules. See documentations of particular modules for details of their behaviors in training/evaluation @@ -956,8 +1157,12 @@
type
(dst_type)¶type
(dst_type: Union[torch.dtype, str]) → T¶
Casts all parameters and buffers to dst_type
.
Note
+This method modifies the module in-place.
+dst_type (type or string) – the desired type
@@ -971,10 +1176,42 @@xpu
(device: Union[int, torch.device, None] = None) → T¶Moves all model parameters and buffers to the XPU.
+This also makes associated parameters and buffers different objects. So +it should be called before constructing optimizer if the module will +live on XPU while being optimized.
+Note
+This method modifies the module in-place.
+device (int, optional) – if specified, all parameters will be +copied to that device
+self
+Module
+zero_grad
()¶Sets gradients of all model parameters to zero.
+zero_grad
(set_to_none: bool = False) → None¶
+Sets gradients of all model parameters to zero. See similar function
+under torch.optim.Optimizer
for more context.
set_to_none (bool) – instead of setting to zero, set the grads to None.
+See torch.optim.Optimizer.zero_grad()
for details.
float
()
Casts all floating point parameters and buffers to float datatype.
Casts all floating point parameters and buffers to float
datatype.
forward
(input, target)
Forward call of module.
named_children
()
Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
named_modules
([memo, prefix])
named_modules
([memo, prefix, remove_duplicate])
Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
named_parameters
([prefix, recurse])
register_backward_hook
(hook)
Registers a backward hook on the module.
register_buffer
(name, tensor)
Adds a persistent buffer to the module.
register_buffer
(name, tensor[, persistent])
Adds a buffer to the module.
register_forward_hook
(hook)
Registers a forward hook on the module.
share_memory
()
See torch.Tensor.share_memory_()
state_dict
([destination, prefix, keep_vars])
Returns a dictionary containing a whole state of the module.
type
(dst_type)
Casts all parameters and buffers to dst_type
.
zero_grad
()
zero_grad
([set_to_none])
Sets gradients of all model parameters to zero.
_get_backward_hooks
()¶Returns the backward hooks for use in the call function. +It returns two lists, one with the full backward hooks and one with the non-full +backward hooks.
+_load_from_state_dict
(state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs)¶add_module
(name, module)¶add_module
(name: str, module: Optional[Module]) → None¶
Adds a child module to the current module.
The module can be accessed as an attribute using the given name.
apply
(fn)¶apply
(fn: Callable[Module, None]) → T¶
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 nn-init-doc).
bfloat16
()¶bfloat16
() → T¶
Casts all floating point parameters and buffers to bfloat16
datatype.
Note
+This method modifies the module in-place.
+self
@@ -361,7 +373,7 @@buffers
(recurse=True)¶buffers
(recurse: bool = True) → Iterator[torch.Tensor]¶
Returns an iterator over module buffers.
children
()¶children
() → Iterator[torch.nn.modules.module.Module]¶
Returns an iterator over immediate children modules.
cpu
()¶cpu
() → T¶
Moves all model parameters and buffers to the CPU.
+Note
+This method modifies the module in-place.
+self
@@ -409,11 +425,15 @@cuda
(device=None)¶cuda
(device: Union[int, torch.device, None] = None) → T¶
Moves all model parameters and buffers to the GPU.
This also makes associated parameters and buffers different objects. So it should be called before constructing optimizer if the module will live on GPU while being optimized.
+Note
+This method modifies the module in-place.
+device (int, optional) – if specified, all parameters will be @@ -430,8 +450,12 @@
double
()¶double
() → T¶
Casts all floating point parameters and buffers to double
datatype.
Note
+This method modifies the module in-place.
+self
@@ -444,13 +468,15 @@eval
()¶eval
() → T¶
Sets the module in evaluation mode.
This has any effect only on certain modules. See documentations of
particular modules for details of their behaviors in training/evaluation
mode, if they are affected, e.g. Dropout
, BatchNorm
,
etc.
This is equivalent with self.train(False)
.
See locally-disable-grad-doc for a comparison between +.eval() and several similar mechanisms that may be confused with it.
self
@@ -463,17 +489,21 @@extra_repr
()¶extra_repr
() → str¶
Set the extra representation of the module
-To print customized extra information, you should reimplement +
To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.
float
()¶Casts all floating point parameters and buffers to float datatype.
+float
() → T¶
+Casts all floating point parameters and buffers to float
datatype.
Note
+This method modifies the module in-place.
+self
@@ -490,10 +520,110 @@get_buffer
(target: str) → torch.Tensor¶Returns the buffer given by target
if it exists,
+otherwise throws an error.
See the docstring for get_submodule
for a more detailed
+explanation of this method’s functionality as well as how to
+correctly specify target
.
target – The fully-qualified string name of the buffer
+to look for. (See get_submodule
for how to specify a
+fully-qualified string.)
The buffer referenced by target
torch.Tensor
+AttributeError – If the target string references an invalid + path or resolves to something that is not a + buffer
+get_parameter
(target: str) → torch.nn.parameter.Parameter¶Returns the parameter given by target
if it exists,
+otherwise throws an error.
See the docstring for get_submodule
for a more detailed
+explanation of this method’s functionality as well as how to
+correctly specify target
.
target – The fully-qualified string name of the Parameter
+to look for. (See get_submodule
for how to specify a
+fully-qualified string.)
The Parameter referenced by target
torch.nn.Parameter
+AttributeError – If the target string references an invalid
+ path or resolves to something that is not an
+ nn.Parameter
get_submodule
(target: str) → torch.nn.modules.module.Module¶Returns the submodule given by target
if it exists,
+otherwise throws an error.
For example, let’s say you have an nn.Module
A
that
+looks like this:
(The diagram shows an nn.Module
A
. A
has a nested
+submodule net_b
, which itself has two submodules net_c
+and linear
. net_c
then has a submodule conv
.)
To check whether or not we have the linear
submodule, we
+would call get_submodule("net_b.linear")
. To check whether
+we have the conv
submodule, we would call
+get_submodule("net_b.net_c.conv")
.
The runtime of get_submodule
is bounded by the degree
+of module nesting in target
. A query against
+named_modules
achieves the same result, but it is O(N) in
+the number of transitive modules. So, for a simple check to see
+if some submodule exists, get_submodule
should always be
+used.
target – The fully-qualified string name of the submodule +to look for. (See above example for how to specify a +fully-qualified string.)
+The submodule referenced by target
torch.nn.Module
+AttributeError – If the target string references an invalid
+ path or resolves to something that is not an
+ nn.Module
half
()¶half
() → T¶
Casts all floating point parameters and buffers to half
datatype.
Note
+This method modifies the module in-place.
+self
@@ -512,7 +642,7 @@load_state_dict
(state_dict, strict=True)¶load_state_dict
(state_dict: OrderedDict[str, Tensor], strict: bool = True)¶
Copies parameters and buffers from state_dict
into
this module and its descendants. If strict
is True
, then
the keys of state_dict
must exactly match the keys returned
@@ -542,7 +672,7 @@
modules
()¶modules
() → Iterator[torch.nn.modules.module.Module]¶
Returns an iterator over all modules in the network.
named_buffers
(prefix='', recurse=True)¶named_buffers
(prefix: str = '', recurse: bool = True) → Iterator[Tuple[str, torch.Tensor]]¶
Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
named_children
()¶named_children
() → Iterator[Tuple[str, torch.nn.modules.module.Module]]¶
Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
named_modules
(memo=None, prefix='')¶named_modules
(memo: Optional[Set[Module]] = None, prefix: str = '', remove_duplicate: bool = True)¶
Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
(string, Module) – Tuple of name and module
+memo – a memo to store the set of modules already added to the result
prefix – a prefix that will be added to the name of the module
remove_duplicate – whether to remove the duplicated module instances in the result
not (or) –
(string, Module) – Tuple of name and module
named_parameters
(prefix='', recurse=True)¶named_parameters
(prefix: str = '', recurse: bool = True) → Iterator[Tuple[str, torch.nn.parameter.Parameter]]¶
Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
parameters
(recurse=True)¶parameters
(recurse: bool = True) → Iterator[torch.nn.parameter.Parameter]¶
Returns an iterator over module parameters.
This is typically passed to an optimizer.
register_backward_hook
(hook)¶register_backward_hook
(hook: Callable[[Module, Union[Tuple[torch.Tensor, ...], torch.Tensor], Union[Tuple[torch.Tensor, ...], torch.Tensor]], Union[None, torch.Tensor]]) → torch.utils.hooks.RemovableHandle¶
Registers a backward hook on the module.
-The hook will be called every time the gradients with respect to module -inputs are computed. The hook should have the following signature:
-hook(module, grad_input, grad_output) -> Tensor or None
-
The grad_input
and grad_output
may be tuples if the
-module has multiple inputs or outputs. The hook should not modify its
-arguments, but it can optionally return a new gradient with respect to
-input that will be used in place of grad_input
in subsequent
-computations.
This function is deprecated in favor of nn.Module.register_full_backward_hook()
and
+the behavior of this function will change in future versions.
a handle that can be used to remove the added hook by calling @@ -716,24 +846,20 @@
torch.utils.hooks.RemovableHandle
Warning
-The current implementation will not have the presented behavior
-for complex Module
that perform many operations.
-In some failure cases, grad_input
and grad_output
will only
-contain the gradients for a subset of the inputs and outputs.
-For such Module
, you should use torch.Tensor.register_hook()
-directly on a specific input or output to get the required gradients.
register_buffer
(name, tensor)¶Adds a persistent buffer to the module.
+register_buffer
(name: str, tensor: Optional[torch.Tensor], persistent: bool = True) → None¶
+Adds a buffer to the module.
This is typically used to register a buffer that should not to be
considered a model parameter. For example, BatchNorm’s running_mean
-is not a parameter, but is part of the persistent state.
persistent
to False
. The
+only difference between a persistent buffer and a non-persistent buffer
+is that the latter will not be a part of this module’s
+state_dict
.
Buffers can be accessed as attributes using given names.
state_dict
.
register_forward_hook
(hook)¶register_forward_hook
(hook: Callable[..., None]) → torch.utils.hooks.RemovableHandle¶
Registers a forward hook on the module.
The hook will be called every time after forward()
has computed an output.
It should have the following signature:
hook(module, input, output) -> None or modified output
The hook can modify the output. It can modify the input inplace but +
The input contains only the positional arguments given to the module.
+Keyword arguments won’t be passed to the hooks and only to the forward
.
+The hook can modify the output. It can modify the input inplace but
it will not have effect on forward since this is called after
forward()
is called.
register_forward_pre_hook
(hook)¶register_forward_pre_hook
(hook: Callable[..., None]) → torch.utils.hooks.RemovableHandle¶
Registers a forward pre-hook on the module.
The hook will be called every time before forward()
is invoked.
It should have the following signature:
hook(module, input) -> None or modified input
The hook can modify the input. User can either return a tuple or a +
The input contains only the positional arguments given to the module.
+Keyword arguments won’t be passed to the hooks and only to the forward
.
+The hook can modify the input. User can either return a tuple or a
single modified value in the hook. We will wrap the value into a tuple
if a single value is returned(unless that value is already a tuple).
register_full_backward_hook
(hook: Callable[[Module, Union[Tuple[torch.Tensor, ...], torch.Tensor], Union[Tuple[torch.Tensor, ...], torch.Tensor]], Union[None, torch.Tensor]]) → torch.utils.hooks.RemovableHandle¶Registers a backward hook on the module.
+The hook will be called every time the gradients with respect to module +inputs are computed. The hook should have the following signature:
+hook(module, grad_input, grad_output) -> tuple(Tensor) or None
+
The grad_input
and grad_output
are tuples that contain the gradients
+with respect to the inputs and outputs respectively. The hook should
+not modify its arguments, but it can optionally return a new gradient with
+respect to the input that will be used in place of grad_input
in
+subsequent computations. grad_input
will only correspond to the inputs given
+as positional arguments and all kwarg arguments are ignored. Entries
+in grad_input
and grad_output
will be None
for all non-Tensor
+arguments.
Warning
+Modifying inputs or outputs inplace is not allowed when using backward hooks and +will raise an error.
+a handle that can be used to remove the added hook by calling
+handle.remove()
torch.utils.hooks.RemovableHandle
register_parameter
(name, param)¶register_parameter
(name: str, param: Optional[torch.nn.parameter.Parameter]) → None¶
Adds a parameter to the module.
The parameter can be accessed as an attribute using given name.
requires_grad_
(requires_grad=True)¶requires_grad_
(requires_grad: bool = True) → T¶
Change if autograd should record operations on parameters in this module.
This method sets the parameters’ requires_grad
attributes
in-place.
This method is helpful for freezing part of the module for finetuning or training parts of a model individually (e.g., GAN training).
+See locally-disable-grad-doc for a comparison between +.requires_grad_() and several similar mechanisms that may be confused with it.
requires_grad (bool) – whether autograd should record operations on @@ -835,6 +1002,12 @@
See torch.Tensor.share_memory_()
state_dict
(destination=None, prefix='', keep_vars=False)¶dtype
s. In addition, this method will
-only cast the floating point parameters and buffers to dtype
+floating point or complex dtype`s. In addition, this method will
+only cast the floating point or complex parameters and buffers to :attr:`dtype
(if given). The integral parameters and buffers will be moved
device
, if that is given, but with dtypes unchanged. When
non_blocking
is set, it tries to convert/move asynchronously
@@ -899,8 +1072,8 @@ device (torch.device
) – the desired device of the parameters
and buffers in this module
dtype (torch.dtype
) – the desired floating point type of
-the floating point parameters and buffers in this module
dtype (torch.dtype
) – the desired floating point or complex dtype of
+the parameters and buffers in this module
tensor (torch.Tensor) – Tensor whose dtype and device are the desired dtype and device for all parameters and buffers in this module
memory_format (torch.memory_format
) – the desired memory
@@ -915,7 +1088,7 @@
Module
Example:
+Examples:
>>> linear = nn.Linear(2, 2)
>>> linear.weight
Parameter containing:
@@ -941,13 +1114,41 @@ netcal.regularization.MMCEPenaltyParameter containing:
tensor([[ 0.1914, -0.3420],
[-0.5112, -0.2324]], dtype=torch.float16)
+
+>>> linear = nn.Linear(2, 2, bias=None).to(torch.cdouble)
+>>> linear.weight
+Parameter containing:
+tensor([[ 0.3741+0.j, 0.2382+0.j],
+ [ 0.5593+0.j, -0.4443+0.j]], dtype=torch.complex128)
+>>> linear(torch.ones(3, 2, dtype=torch.cdouble))
+tensor([[0.6122+0.j, 0.1150+0.j],
+ [0.6122+0.j, 0.1150+0.j],
+ [0.6122+0.j, 0.1150+0.j]], dtype=torch.complex128)
to_empty
(*, device: Union[str, torch.device]) → T¶Moves the parameters and buffers to the specified device without copying storage.
+device (torch.device
) – The desired device of the parameters
+and buffers in this module.
self
+Module
+train
(mode=True)¶train
(mode: bool = True) → T¶
Sets the module in training mode.
This has any effect only on certain modules. See documentations of particular modules for details of their behaviors in training/evaluation @@ -969,8 +1170,12 @@
type
(dst_type)¶type
(dst_type: Union[torch.dtype, str]) → T¶
Casts all parameters and buffers to dst_type
.
Note
+This method modifies the module in-place.
+dst_type (type or string) – the desired type
@@ -984,10 +1189,42 @@xpu
(device: Union[int, torch.device, None] = None) → T¶Moves all model parameters and buffers to the XPU.
+This also makes associated parameters and buffers different objects. So +it should be called before constructing optimizer if the module will +live on XPU while being optimized.
+Note
+This method modifies the module in-place.
+device (int, optional) – if specified, all parameters will be +copied to that device
+self
+Module
+zero_grad
()¶Sets gradients of all model parameters to zero.
+zero_grad
(set_to_none: bool = False) → None¶
+Sets gradients of all model parameters to zero. See similar function
+under torch.optim.Optimizer
for more context.
set_to_none (bool) – instead of setting to zero, set the grads to None.
+See torch.optim.Optimizer.zero_grad()
for details.
+ |
NavigationNavigationNavigationNavigation |