Skip to main content

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
This guide covers both approaches and when to use each.

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:
Each training sample should include:
  • EOS token </s> as separator
  • Similar molecules with similarity scores
  • Property values in [PROPERTY]name value[/PROPERTY] format
  • Target SMILES in [START_SMILES]...[END_SMILES]

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:
  1. Generating candidate molecules
  2. Scoring them with an oracle
  3. Fine-tuning on high-scoring examples
This approach is used in the optimization loop (see Custom Oracles).

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

  • 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
  • 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_alpha for better generalization
  • Set train_tol_level based 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
  • 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
When using rejection sampling, ensure your oracle has appropriate caching to avoid redundant calculations. The optimization process may evaluate the same molecule multiple times.

Next Steps

Custom Oracles

Build custom scoring functions for optimization

Benchmarking

Evaluate model performance on standard benchmarks