Module containing functions to clip gradients
This module implements clipping methods for layer gradients
Interface for the clip type
Set up the clip dictionary
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real32), | intent(in), | optional | :: | clip_min |
Minimum, maximum, and norm values for clipping |
|
| real(kind=real32), | intent(in), | optional | :: | clip_max |
Minimum, maximum, and norm values for clipping |
|
| real(kind=real32), | intent(in), | optional | :: | clip_norm |
Minimum, maximum, and norm values for clipping |
Clip dictionary
Type for clipping gradients
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| logical, | public | :: | l_min_max | = | .false. |
Boolean whether min/max values are set |
|
| logical, | public | :: | l_norm | = | .false. |
Boolean whether a norm is set |
|
| real(kind=real32), | public | :: | max | = | huge(1._real32) |
Maximum value for clipping |
|
| real(kind=real32), | public | :: | min | = | -huge(1._real32) |
Minimum value for clipping |
|
| real(kind=real32), | public | :: | norm | = | huge(1._real32) |
Maximum L2-norm for clipping |
Interface for the clip type
| private module function clip_setup (clip_min, clip_max, clip_norm) | Set up the clip dictionary |
| procedure, public, pass(this) :: apply => apply_clip | Apply clipping to gradients |
| procedure, public, pass(this) :: read => read_clip | Read clipping information |
| procedure, public, pass(this) :: set => set_clip | Set clipping information |
Set up the clip dictionary
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real32), | intent(in), | optional | :: | clip_min |
Minimum, maximum, and norm values for clipping |
|
| real(kind=real32), | intent(in), | optional | :: | clip_max |
Minimum, maximum, and norm values for clipping |
|
| real(kind=real32), | intent(in), | optional | :: | clip_norm |
Minimum, maximum, and norm values for clipping |
Instance of the clip type
Function to apply clipping to gradients
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(clip_type), | intent(in) | :: | this |
Instance of the clip type |
||
| integer, | intent(in) | :: | length |
Length of the gradient |
||
| real(kind=real32), | intent(inout), | dimension(length) | :: | gradient |
Gradient to be clipped |
|
| real(kind=real32), | intent(inout), | optional, | dimension(:) | :: | bias |
Bias to be clipped |
Read clipping information
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(clip_type), | intent(inout) | :: | this |
Instance of the clip type |
||
| character(len=*), | intent(in) | :: | min_str |
Strings for min, max, and norm values |
||
| character(len=*), | intent(in) | :: | max_str |
Strings for min, max, and norm values |
||
| character(len=*), | intent(in) | :: | norm_str |
Strings for min, max, and norm values |
Set clipping information
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(clip_type), | intent(inout) | :: | this |
Instance of the clip type |
||
| type(clip_type), | intent(in), | optional | :: | clip_dict |
Clip dictionary |
|
| real(kind=real32), | intent(in), | optional | :: | clip_min |
Minimum, maximum, and norm values for clipping |
|
| real(kind=real32), | intent(in), | optional | :: | clip_max |
Minimum, maximum, and norm values for clipping |
|
| real(kind=real32), | intent(in), | optional | :: | clip_norm |
Minimum, maximum, and norm values for clipping |