noisy_model
Classes:
| Name | Description |
|---|---|
NoisyModel |
Applies a |
NoisyModel
¶
Bases: Module, Generic[ModuleT, NoiseLayerP, NoiseLayerT]
Applies a BaseNoiseLayer to a model input Tensor or a submodule output Tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Callable[NoiseLayerP, NoiseLayerT]
|
The type of |
required |
|
ModuleT
|
The model to apply the |
required |
|
args
|
Positional arguments to |
()
|
|
str | None
|
The name of the |
None
|
|
str | None
|
The name of the |
None
|
|
kwargs
|
Keyword arguments to |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If both |
ValueError
|
If neither |
Methods:
| Name | Description |
|---|---|
distillation_context |
Prepare the base model to facilitate distillation training by applying losses over the transformed and non-transformed |
forward |
Call the |
reset_parameters |
Reinitialize parameters and buffers. |
Attributes:
| Name | Type | Description |
|---|---|---|
target_layer |
Module
|
The |
target_parameter |
str | None
|
The name of the |
target_parameter_index |
int
|
The index of the |
target_layer
property
¶
target_layer: Module
The base_model submodule whose output Tensor to transform.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
target_parameter
property
¶
target_parameter: str | None
The name of the base_model input Tensor argument to transform when target_layer is None.
target_parameter_index
cached
property
¶
target_parameter_index: int
The index of the base_model input Tensor argument to transform when target_layer is None.
distillation_context
¶
Prepare the base model to facilitate distillation training by applying losses over the transformed and non-transformed activations.
Note
This context manager assumes that the output of the base_model is a mutable mapping with a logits key.
Returns:
| Type | Description |
|---|---|
contextlib.ExitStack
|
A context manager that detaches the hooks when exited. |
Added in version v2.6.0.
forward
¶
Call the base_model, applying the noise_layer to the target_parameter or target_layer output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Positional arguments to |
required |
|
Tensor | None
|
An optional mask that selects the elements of the |
None
|
|
Any
|
Keyword arguments to |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The result of |
reset_parameters
¶
Reinitialize parameters and buffers.
This method is useful for initializing tensors created on the meta device.