Overview
ChemLactica supports two types of fine-tuning:- Supervised Fine-Tuning (SFT): Train on labeled molecular property data
- Rejection Sampling: Optimize for specific properties during molecule generation
Supervised Fine-Tuning (SFT)
When to Use SFT
Use supervised fine-tuning when you have:- Labeled dataset with molecular properties
- Want to predict specific properties (QED, activity, etc.)
- Need the model to learn property-structure relationships
Dataset Format
Prepare your data in the ChemLactica format with property tags:Configuration
Create an SFT configuration file:Key SFT Parameters
boolean
default:"true"
Pack multiple short sequences into single examples for efficiency
integer
default:"512"
Maximum sequence length for training samples
integer
default:"5"
NEFTune noise parameter for improved generalization
Rejection Sampling Fine-Tuning
Overview
Rejection sampling optimizes the model during molecule generation by:- Generating candidate molecules
- Scoring them with an oracle
- Fine-tuning on high-scoring examples
Configuration
Rejection sampling is configured within the optimization config:optimization_config.yaml
How It Works
1
Generate Molecules
The model generates molecules based on similar molecules and desired properties:
2
Score with Oracle
Generated molecules are evaluated:
3
Build Training Pool
High-scoring molecules are added to a pool:
4
Fine-tune Model
When improvement stalls (
tol_level >= train_tol_level), fine-tune on the pool:Pool Management
The pool maintains diversity and quality:- Molecules are sorted by score
- Duplicates and highly similar molecules are removed (Tanimoto > threshold)
- Top 20% are reserved for validation
- Remaining 80% used for training
Training Arguments
Common Parameters
float
default:"1e-4"
Peak learning rate for training
integer
default:"500"
Number of warmup steps for learning rate scheduler
float
default:"0.1"
Weight decay for AdamW optimizer
integer
default:"1"
Accumulate gradients over multiple batches
boolean
default:"true"
Use bfloat16 mixed precision training
Optimizer Configuration
ChemLactica uses AdamW with polynomial decay:Callbacks
Model Selection Callback
Saves the best model based on validation loss:Early Stopping Callback
Stops training when validation loss stops improving:Example: Complete SFT Workflow
Best Practices
Data Quality
Data Quality
- Ensure property values are normalized to appropriate ranges
- Include diverse molecular scaffolds in training data
- Balance the dataset across property value ranges
- Validate SMILES strings before training
Hyperparameter Tuning
Hyperparameter Tuning
- Start with smaller learning rates (1e-5 to 1e-4) for fine-tuning
- Use warmup steps (10-20% of training steps)
- Monitor validation loss to prevent overfitting
- Adjust
neftune_noise_alphafor better generalization
Rejection Sampling
Rejection Sampling
- Set
train_tol_levelbased on oracle budget (typically 2-3) - Use larger pool sizes (100-200) for better diversity
- Keep validation_perc around 0.2 for reliable evaluation
- Save checkpoints periodically during long optimizations
Monitoring
Monitoring
- Track top-1, top-10, top-100 scores during optimization
- Monitor validation loss during fine-tuning
- Check molecular validity and diversity of generated molecules
- Use TensorBoard or Weights & Biases for visualization
Next Steps
Custom Oracles
Build custom scoring functions for optimization
Benchmarking
Evaluate model performance on standard benchmarks