CodonFM: Foundation Models for Codon Sequences
CodonFM is a fully open-source suite of foundation models trained directly on codon sequences to learn contextual codon representations and enable downstream codon-aware tasks. We release the entire stack: code, training/finetuning/evaluation scripts, dockerized environments, experiment templates, and pre-trained model weights under an open license for transparent and reproducible use.
Our primary model family, Encodon, uses masked language modeling over codons with scalable architectures (80M to 1B) and efficient memmapped data pipelines. Public links to the pre-trained checkpoints are here: 80M, 600M, 1B, 1B-Cdwt.
The checkpoints can also be found on NGC here.
Release v1.1 security scope: This branch contains the Encodon model family and the release package and container security updates.
Methodology and Results
The pre-print of this work with detailed methodology and results can be found here
If you like this work please cite it as follows:
@article{codonfm_2025,
author = {Darabi+, Sajad and Cao+, Fan and Naghipourfar+, Mohsen and Rabi, Sara and Sethia, Ankit and Gion, Kyle and Grewal, Jasleen and Cohen, Jonathan and Greenleaf, William and Goodarzi*, Hani and Sundaram*, Laksshman},
title = {{Learning the language of codon translation with CodonFM}},
url = {https://research.nvidia.com/labs/dbr/assets/data/manuscripts/nv-codonfm-preprint.pdf},
year = {2025}
}
Note: Sajad Darabi, Fan Cao and Mohsen Naghipourfar are equal contributing first authors.
Corresponding Author: Hani Goodarzi and Laksshman Sundaram
Accelerated CodonFM
This repository contains the exact code used in the pre-print.
An accelerated version of the codebase is available in BioNeMo Framework Recipes, which uses TransformerEngine to accelerate training and inference. Accelerated checkpoints are available for all Encodon model variants: 80M, 600M, 1B, 1B-Cdwt.
Table of Contents
Pre-trained Models
The table below summarizes the set of open source pre-trained weights currently made available. All of the training scripts are contained in the directory experiment_scripts/pretraining/encodon_filtered/.
| Model |
Variant |
Hidden size |
Layers |
Heads |
Intermediate |
Script |
Checkpoint |
| Encodon 80M |
MLM (random p=0.15) |
1024 |
6 |
8 |
4096 |
mlm/encodon_80m.sh |
link |
| Encodon 600M |
MLM (random p=0.15) |
2048 |
12 |
16 |
8192 |
mlm/encodon_600m.sh |
link |
| Encodon 1B |
MLM (random p=0.15) |
2048 |
18 |
16 |
8192 |
mlm/encodon_1b.sh |
link |
| Encodon 1B (CDSWT) |
MLM (codon frequency-weighted) |
2048 |
18 |
16 |
8192 |
cdswt/encodon_1b.sh |
link |
Repository Structure
High-level overview (NerdTree-style):
codon-fm/
├── src/ — core library and CLI entrypoints
│ ├── runner.py — entry for pretrain/finetune/eval
│ ├── config.py — model/data/trainer configs
│ ├── tasks.py — pretraining/finetuning/eval tasks
│ ├── models/ — model definitions and components
│ ├── data/ — datamodules, datasets, preprocessing
│ │ └── preprocess/ — item level process items
│ ├── inference/ — inference wrappers and prediction definitions
│ ├── tokenizer/ — codon tokenizer and mappings
│ └── utils/ — logging, schedulers, writers, helpers
├── experiment_scripts/ — launch scripts for pre-training
│ └── pretraining/ — Encodon pretraining
├── data_scripts/ — data download and curation tools
├── notebooks/ — analysis and evaluation notebooks
├── pyproject.toml — package metadata, dependencies, and NGC image constraints
├── env.example — sample env vars
└── README.md — repo guide
Quickstart
To run the scripts in this repository, we recommend using the provided Docker setup.
1. Clone the repository
git clone https://github.com/NVIDIA-BioNeMo/CodonFM
cd CodonFM
2. Docker Setup
The fastest way to get up and running with CodonFM is through the Docker setup below. This is an interactive development environment, you can build and launch a container that mounts your local repository. This allows you to edit code locally and run it inside the container.
To build and launch the development container, simply run the following from the root folder:
bash run_dev.sh
This script will:
- Build the development Docker image using the
development target in the Dockerfile.
- Pass your user and group IDs to the container to avoid permission issues with mounted files.
- Stop and remove any existing container with the same name.
- Launch a new container with your local code mounted at
/workspace, GPU access, isolated networking, a published Jupyter port, and the configured data directories.
You can also customize the data and checkpoint directory paths by passing arguments:
bash run_dev.sh --data-dir /path/to/your/data --checkpoints-dir /path/to/your/checkpoints
You will be dropped into a bash shell inside the container as a non-root user.
Evaluation Notebooks 📓
A series of notebooks in the notebooks directory show zero-shot variant prediction and downstream tasks that train Random Forest regressors on pretrained Encodon embeddings. See a brief overview below:
Data 📊
Pre-training Dataset
The data curation tools live under data_scripts/data_curation/.
- Main entrypoint: open and run
data_scripts/data_curation/download_cds_clean.ipynb. It documents how to obtain coding sequences (CDS), process metadata, and produce curated outputs.
- Filtering resources:
data_scripts/data_curation/taxids_to_remove_bac.json lists bacterial taxids to exclude during curation.
- Recommended environment: use the provided dev container (
bash run_dev.sh), then open the notebook in Jupyter/VS Code and execute the cells.
Outputs from the notebook (cleaned CDS files and metadata tables) can be transformed into training-ready memory-mapped data with data_scripts/ncbi_memmap_dataset_batched.py. The resulting files can then be consumed by CodonMemmapDataset.
CodonMemmapDataset also requires a sequence cluster file, allSeqClusterIdx.npy, in the data directory to build train/val/test splits. Generate it with data_scripts/data_curation/allseq_clustering_for_splits.ipynb (see data_scripts/README.md).
Evaluation Datasets
- mRFP expression and mRNA stability:
- Open and run the notebooks
notebooks/5-EnCodon-Downstream-Task-mRFP-expression.ipynb and notebooks/6-EnCodon-Downstream-Task-mRNA-stability.ipynb. These notebooks contain cells that download/prepare the datasets and guide you through executing the evaluations end-to-end.
- Mean translation efficiency prediction task:
- Open and run the notebook
notebooks/4-EnCodon-Downstream-Task-riboNN.ipynb. It will download/prepare the downstream dataset and guide you through finetuning on this downstream task.
- Synonymous, DDD/ASD, and Cancer Hotspot variant datasets:
- Follow
notebooks/00-Mutation-Datasets-Preprocessing.ipynb. This notebook includes a cell that lists the required input files (with expected names/locations) and outlines how to process them into harmonized formats.
- After preprocessing, use the task-specific notebooks in
notebooks/ (e.g., 0-...CancerHotspot.ipynb and 1-...DDD-ASD.ipynb) which consume the harmonized outputs produced by the preprocessing notebook.
Running Training/Finetuning/Evaluation
The main entry point is available as either python -m src.runner or the installed codon-fm command. It supports three modes:
Pre-training
The explicit scripts used to train the released checkpoints are referenced in Pre-trained Models
python -m src.runner pretrain \
--out_dir <output_dir> \
--exp_name <experiment_name> \
--model_name <model_size> \
--data_path <path_to_data> \
--process_item mlm_memmap \
--dataset_name CodonMemmapDataset \
--lr <learning_rate> \
--num_gpus <num_gpus> \
--num_nodes <num_nodes>
Optional path overrides:
--out_dir <dir>
--checkpoints_dir <dir>
--pretrained_ckpt_path <path>
Available --process_item options:
mlm_memmap: Constructs MLM training examples using memory-mapped data input format.
mutation_pred_mlm: Constructs mutation prediction scoring input for the model using ref/alt/mut pos
mutation_pred_likelihood: Constructs input sentence with alt mutation at input to be scored by the model.
codon_sequence: Constructs a codon sequence that can be inputed into the model.
Available --dataset_name options: