athena__base_layer_submodule Submodule

Submodule containing the implementation of the base layer types

This submodule contains the implementation of the base layer types used in the ATHENA library. The base layer types are the abstract types from which all other layer types are derived. The submodule contains the implementation of the procedures that are common to all layer types, such as setting the input shape, getting the number of parameters, and printing the layer to a file.

The following procedures are based on code from the neural-fortran library https://github.com/modern-fortran/neural-fortran/blob/main/src/nf/nf_layer.f90 procedures: - get_num_params - get_params - set_params - get_gradients - set_gradients*


Uses


Module Functions

module function add_learnable(a, b) result(output)

Add two learnable layers together

Arguments

Type IntentOptional Attributes Name
class(learnable_layer_type), intent(in) :: a

Instances of layers

class(learnable_layer_type), intent(in) :: b

Instances of layers

Return Value class(learnable_layer_type), allocatable

Output layer

module function forward_eval_base(this, input) result(output)

Forward pass of layer and return output for evaluation

Arguments

Type IntentOptional Attributes Name
class(base_layer_type), intent(inout), target :: this

Instance of the layer

class(array_type), intent(in), dimension(:,:) :: input

Input data

Return Value type(array_type), pointer, (:,:)

Output data

module function get_attributes_base(this) result(attributes)

Get the attributes of the layer (for ONNX export)

Arguments

Type IntentOptional Attributes Name
class(base_layer_type), intent(in) :: this

Instance of the layer

Return Value type(onnx_attribute_type), allocatable, dimension(:)

Attributes of the layer

module function get_attributes_batch(this) result(attributes)

Get the attributes of a batch normalisation layer (for ONNX export)

Arguments

Type IntentOptional Attributes Name
class(batch_layer_type), intent(in) :: this

Instance of the layer

Return Value type(onnx_attribute_type), allocatable, dimension(:)

Attributes of the layer

module function get_attributes_conv(this) result(attributes)

Get the attributes of a convolutional layer (for ONNX export)

Arguments

Type IntentOptional Attributes Name
class(conv_layer_type), intent(in) :: this

Instance of the layer

Return Value type(onnx_attribute_type), allocatable, dimension(:)

Attributes of the layer

module function get_attributes_pool(this) result(attributes)

Get the attributes of a pooling layer (for ONNX export)

Arguments

Type IntentOptional Attributes Name
class(pool_layer_type), intent(in) :: this

Instance of the layer

Return Value type(onnx_attribute_type), allocatable, dimension(:)

Attributes of the layer

pure module function get_gradients(this, clip_method) result(gradients)

Get the gradients of the layer

Read more…

Arguments

Type IntentOptional Attributes Name
class(learnable_layer_type), intent(in) :: this

Instance of the layer

type(clip_type), intent(in), optional :: clip_method

Method to clip the gradients

Return Value real(kind=real32), dimension(this%num_params)

Gradients of the layer

pure module function get_num_params_base(this) result(num_params)

Get the number of parameters in the layer

Arguments

Type IntentOptional Attributes Name
class(base_layer_type), intent(in) :: this

Instance of the layer

Return Value integer

Number of parameters

pure module function get_num_params_batch(this) result(num_params)

Get the number of parameters in batch normalisation layer

Arguments

Type IntentOptional Attributes Name
class(batch_layer_type), intent(in) :: this

Instance of the layer

Return Value integer

Number of parameters

pure module function get_num_params_conv(this) result(num_params)

Get the number of parameters in convolutional layer

Arguments

Type IntentOptional Attributes Name
class(conv_layer_type), intent(in) :: this

Instance of the layer

Return Value integer

Number of parameters

pure module function get_params(this) result(params)

Get the learnable parameters of the layer

Read more…

Arguments

Type IntentOptional Attributes Name
class(learnable_layer_type), intent(in) :: this

Instance of the layer

Return Value real(kind=real32), dimension(this%num_params)

Learnable parameters


Module Subroutines

module subroutine build_from_onnx_base(this, node, initialisers, value_info, verbose)

Build layer from ONNX node and initialiser

Arguments

Type IntentOptional Attributes Name
class(base_layer_type), intent(inout) :: this

Instance of the layer

type(onnx_node_type), intent(in) :: node

ONNX node

type(onnx_initialiser_type), intent(in), dimension(:) :: initialisers

ONNX initialisers

type(onnx_tensor_type), intent(in), dimension(:) :: value_info

ONNX value info

integer, intent(in) :: verbose

Verbosity level

module subroutine emit_onnx_graph_inputs_base(this, prefix, graph_inputs, num_inputs)

Default implementation: no-op (standard layers don't add graph inputs)

Arguments

Type IntentOptional Attributes Name
class(base_layer_type), intent(in) :: this

Instance of the layer

character(len=*), intent(in) :: prefix

Prefix for input names

type(onnx_tensor_type), intent(inout), dimension(:) :: graph_inputs

ONNX graph inputs

integer, intent(inout) :: num_inputs

Number of ONNX graph inputs

module subroutine emit_onnx_nodes_base(this, prefix, nodes, num_nodes, max_nodes, inits, num_inits, max_inits, input_name, is_last_layer, format)

Default implementation: no-op (standard layers are handled by write_onnx)

Arguments

Type IntentOptional Attributes Name
class(base_layer_type), intent(in) :: this

Instance of the layer

character(len=*), intent(in) :: prefix

Prefix for node names

type(onnx_node_type), intent(inout), dimension(:) :: nodes

ONNX nodes

integer, intent(inout) :: num_nodes

Number of ONNX nodes

integer, intent(in) :: max_nodes

Maximum number of ONNX nodes

type(onnx_initialiser_type), intent(inout), dimension(:) :: inits

ONNX initialisers

integer, intent(inout) :: num_inits

Number of ONNX initialisers

integer, intent(in) :: max_inits

Maximum number of ONNX initialisers

character(len=*), intent(in), optional :: input_name

Name of the input tensor from the previous layer

logical, intent(in), optional :: is_last_layer

Whether this is the last non-input layer

integer, intent(in), optional :: format

Export format selector

module subroutine extract_output_base(this, output)

Get the output of the layer

Arguments

Type IntentOptional Attributes Name
class(base_layer_type), intent(in) :: this

Instance of the layer

real(kind=real32), intent(out), allocatable, dimension(..) :: output

Output of the Layer

module subroutine forward_base(this, input)

Forward pass for the layer

Arguments

Type IntentOptional Attributes Name
class(base_layer_type), intent(inout) :: this

Instance of the layer

class(array_type), intent(in), dimension(:,:) :: input

Input data

module subroutine nullify_graph_base(this)

Nullify the forward pass data of the layer to free memory

Arguments

Type IntentOptional Attributes Name
class(base_layer_type), intent(inout) :: this

Instance of the layer

module subroutine reduce_learnable(this, input)

Merge two learnable layers via summation

Arguments

Type IntentOptional Attributes Name
class(learnable_layer_type), intent(inout) :: this

Instance of the layer

class(learnable_layer_type), intent(in) :: input

Instance of a layer

module subroutine set_gradients(this, gradients)

Set the gradients of the layer

Read more…

Arguments

Type IntentOptional Attributes Name
class(learnable_layer_type), intent(inout) :: this

Instance of the layer

real(kind=real32), intent(in), dimension(..) :: gradients

Gradients of the layer

module subroutine set_graph_base(this, graph)

Set the graph structure of the input data

Arguments

Type IntentOptional Attributes Name
class(base_layer_type), intent(inout) :: this

Instance of the layer

type(graph_type), intent(in), dimension(:) :: graph

Graph structure of input data

module subroutine set_params(this, params)

Set the learnable parameters of the layer

Read more…

Arguments

Type IntentOptional Attributes Name
class(learnable_layer_type), intent(inout) :: this

Instance of the layer

real(kind=real32), intent(in), dimension(this%num_params) :: params

Learnable parameters

module subroutine set_rank_base(this, input_rank, output_rank)

Set the input and output ranks of the layer

Arguments

Type IntentOptional Attributes Name
class(base_layer_type), intent(inout) :: this

Instance of the layer

integer, intent(in) :: input_rank

Input rank

integer, intent(in) :: output_rank

Output rank

module subroutine set_shape_base(this, input_shape)

Set the input shape of the layer

Arguments

Type IntentOptional Attributes Name
class(base_layer_type), intent(inout) :: this

Instance of the layer

integer, intent(in), dimension(:) :: input_shape

Input shape