Training & Evaluation Utilities
Relevant source files
The following files were used as context for generating this wiki page:
- python/dgllife/utils/analysis.py
- examples/generative_models/dgmg/utils.py
- examples/generative_models/dgmg/train.py
- examples/generative_models/dgmg/eval.py
- examples/property_prediction/csv_data_configuration/classification_inference.py
- examples/property_prediction/csv_data_configuration/README.md
- examples/reaction_prediction/rexgen_direct/README.md
The Training & Evaluation Utilities in DGL-LifeSci provide a robust framework for managing the lifecycle of Graph Neural Network (GNN) models applied to life science data. This includes tools for molecular data analysis, standardized training loops with early stopping, multi-process optimization, and comprehensive evaluation metrics for regression, classification, and generative tasks.
These utilities enable researchers to perform complex workflows such as reaction center prediction and molecular property estimation by providing reusable components for data splitting, model checkpointing, and performance summarization. The architecture supports both single-GPU and multi-GPU training environments, as well as multi-process CPU training for auto-regressive models.
Sources: README.md:12-20, examples/property_prediction/csv_data_configuration/README.md:10-30, examples/generative_models/dgmg/utils.py:1-20
Molecular Data Analysis
Before training, the system provides utilities to analyze molecular datasets to ensure data quality and understand structural distributions. The primary tool is analyze_mols, which filters invalid SMILES and computes descriptive statistics.
Key Analysis Features
- Validity Checking: Identifies and filters out molecules that cannot be processed by RDKit.
- Descriptor Calculation: Computes frequencies for atom types, bond types, degrees, and hybridization.
- Structural Summary: Calculates averages and standard deviations for the number of atoms, bonds, and rings.
Sources: python/dgllife/utils/analysis.py:93-130, examples/property_prediction/csv_data_configuration/README.md:25-45
The diagram shows the data flow from raw input SMILES strings to the generation of analysis reports and filtered datasets.
Sources: python/dgllife/utils/analysis.py:133-160
Training Framework
The training utilities are designed to support various model architectures, including GCN, GAT, Weave, and DGMG. The framework emphasizes reproducibility through random seed management and efficiency via multi-process optimization.
Optimization and Checkpointing
The project utilizes custom wrappers for PyTorch optimizers to handle standard and multi-process training scenarios.
| Component | Description |
|---|---|
Optimizer | A wrapper that manages zero_grad, backward, and step operations. |
MultiProcessOptimizer | Extends the base optimizer to synchronize gradients across multiple processes using all_reduce. |
Early Stopping | Monitors validation performance and saves the best model state to prevent overfitting. |
Checkpointing | Saves model state dictionaries (model.pth or checkpoint.pth) periodically or upon improvement. |
| Sources: examples/generative_models/dgmg/utils.py:230-275, examples/property_prediction/csv_data_configuration/README.md:110-125 |
Training Data Flow (DGMG Example)
For generative models like DGMG, the training process involves an environment-based approach where actions (node/edge additions) are modeled.
This sequence illustrates the synchronization required during multi-process training for auto-regressive generative models.
Sources: examples/generative_models/dgmg/train.py:70-120, examples/generative_models/dgmg/utils.py:260-275
Evaluation Utilities
Evaluation utilities vary by task type, providing specific metrics for regression, classification, and molecular generation.
Classification and Regression Metrics
- Regression: Supports R2 (Pearson correlation), Mean Absolute Error (MAE), and Root Mean Square Error (RMSE).
- Classification: Standard metric is ROC-AUC score, with support for both hard and soft classification outputs.
Sources: examples/property_prediction/csv_data_configuration/README.md:100-110, examples/property_prediction/csv_data_configuration/README.md:225-235
Generative Model Evaluation
For generative models, evaluation focuses on the quality of the generated chemical space rather than simple loss values. The aggregate_and_evaluate function in the DGMG module tracks three critical statistics:
- Validity: Percentage of generated molecules that are valid RDKit molecules.
- Uniqueness: Percentage of valid molecules that are not duplicates.
- Novelty: Percentage of unique valid molecules that were not present in the training set.
Sources: examples/generative_models/dgmg/eval.py:58-85
Reaction Prediction Evaluation
Reaction prediction evaluation is split into two stages:
- Reaction Center Prediction: Measured using Top-K accuracy (Acc@K), determining if the true bond changes are within the top-ranked predictions.
- Candidate Ranking: Evaluated based on whether the ground truth product can be recovered and ranked highly among generated candidates, using both "Strict" (RDKit-based) and "MolVS" equivalence.
Sources: examples/reaction_prediction/rexgen_direct/README.md:65-85, examples/reaction_prediction/rexgen_direct/README.md:235-255
Summary of Configuration Parameters
Common training and evaluation configurations are managed via command-line arguments and JSON configuration files.
| Parameter | Type | Default | Description |
|---|---|---|---|
num_processes | int | 32 (DGMG) / 1 (CSV) | Number of processes for data loading/training. |
lr | float | 1e-4 | Learning rate for the optimizer. |
split | str | 'scaffold' | Dataset split method (scaffold or random). |
metric | str | 'roc_auc_score' | Primary evaluation metric. |
batch_size | int | 1 | Samples per gradient update. |
| Sources: examples/generative_models/dgmg/utils.py:100-115, examples/property_prediction/csv_data_configuration/README.md:180-200, examples/generative_models/dgmg/train.py:165-180 |
The training and evaluation utilities provide a standardized interface for processing complex biological data. By integrating automated analysis, multi-process optimization, and rigorous chemical-aware evaluation metrics, the system ensures that GNN models are both technically sound and biologically relevant.
Sources: README.md:5-15, examples/generative_models/dgmg/README.md:120-140