layer_adaptation
¶
Functions:
Name | Description |
---|---|
expand_weights |
Expands |
get_expansion_instructions |
Returns a dictionary containing information on how |
get_in_out_axes |
Returns a dictionary containing information on how a |
expand_weights
¶
expand_weights(
weights: Tensor,
axis: int,
n_dims_to_add: int,
init_fn: Callable,
n_subparams: int = 1,
)
Expands weights
along the given axis by n_dims_to_add
.
The expanded weights are created by evenly splitting the
original weights into its subparams and appending new weights
to them.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
weights
|
Tensor
|
Parameter to be expanded. |
required |
axis
|
int
|
Axis along which to expand the parameter. |
required |
n_dims_to_add
|
int
|
Number of dims to add to each sub-parameter within the parameter. |
required |
init_fn
|
Callable
|
Function to initiate the new weights with. |
required |
n_subparams
|
int
|
Number of sub-parameters contained in the parameter. |
1
|
Returns:
Type | Description |
---|---|
weights_expanded
|
The expanded weights as a pytorch parameter. |
Source code in deep_river/utils/layer_adaptation.py
get_expansion_instructions
¶
Returns a dictionary containing information on how each parameter of a layer contained in param_shapes corresponds to the input and output dimensionality given its shape string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
param_shapes
|
Dict
|
Dictionary containing all parameters of a layer as keys and their corresponding shape strings as values. |
required |
Returns:
Type | Description |
---|---|
instructions
|
Dictionary specifying which axes of each parameter have to be altered to modify the input- or output dimensionality as well as the number of sub-parameters contained in the axes. |
Source code in deep_river/utils/layer_adaptation.py
get_in_out_axes
¶
Returns a dictionary containing information on how a specific parameter's axis sizes correspond to the input and output dimensionality given its shape string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shape_str
|
str
|
String specifying the shape of a parameter. |
required |
Returns:
Type | Description |
---|---|
axes
|
Dictionary specifying which axes have to be altered to modify the input- or output dimensionality as well as the number of sub-parameters contained in the axes. |