Medical-domain continued pre-training (CPT) pipeline for HuggingFaceTB's
SmolLM-135M model. Trains on PubMed, PMC, Medline, and FineWeb datasets
using LoRA adapters with the Unsloth framework.
Load Model (model_utils.py) — Loads SmolLM-135M in 4-bit (NF4) via Unsloth with bfloat16 compute dtype.
Baseline Eval — Evaluates the untrained base model on perplexity (PubMed Abstracts, Medline) and benchmarks (PubMedQA, MedMCQA).
Data Phase (data.py) — Downloads and tokenizes biomedical datasets (PubMed, PMC, Medline, FineWeb; 200K samples), splits 90/10 train/val, writes to text files, loads into HuggingFace Datasets. Called inside train.py.
Training (train.py) — Loads base model, attaches LoRA adapters (rank 32), tokenizes datasets into packed sequences, runs 1 epoch of CPT with UnslothTrainer.
Export — Saves a merged 16-bit model to SmolLM-135M_Med_Merged/.
Post-Training Eval — Re-runs perplexity and benchmarks on the trained model.
Configuration
All paths and hyperparameters are set in config.yaml:
Key
Value
Description
MODEL_NAME
HuggingFaceTB/SmolLM-135M
Base model
SEED
42
Random seed
MAX_SEQ_LENGTH
512
Max sequence length
OVERLAP
128
Overlap (reserved)
data_file
./data/dataset.txt
Combined dataset path
train_file
./data/train.txt
Training data path
val_file
./data/val.txt
Validation data path
Training Details
Model
Base: HuggingFaceTB/SmolLM-135M (135M parameters)
Precision: 4-bit loaded (NF4), merged to 16-bit on save