Skip to main content

Overview

ChemLactica uses a combination of YAML configuration files and Python dataclasses to configure model architecture and training hyperparameters. This guide covers all available options.

Configuration Structure

Configuration Files

Configuration is split into two main components:
  • Model Config: Architecture parameters (layers, heads, dimensions)
  • Train Config: Training hyperparameters (learning rate, batch size, etc.)

Available Model Configurations

Model Configuration

ModelConfig Dataclass

integer
default:"2048"
Maximum sequence length the model can process
integer
default:"50000"
Size of the tokenizer vocabulary
string
default:"</s>"
Token used to separate sequences
integer
default:"2"
Token ID for the separator token
string
Path to the tokenizer directory

Training Configuration

TrainConfig Dataclass

Optimizer Configuration

string
default:"adamw_torch"
Optimizer to use. Options: adamw_torch, adamw_hf, sgd, etc.
float
default:"0.9"
Adam optimizer beta1 parameter (exponential decay rate for first moment)
float
default:"0.95"
Adam optimizer beta2 parameter (exponential decay rate for second moment)
float
default:"0.1"
Weight decay (L2 regularization) coefficient
float
default:"1.0"
Maximum gradient norm for gradient clipping

Learning Rate Configuration

float
default:"6.0e-4"
Maximum learning rate (peak LR after warmup)
integer
default:"500"
Number of steps to warm up learning rate from 0 to max
string
default:"linear"
Learning rate scheduler type. Options: linear, constant_with_warmup, cosine, polynomial
float
default:"0.1"
Learning rate decay factor (used by some schedulers)

Precision Configuration

boolean
default:"true"
Use bfloat16 mixed precision training
boolean
default:"true"
Use bfloat16 for evaluation as well
boolean
default:"false"
Use float16 mixed precision (alternative to bf16)
boolean
default:"true"
Use TF32 precision on Ampere GPUs for matmuls

Evaluation and Checkpointing

string
default:"steps"
When to run evaluation. Options: no, steps, epoch
integer
default:"256"
Number of steps between evaluations (when evaluation_strategy="steps")
integer
default:"4"
Maximum number of checkpoints to keep (older ones are deleted)

Gradient Accumulation

boolean
default:"false"
Enable dynamic gradient accumulation scheduling
boolean
default:"false"
Allow gradient accumulation steps to change during training
integer
default:"256"
Maximum gradient accumulation steps (when dynamic)
integer
default:"100"
Steps between gradient accumulation adjustments
float
default:"0.02"
Percentage change in gradient accumulation per adjustment
integer
default:"4000"
Steps to wait before adjusting gradient accumulation

Other Parameters

integer
default:"500000"
Global batch size (used for calculating effective batch size)
float
default:"0.1"
Dropout probability for regularization

Model-Specific Configurations

125M Configuration

Recommended for:
  • Quick experimentation
  • Single GPU training
  • Limited compute resources

1.3B Configuration

Recommended for:
  • Multi-GPU training (2-4 GPUs)
  • Production use cases
  • Good balance of performance and resources

Mistral 7B Configuration

Recommended for:
  • Multi-GPU training (4-8 GPUs)
  • Large-scale pretraining
  • State-of-the-art performance

Llama 2 Configuration

Recommended for:
  • Fine-tuning tasks
  • Leveraging pretrained Llama 2 weights
  • Chemistry-specific adaptations

SFT Configuration

SFTTrainConfig

boolean
default:"false"
Pack multiple short samples into single sequences
integer
default:"64"
Maximum sequence length for SFT samples
integer
default:"10"
Noise level for NEFTune (embedding perturbation)

CustomArguments

Extends Hugging Face TrainingArguments with ChemLactica-specific options:

Key Training Arguments

From train.py:217-264:

Accelerate Configuration

For distributed training, ChemLactica uses Accelerate:

FSDP Configuration

Configuration Examples

Small-Scale Pretraining

Large-Scale Pretraining

Fine-Tuning

Best Practices

Pretraining:
  • 125M: 1.4e-3
  • 1.3B: 1.4e-3
  • 6.7B: 1.2e-4
  • Mistral 7B: 5.0e-4
  • Llama 2: 3.0e-5
Fine-tuning:
  • 10-100x lower than pretraining
  • Typical range: 1e-5 to 1e-4
  • Pretraining: 500-2000 steps
  • SFT: 0-100 steps
  • Rule of thumb: ~1-5% of total steps
  • Larger batches = more stable training
  • Use gradient accumulation if GPU memory limited
  • Effective batch size = per_device_batch_size × num_gpus × grad_accum_steps
  • Default: 1.0 works well for most cases
  • Lower (0.1) for Llama 2 fine-tuning
  • Monitor gradient norms during training
  • BF16 recommended for Ampere GPUs (A100, A6000)
  • FP16 for older GPUs (V100)
  • TF32 provides free speedup on Ampere

Environment Variables

Next Steps

Pretraining

Start pretraining with these configs

Fine-tuning

Apply configs to fine-tuning

Rejection Sampling

Configure rejection sampling