Overview
ChemLactica supports supervised fine-tuning (SFT) to adapt pretrained models for specific chemical tasks. The SFT framework uses TRL’sSFTTrainer with custom data collators for completion-only training.
Supervised Fine-Tuning (SFT)
Quick Start
1
Prepare SFT Data
Format your data with prompts and completions in JSONL format
2
Configure SFT Parameters
Set up packing, sequence length, and noise parameters
3
Run SFT Training
Launch training with the
sft train typeBasic SFT Command
SFT Configuration
SFT-specific parameters are defined inconfig/default_train_config.py:
SFT Parameters
boolean
default:"false"
Enable packing multiple samples into a single sequence for efficiency
integer
default:"64"
Maximum sequence length for SFT samples
integer
default:"10"
NEFTune noise parameter for embedding perturbation (improves generalization)
Data Format
Response Template
The SFT trainer uses a response template to train only on completions:Example Data Format
Training Configuration
Recommended Settings for SFT
Advanced SFT Features
NEFTune (Noisy Embeddings)
NEFTune adds noise to embeddings during training to improve generalization:Completion-Only Training
TheDataCollatorForCompletionOnlyLM ensures loss is computed only on the completion tokens:
SFT Numerical Evaluation
ChemLactica includes a custom callback for evaluating SFT models:Example: Activity Prediction SFT
Data Preparation
Create training data with molecular descriptors and activity values:Training Command
Multi-GPU SFT Training
For larger models or datasets:Evaluation-Only Mode
Evaluate a fine-tuned model without training:SFT vs Pretraining
Best Practices
Learning Rate Selection
Learning Rate Selection
- Use 10-100x lower learning rate than pretraining
- Start with 1e-4 for small models
- Use 2e-5 or lower for models >1B parameters
- Monitor validation loss closely for overfitting
Data Quality
Data Quality
- Ensure consistent formatting across all samples
- Balance your dataset across different property values
- Remove duplicates and low-quality samples
- Use validation set from same distribution as training
Sequence Length
Sequence Length
- Keep
max_seq_lengthas small as possible - Typical values: 64-512 tokens
- Longer sequences require more memory
- Consider packing for short sequences
Training Duration
Training Duration
- SFT typically requires 1000-10000 steps
- Watch for overfitting after a few epochs
- Use early stopping based on validation loss
- Save checkpoints frequently for model selection
Troubleshooting
Model Not Learning
- Check that response template matches your data format
- Verify data formatting is consistent
- Try increasing learning rate slightly
- Ensure sufficient training steps
Overfitting
- Reduce learning rate
- Increase weight decay
- Add more training data
- Enable dropout if needed
- Use NEFTune noise
Memory Issues
- Reduce
max_seq_length - Decrease
train_batch_size - Increase
gradient_accumulation_steps - Enable packing for short sequences
- Use
--gradient_checkpointing
Next Steps
Rejection Sampling
Learn about rejection sampling fine-tuning strategy
Configuration
Explore detailed configuration options