Evo2
Model Introduction
Evo2 is a large-scale foundation model for genomic sequences. It can generate, complete, and predict functions for DNA/RNA sequences. The model supports pretraining on large-scale genomic datasets and can be rapidly adapted to downstream tasks such as regulatory element prediction and variant effect assessment, providing a unified sequence modeling tool for genomics research.
Model Description
Evo2 is built on a hybrid architecture that combines Hyena operators with convolutional gating, and supports context windows at the million-token scale. The model is pretrained on multi-species genomic data containing trillions of base pairs. It takes raw nucleotide sequences as input and supports autoregressive generation, sequence classification, and embedding extraction. Evo2 is compatible with multi-GPU distributed training and flexible data mixing, achieves leading performance on benchmarks such as GenBench, and is suitable for pretraining, fine-tuning, and downstream functional validation.
Applicable Scenarios
| Scenario | Description |
|---|---|
| DNA/RNA sequence generation | Generate subsequent genomic sequence fragments from an input prompt |
| FASTA sequence prediction | Read FASTA input and output sequence prediction results |
| Local offline inference validation | Use the example inputs in this repository and a local checkpoint to verify the inference workflow end to end |
| Mini training workflow validation | Use data/data_mini/genome_data/ to validate the training scripts, data loading, and checkpoint workflow |
| Cluster training adaptation | Use scripts/train_slurm.py to run training in a Slurm/cluster environment |
| Data preprocessing | Generate the .bin/.idx data required by the Byte-Level tokenizer from FASTA/JSON data |
Usage
1. Using OneCode
You can try intelligent one-click AI4S programming through the OneCode online environment:
Try intelligent one-click AI4S programming
2. Manual Installation and Usage
Hardware Requirements
- Running on a GPU or DCU is recommended.
- A CPU can be used for import checks and small-configuration connectivity validation, but full training and inference will be slow.
- DCU users need to install DTK in advance. DTK 25.04.2 or later is recommended, or the OneScience-recommended version that matches the current cluster.
Download the Model Package
hf download OneScience-Group/evo2 --local-dir ./evo2
cd evo2
Install the Runtime Environment
DCU Environment
# Activate DTK and CONDA first
conda create -n onescience311 python=3.11 -y
conda activate onescience311
# uv installation is supported
pip install onescience[bio] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai
If the scripts need to access the OneScience source code, set:
export ONESCIENCE_ROOT=/path/to/onescience
When run from this directory, the scripts automatically add the project root and model/ to sys.path. You can also manually verify that the local package can be imported:
export PYTHONPATH=$(pwd)/model:${PYTHONPATH:-}
python -c "import evo2; print('evo2 import ok')"
3. Quick Start
Quick Checks
View the entry-point arguments:
python scripts/infer.py --help
python scripts/predict.py --help
python scripts/train.py --help
python scripts/train_slurm.py --help
4. Data and Weights
The example training data has been placed at:
data/data_mini/genome_data/
It contains:
chr20.fa,chr21.fa,chr22.fa, and their compressed versions- Merged FASTA:
chr20_21_22.fa - Preprocessed binary data for training, validation, and testing:
preprocessed_data/
The dataset_prefix in config/genome_data_config.yaml is a relative path. During actual runs, it should be used together with:
--dataset-dir data/data_mini/genome_data
By default, the 7B NeMo checkpoint is placed inside the repository:
checkpoints/evo2_nemo_7b/
The inference and prediction entry points read this directory by default; training does not load a checkpoint by default. To fine-tune from existing weights or resume training, explicitly pass --ckpt-dir checkpoints/evo2_nemo_7b in the training command. You can also use EVO2_CKPT_DIR or --ckpt-dir to override it with another checkpoint path:
export EVO2_CKPT_DIR=/path/to/evo2_nemo_7b
The weight files are located under /path/to/evo2/checkpoints/evo2_nemo_7b/weights.
5. Prompt-Based Generation Inference
infer.py writes results to --output-file, but it does not automatically create the parent directory. Create the output directory before the first run:
mkdir -p outputs
Minimal example:
python scripts/infer.py \
--prompt "ATGCGT" \
--output-file outputs/evo2_generation.txt
Common parameters:
| Parameter | Default | Description |
|---|---|---|
--ckpt-dir |
checkpoints/evo2_nemo_7b |
NeMo checkpoint directory; can be overridden with EVO2_CKPT_DIR |
--prompt |
Built-in E. coli classification-label prompt | Input sequence or text prompt |
--max-new-tokens |
1024 |
Maximum number of tokens to generate |
--temperature |
1.0 |
Sampling temperature |
--top-k |
0 |
top-k sampling |
--top-p |
0.0 |
top-p sampling |
--tensor-parallel-size |
1 |
Tensor parallel size |
--output-file |
Empty | Write to a file when specified; otherwise print logs |
6. FASTA Prediction
The directory includes an example FASTA:
data/predict_example.fa
Run prediction:
python scripts/predict.py \
--fasta data/predict_example.fa \
--output-dir outputs/predict
predict.py automatically creates --output-dir. If --fasta is not passed, it reads data/predict_example.fa by default; if --output-dir is not passed, it writes output to outputs/predict by default.
Common parameters:
| Parameter | Default | Description |
|---|---|---|
--fasta |
data/predict_example.fa |
Input FASTA file |
--ckpt-dir |
checkpoints/evo2_nemo_7b |
NeMo checkpoint directory; can be overridden with EVO2_CKPT_DIR |
--output-dir |
outputs/predict |
Prediction result directory |
--batch-size |
1 |
Prediction batch size |
--model-size |
7b |
Model specification; available values are determined by NeMo HYENA_MODEL_OPTIONS |
--output-log-prob-seqs |
Disabled | Output sequence log probability |
data/data_mini/genome_data/chr20.fa, chr21.fa, and chr22.fa are relatively large chromosome-level FASTA files. Direct prediction may consume substantial GPU memory. It is recommended to split them into shorter fragments first, or use a multi-GPU parallel configuration.
7. Training
The training entry point requires one of two options: pass -d/--dataset-config, or use --mock-data. For the built-in example data, config/genome_data_config.yaml and data/data_mini/genome_data are recommended.
Example for training the 1B architecture from scratch or validating the training workflow:
python scripts/train.py \
-d config/genome_data_config.yaml \
--dataset-dir data/data_mini/genome_data \
--model-size 1b \
--result-dir results_1b \
--devices 8 \
--num-nodes 1 \
--seq-length 8192 \
--micro-batch-size 2 \
--lr 0.0001 \
--warmup-steps 5 \
--max-steps 1000 \
--clip-grad 1 \
--wd 0.01 \
--activation-checkpoint-recompute-num-layers 1 \
--val-check-interval 50 \
--limit-val-batches 2
This example does not load a checkpoint and is suitable for validating the training workflow when 1B weights are unavailable. To fine-tune from a 1B NeMo checkpoint, additionally pass --ckpt-dir /path/to/evo2_nemo_1b.
Example for training the 7B long-context architecture from scratch or validating the training workflow:
python scripts/train.py \
-d config/genome_data_config.yaml \
--dataset-dir data/data_mini/genome_data \
--model-size 7b_arc_longcontext \
--result-dir results_7b \
--devices 8 \
--num-nodes 1 \
--seq-length 1024 \
--micro-batch-size 1 \
--lr 0.0001 \
--warmup-steps 5 \
--max-steps 1000 \
--clip-grad 1 \
--wd 0.01 \
--activation-checkpoint-recompute-num-layers 1 \
--val-check-interval 50 \
--limit-val-batches 2
This example does not load a checkpoint. If you need to fine-tune from an existing 7B NeMo checkpoint or resume training, additionally pass --ckpt-dir checkpoints/evo2_nemo_7b or another checkpoint path.
In a Slurm/cluster environment, replace the entry point with:
python scripts/train_slurm.py ...
Common training parameters:
The table below covers the main parameters used in the training examples above and in scripts/train_evo2_1b.sh and scripts/train_evo2_7b.sh. For more advanced parameters, run python scripts/train.py --help.
| Parameter | Default | Description |
|---|---|---|
-d, --dataset-config |
Required, or use --mock-data |
Training data configuration YAML |
--mock-data |
Disabled | Do not read real data; use mock data for connectivity testing. Mutually exclusive with -d/--dataset-config |
--dataset-dir |
EVO2_DATASET_DIR or data/data_mini/genome_data |
Data root directory |
--ckpt-dir |
Empty | Initial checkpoint directory; pass explicitly when fine-tuning from existing weights or resuming training |
--model-size |
7b |
Model specification. Common values include 1b, 7b, and 7b_arc_longcontext; use test for testing |
--devices |
1 |
Number of devices on a single node |
--num-nodes |
1 |
Number of nodes |
--tensor-parallel-size |
1 |
Tensor parallel size |
--pipeline-model-parallel-size |
1 |
Pipeline model parallel size |
--context-parallel-size |
1 |
Context parallel size |
--sequence-parallel |
Disabled | Enable sequence parallel, usually used together with tensor parallelism |
--seq-length |
8192 |
Training sequence length |
--micro-batch-size |
1 |
Micro batch size |
--global-batch-size |
Automatically inferred | Global batch size |
--grad-acc-batches |
1 |
Number of gradient accumulation batches, used to infer the global batch size |
--lr |
3e-4 |
Learning rate, explicitly set to 0.0001 in the examples |
--min-lr |
3e-5 |
Minimum learning rate of the cosine scheduler |
--warmup-steps |
2500 |
Number of warmup steps, explicitly set to 5 in the examples |
--constant-steps |
80000 |
Number of steps for which the learning rate stays constant |
--max-steps |
500000 |
Number of training steps |
--wd |
0.01 |
Optimizer weight decay |
--clip-grad |
1.0 |
Gradient clipping threshold |
--workers |
8 |
Number of DataLoader workers |
--activation-checkpoint-recompute-num-layers |
Empty | Override the number of activation recomputation layers; explicitly set to 1 in the examples |
--val-check-interval |
Empty | Validation and checkpoint check interval; explicitly set to 50 in the examples |
--limit-val-batches |
20 |
Maximum number of batches to run per validation; explicitly set to 2 in the examples |
--result-dir |
./results |
Log and result directory |
--experiment-name |
evo2 |
Experiment name, which affects the log directory |
--disable-checkpointing |
Not passed by default; checkpoint callback enabled | Pass this parameter during connectivity tests to disable the checkpoint callback |
--no-save-last-checkpoint |
Save the last checkpoint by default | Disable saving the last checkpoint; often used together with --disable-checkpointing for quick tests |
--save-top-k |
5 |
Number of best checkpoints to save |
--ckpt-async-save |
Disabled | Enable asynchronous checkpoint saving |
8. Data Preprocessing
The current example training data has already been preprocessed. To process new FASTA or JSON data, use:
bash scripts/tools/data_process/preprocess_data_fasta.sh
bash scripts/tools/data_process/preprocess_data_json.sh
Related configurations:
config/genome_preprocess_config.yaml
config/genome_data_config.yaml
Official OneScience Information
| Platform | OneScience Main Repository | Skills Repository |
|---|---|---|
| Gitee | https://gitee.com/onescience-ai/onescience | https://gitee.com/onescience-ai/oneskills |
| GitHub | https://github.com/onescience-ai/OneScience | https://github.com/onescience-ai/oneskills |
Citations and License
- Original Evo2 paper: Genome modelling and design across all domains of life with Evo 2.
- The original Evo2 code uses the Apache License 2.0. See
LICENSEin this repository. Original license source: ArcInstitute/evo2 LICENSE. - The Evo2 7B model weights are sourced from Hugging Face
arcinstitute/evo2_7b. In this repository,checkpoints/evo2_nemo_7bis the converted NeMo checkpoint format. The original weight license is Apache-2.0. - The example dataset
data/data_mini/genome_data/was downloaded and preprocessed from the hg38chr20,chr21, andchr22chromosome FASTA files provided by the UCSC Genome Browser. It is used only to validate the training and inference workflows. See the data download directory: UCSC hg38 chromosomes. - Use of UCSC hg38 data must comply with the UCSC Genome Browser data usage terms. See: UCSC Terms of Use.
- If you use this repository, the model weights, or generated results in research, it is recommended to cite the original Evo2 paper, the model weight source, the UCSC hg38 data source, and relevant OneScience project information, and to add citations for downstream analysis tools or datasets according to the actual task.
中文说明
模型简介
Evo2 是一个面向基因组序列的大规模基础模型。它可以对 DNA/RNA 序列进行生成、补全和功能预测。该模型支持在大规模基因组数据集上进行预训练,并可快速适配到调控元件预测、变异效应评估等下游任务,为基因组学研究提供统一的序列建模工具。
模型描述
Evo2 基于一种将 Hyena 算子与卷积门控相结合的混合架构构建,支持百万 token 量级的上下文窗口。该模型在包含数万亿碱基对的多物种基因组数据上完成预训练。它以原始核苷酸序列作为输入,支持自回归生成、序列分类和嵌入提取。Evo2 兼容多 GPU 分布式训练和灵活的数据混合,在 GenBench 等基准上达到领先性能,适用于预训练、微调(fine-tuning)和下游功能验证。
适用场景
| 场景 | 描述 |
|---|---|
| DNA/RNA 序列生成 | 根据输入提示生成后续的基因组序列片段 |
| FASTA 序列预测 | 读取 FASTA 输入并输出序列预测结果 |
| 本地离线推理(inference)验证 | 使用本仓库中的示例输入和本地模型权重(检查点)端到端验证推理流程 |
| 迷你训练流程验证 | 使用 data/data_mini/genome_data/ 验证训练脚本、数据加载和检查点流程 |
| 集群训练适配 | 使用 scripts/train_slurm.py 在 Slurm/集群环境中运行训练 |
| 数据预处理 | 从 FASTA/JSON 数据生成 Byte-Level 分词器所需的 .bin/.idx 数据 |
使用方法
1. 使用 OneCode
你可以通过 OneCode 在线环境体验一键式 AI4S 智能编程:
2. 手动安装与使用
硬件要求
- 建议在 GPU 或 DCU 上运行。
- CPU 可用于导入检查和小配置的连通性验证,但完整的训练和推理会很慢。
- DCU 用户需提前安装 DTK。建议使用 DTK 25.04.2 或更高版本,或与当前集群匹配的 OneScience 推荐版本。
下载模型包
hf download OneScience-Group/evo2 --local-dir ./evo2
cd evo2
安装运行环境
DCU 环境
# Activate DTK and CONDA first
conda create -n onescience311 python=3.11 -y
conda activate onescience311
# uv installation is supported
pip install onescience[bio] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai
如果脚本需要访问 OneScience 源代码,请设置:
export ONESCIENCE_ROOT=/path/to/onescience
从该目录运行时,脚本会自动将项目根目录和 model/ 添加到 sys.path。你也可以手动验证本地包能否被导入:
export PYTHONPATH=$(pwd)/model:${PYTHONPATH:-}
python -c "import evo2; print('evo2 import ok')"
3. 快速开始
快速检查
查看入口参数:
python scripts/infer.py --help
python scripts/predict.py --help
python scripts/train.py --help
python scripts/train_slurm.py --help
4. 数据与权重
示例训练数据已放置于:
data/data_mini/genome_data/
其中包含:
chr20.fa、chr21.fa、chr22.fa及其压缩版本- 合并后的 FASTA:
chr20_21_22.fa - 用于训练、验证和测试的预处理二进制数据:
preprocessed_data/
config/genome_data_config.yaml 中的 dataset_prefix 是相对路径。在实际运行时,应与以下项配合使用:
--dataset-dir data/data_mini/genome_data
默认情况下,7B NeMo 检查点放置在仓库内:
checkpoints/evo2_nemo_7b/
推理和预测入口默认读取该目录;训练默认不加载检查点。若要从已有权重微调或恢复训练,请在训练命令中显式传入 --ckpt-dir checkpoints/evo2_nemo_7b。你也可以使用 EVO2_CKPT_DIR 或 --ckpt-dir 将其覆盖为其他检查点路径:
export EVO2_CKPT_DIR=/path/to/evo2_nemo_7b
权重文件位于 /path/to/evo2/checkpoints/evo2_nemo_7b/weights 下。
5. 基于提示的生成式推理
infer.py 将结果写入 --output-file,但不会自动创建父目录。首次运行前请先创建输出目录:
mkdir -p outputs
最小示例:
python scripts/infer.py \
--prompt "ATGCGT" \
--output-file outputs/evo2_generation.txt
常用参数:
| 参数 | 默认值 | 描述 |
|---|---|---|
--ckpt-dir |
checkpoints/evo2_nemo_7b |
NeMo 检查点目录;可通过 EVO2_CKPT_DIR 覆盖 |
--prompt |
内置的 E. coli 分类标签提示 | 输入序列或文本提示 |
--max-new-tokens |
1024 |
生成的最大 token 数 |
--temperature |
1.0 |
采样温度 |
--top-k |
0 |
top-k 采样 |
--top-p |
0.0 |
top-p 采样 |
--tensor-parallel-size |
1 |
张量并行大小 |
--output-file |
空 | 指定时写入文件;否则打印日志 |
6. FASTA 预测
该目录包含一个示例 FASTA:
data/predict_example.fa
运行预测:
python scripts/predict.py \
--fasta data/predict_example.fa \
--output-dir outputs/predict
predict.py 会自动创建 --output-dir。如果未传入 --fasta,默认读取 data/predict_example.fa;如果未传入 --output-dir,默认将输出写入 outputs/predict。
常用参数:
| 参数 | 默认值 | 描述 |
|---|---|---|
--fasta |
data/predict_example.fa |
输入 FASTA 文件 |
--ckpt-dir |
checkpoints/evo2_nemo_7b |
NeMo 检查点目录;可通过 EVO2_CKPT_DIR 覆盖 |
--output-dir |
outputs/predict |
预测结果目录 |
--batch-size |
1 |
预测批大小 |
--model-size |
7b |
模型规格;可用取值由 NeMo HYENA_MODEL_OPTIONS 决定 |
--output-log-prob-seqs |
关闭 | 输出序列对数概率 |
data/data_mini/genome_data/chr20.fa、chr21.fa 和 chr22.fa 是相对较大的染色体级 FASTA 文件。直接预测可能会占用大量显存。建议先将其切分为较短的片段,或使用多 GPU 并行配置。
7. 训练
训练入口需要二选一:传入 -d/--dataset-config,或使用 --mock-data。对于内置示例数据,推荐使用 config/genome_data_config.yaml 和 data/data_mini/genome_data。
从零训练 1B 架构或验证训练流程的示例:
python scripts/train.py \
-d config/genome_data_config.yaml \
--dataset-dir data/data_mini/genome_data \
--model-size 1b \
--result-dir results_1b \
--devices 8 \
--num-nodes 1 \
--seq-length 8192 \
--micro-batch-size 2 \
--lr 0.0001 \
--warmup-steps 5 \
--max-steps 1000 \
--clip-grad 1 \
--wd 0.01 \
--activation-checkpoint-recompute-num-layers 1 \
--val-check-interval 50 \
--limit-val-batches 2
该示例不加载检查点,适用于在没有 1B 权重时验证训练流程。若要从 1B NeMo 检查点微调,请额外传入 --ckpt-dir /path/to/evo2_nemo_1b。
从零训练 7B 长上下文架构或验证训练流程的示例:
python scripts/train.py \
-d config/genome_data_config.yaml \
--dataset-dir data/data_mini/genome_data \
--model-size 7b_arc_longcontext \
--result-dir results_7b \
--devices 8 \
--num-nodes 1 \
--seq-length 1024 \
--micro-batch-size 1 \
--lr 0.0001 \
--warmup-steps 5 \
--max-steps 1000 \
--clip-grad 1 \
--wd 0.01 \
--activation-checkpoint-recompute-num-layers 1 \
--val-check-interval 50 \
--limit-val-batches 2
该示例不加载检查点。如果需要从已有的 7B NeMo 检查点微调或恢复训练,请额外传入 --ckpt-dir checkpoints/evo2_nemo_7b 或其他检查点路径。
在 Slurm/集群环境中,请将入口替换为:
python scripts/train_slurm.py ...
常用训练参数:
下表涵盖上述训练示例以及 scripts/train_evo2_1b.sh 和 scripts/train_evo2_7b.sh 中使用的主要参数。更多高级参数请运行 python scripts/train.py --help。
| 参数 | 默认值 | 描述 |
|---|---|---|
-d, --dataset-config |
必填,或使用 --mock-data |
训练数据配置 YAML |
--mock-data |
关闭 | 不读取真实数据;使用模拟数据进行连通性测试。与 -d/--dataset-config 互斥 |
--dataset-dir |
EVO2_DATASET_DIR 或 data/data_mini/genome_data |
数据根目录 |
--ckpt-dir |
空 | 初始检查点目录;从已有权重微调或恢复训练时显式传入 |
--model-size |
7b |
模型规格。常用取值包括 1b、7b 和 7b_arc_longcontext;测试时使用 test |
--devices |
1 |
单节点上的设备数量 |
--num-nodes |
1 |
节点数量 |
--tensor-parallel-size |
1 |
张量并行大小 |
--pipeline-model-parallel-size |
1 |
流水线模型并行大小 |
--context-parallel-size |
1 |
上下文并行大小 |
--sequence-parallel |
关闭 | 启用序列并行,通常与张量并行配合使用 |
--seq-length |
8192 |
训练序列长度 |
--micro-batch-size |
1 |
微批大小 |
--global-batch-size |
自动推断 | 全局批大小 |
--grad-acc-batches |
1 |
梯度累积的批数量,用于推断全局批大小 |
--lr |
3e-4 |
学习率,示例中显式设为 0.0001 |
--min-lr |
3e-5 |
余弦调度器的最小学习率 |
--warmup-steps |
2500 |
预热步数,示例中显式设为 5 |
--constant-steps |
80000 |
学习率保持恒定的步数 |
--max-steps |
500000 |
训练步数 |
--wd |
0.01 |
优化器权重衰减 |
--clip-grad |
1.0 |
梯度裁剪阈值 |
--workers |
8 |
DataLoader 工作进程数 |
--activation-checkpoint-recompute-num-layers |
空 | 覆盖激活重计算的层数;示例中显式设为 1 |
--val-check-interval |
空 | 验证与检查点的检查间隔;示例中显式设为 50 |
--limit-val-batches |
20 |
每次验证运行的最大批数;示例中显式设为 2 |
--result-dir |
./results |
日志和结果目录 |
--experiment-name |
evo2 |
实验名称,会影响日志目录 |
--disable-checkpointing |
默认不传入;启用检查点回调 | 在连通性测试时传入该参数以禁用检查点回调 |
--no-save-last-checkpoint |
默认保存最后一个检查点 | 禁用保存最后一个检查点;常与 --disable-checkpointing 配合用于快速测试 |
--save-top-k |
5 |
保存的最佳检查点数量 |
--ckpt-async-save |
关闭 | 启用异步检查点保存 |
8. 数据预处理
当前的示例训练数据已经过预处理。若要处理新的 FASTA 或 JSON 数据,请使用:
bash scripts/tools/data_process/preprocess_data_fasta.sh
bash scripts/tools/data_process/preprocess_data_json.sh
相关配置:
config/genome_preprocess_config.yaml
config/genome_data_config.yaml
OneScience 官方信息
| 平台 | OneScience 主仓库 | Skills 仓库 |
|---|---|---|
| Gitee | https://gitee.com/onescience-ai/onescience | https://gitee.com/onescience-ai/oneskills |
| GitHub | https://github.com/onescience-ai/OneScience | https://github.com/onescience-ai/oneskills |
引用与许可
- Evo2 原始论文:Genome modelling and design across all domains of life with Evo 2。
- Evo2 原始代码使用 Apache License 2.0。参见本仓库中的
LICENSE。原始许可证来源:ArcInstitute/evo2 LICENSE。 - Evo2 7B 模型权重来源于 Hugging Face
arcinstitute/evo2_7b。在本仓库中,checkpoints/evo2_nemo_7b是转换后的 NeMo 检查点格式。原始权重许可证为 Apache-2.0。 - 示例数据集
data/data_mini/genome_data/是从 UCSC Genome Browser 提供的 hg38chr20、chr21、chr22染色体 FASTA 文件下载并预处理而来。它仅用于验证训练和推理流程。参见数据下载目录:UCSC hg38 chromosomes。 - 使用 UCSC hg38 数据必须遵守 UCSC Genome Browser 的数据使用条款。参见:UCSC Terms of Use。
- 如果你在研究中使用本仓库、模型权重或生成结果,建议引用 Evo2 原始论文、模型权重来源、UCSC hg38 数据来源以及相关的 OneScience 项目信息,并根据实际任务补充下游分析工具或数据集的引用。
- Downloads last month
- 10