Train AGAT model
Python script
import os
import torch.nn as nn
from agat.model import Fit
train_config = {
'verbose': 1, # `0`: no train and validation output; `1`: Validation and test output; `2`: train, validation, and test output.
'dataset_path': os.path.join('dataset', 'all_graphs.bin'),
'model_save_dir': 'agat_model',
'epochs': 1000,
'output_files': 'out_file',
'device': 'cuda:0',
'validation_size': 0.15,
'test_size': 0.15,
'early_stop': True,
'stop_patience': 300,
'head_list': ['mul', 'div', 'free'],
'gat_node_dim_list': [len(default_elements), 100, 100, 100],
'energy_readout_node_list': [len(head_list)*gat_node_dim_list[-1], 100, 50, 30, 10, 3, FIX_VALUE[0]],
'force_readout_node_list': [len(head_list)*gat_node_dim_list[-1], 100, 50, 30, 10, FIX_VALUE[1]],
'stress_readout_node_list': [len(head_list)*gat_node_dim_list[-1], 100, 50, 30, 10, FIX_VALUE[2]],
'bias': True,
'negative_slope': 0.2,
'criterion': nn.MSELoss(),
'a': 1.0,
'b': 1.0,
'c': 0.0,
# 'optimizer': 'adam',
'learning_rate': 0.0001,
'weight_decay': 0.0, # weight decay (L2 penalty)
'batch_size': 64,
'val_batch_size': 400,
'transfer_learning': False,
'trainable_layers': -4,
'mask_fixed': False,
'tail_readout_no_act': [3,3,3],
# 'adsorbate': False, # or not when building graphs.
'adsorbate_coeff': 20.0 # indentify and specify the importance of adsorbate atoms with respective to surface atoms. zero for equal importance.
}
f = Fit(**train_config)
f.fit()
See default_train_config to know how to use the parameter settings.
Output
The file structure:
.
├── agat_model
│ ├── agat_model.json
│ ├── agat.pth
│ └── agat_state_dict.pth
├── dataset
│ ├── all_graphs.bin
│ ├── fname_prop.csv
│ └── graph_build_scheme.json
├── fit.log
├── out_file
│ ├── energy_test_pred_true.txt
│ ├── energy_val_pred_true.txt
│ ├── force_test_pred_true.txt
│ ├── force_val_pred_true.txt
│ ├── stress_test_pred_true.txt
│ └── stress_val_pred_true.txt
└── train.py
Folder/File |
File |
Explanation |
---|---|---|
|
─── |
A directory for saving well-trained model. |
├── |
|
An information file tells you how to build an AGAT model. |
├── |
|
The saved AGAT model including model structure and parameters. |
└── |
|
Model and optimizer state dict file including model parameters only. You will need to construct a model or optimizer before using this file. |
|
─── |
A directory for the database. |
├── |
|
Binary file of the DGL graphs |
├── |
|
A file storing the structural file name, properties, and paths. This file will not be used in the training, but is useful for checking the raw data. |
└── |
|
An information file tells you how to build the database. When deploying the well-trained model, this file is useful to construct new graphs. |
|
The training log file. The |
|
|
─── |
A directory to store ouputs of true and predicted properties. Folder name specified by |
├── |
|
Predicted and true energy on the test dataset. |
├── |
|
Predicted and true energy on the validation dataset. |
├── |
|
Predicted and true force on the test dataset. |
├── |
|
Predicted and true force on the validation dataset. |
├── |
|
Predicted and true stress on the test dataset. |
└── |
|
Predicted and true stress on the validation dataset. |
|
The training script. |