LibtorchANNTrainer

Overview

This trainer is dedicated to train a LibtorchArtificialNeuralNet. For a detailed description of the neural network trained by this object, visit LibtorchArtificialNeuralNet. The user can customize the neural network in the trainer, however the optimization algorithm is hardcoded to be Adam.

Example Input File Syntax

Let us try to approximate the following function: y=Πi=134xi2y = \Pi_{i=1}^3|4x_i-2| over the [0,0.05]3[0,0.05]^3 domain. For this, we select 125(5×5×5)125 (5 \times 5 \times 5) points using a tensor product grid as follows:

[Samplers]
  [sample]
    type = CartesianProduct
    linear_space_items = '0 0.0125 5
                          0 0.0125 5
                          0 0.0125 5'
  []
[]
(contrib/moose/modules/stochastic_tools/test/tests/surrogates/libtorch_nn/train.i)

Following this, the function is evaluated using a vector postprocessor:

[VectorPostprocessors]
  [values]
    type = GFunction
    sampler = sample
    q_vector = '0 0 0'
    execute_on = INITIAL
    outputs = none
  []
[]
(contrib/moose/modules/stochastic_tools/test/tests/surrogates/libtorch_nn/train.i)

Once this is done, the corresponding inputs (from the sampler) and outputs (from the postprocessor) are handed to the neural net trainer to optimize the weights:

[Trainers]
  [train]
    type = LibtorchANNTrainer
    sampler = sample
    response = values/g_values
    num_epochs = 40
    num_batches = 10
    num_neurons_per_layer = '64 32'
    learning_rate = 0.001
    nn_filename = mynet.pt
    read_from_file = false
    print_epoch_loss = 10
    activation_function = 'relu relu'
    max_processes = 1
    standardize_input = false
    standardize_output = false
  []
[]
(contrib/moose/modules/stochastic_tools/test/tests/surrogates/libtorch_nn/train.i)
warningwarning

The detailed documentation of this object is only available when Moose is compiled with Libtorch. For instructions on how to compile Moose with Libtorch, visit the general installation webpage or click here.