athena__clipper Module

Module containing functions to clip gradients

This module implements clipping methods for layer gradients


Uses

    • coreutils

Interfaces

public interface clip_type

Interface for the clip type

  • private module function clip_setup(clip_min, clip_max, clip_norm) result(clip)

    Set up the clip dictionary

    Arguments

    Type IntentOptional 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

    Return Value type(clip_type)

    Clip dictionary


Derived Types

type, public ::  clip_type

Type for clipping gradients

Components

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

Constructor

Interface for the clip type

private module function clip_setup (clip_min, clip_max, clip_norm)

Set up the clip dictionary

Type-Bound Procedures

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


Functions

private module function clip_setup(clip_min, clip_max, clip_norm) result(clip)

Set up the clip dictionary

Arguments

Type IntentOptional 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

Return Value type(clip_type)

Instance of the clip type


Subroutines

private pure subroutine apply_clip(this, length, gradient, bias)

Function to apply clipping to gradients

Arguments

Type IntentOptional 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

private subroutine read_clip(this, min_str, max_str, norm_str)

Read clipping information

Arguments

Type IntentOptional 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

private subroutine set_clip(this, clip_dict, clip_min, clip_max, clip_norm)

Set clipping information

Arguments

Type IntentOptional 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