deepmd-finetune-dpa3
Fine-tune a DPA3 model in DeePMD-kit using the PyTorch backend. Use when the user wants to adapt a pre-trained DPA3 model to a new downstream dataset. Supports fine-tuning from a self-trained DPA3 model (.pt checkpoint), from a multi-task pre-trained model, or from a built-in pretrained model downloaded via `dp pretrained download` (e.g., DPA-3.1-3M, DPA-3.2-5M, DPA-3.3-1M). Covers single-task and multi-task fine-tuning workflows.
jinzhezenggroup · 已有 AI 审核记录
安装与使用
运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。
npx skills add jinzhezenggroup/computational-chemistry-agent-skills --skill deepmd-finetune-dpa3技能说明
name: deepmd-finetune-dpa3
description: Fine-tune a DPA3 model in DeePMD-kit using the PyTorch backend. Use when the user wants to adapt a pre-trained DPA3 model to a new downstream dataset. Supports fine-tuning from a self-trained DPA3 model (.pt checkpoint), from a multi-task pre-trained model, or from a built-in pretrained model downloaded via dp pretrained download (e.g., DPA-3.1-3M, DPA-3.2-5M, DPA-3.3-1M). Covers single-task and multi-task fine-tuning workflows.
compatibility: Requires deepmd-kit with PyTorch backend installed. GPU strongly recommended.
license: LGPL-3.0-or-later
metadata:
author: iProzd
version: '1.0'
repository: https://github.com/deepmodeling/deepmd-kit
DeePMD-kit Fine-tuning: DPA3
Fine-tune a pre-trained DPA3 model on a downstream dataset. This skill covers three scenarios:
- Fine-tuning from a self-trained single-task DPA3 model
- Fine-tuning from a multi-task pre-trained DPA3 model
- Fine-tuning from a built-in pretrained model (e.g., DPA-3.1-3M, DPA-3.2-5M, DPA-3.3-1M) downloaded via
dp pretrained download
Quick Start
# Fine-tune from a self-trained model
dp --pt train input.json --finetune pretrained.pt --use-pretrain-script
# Fine-tune from a built-in pretrained model
dp pretrained download DPA-3.2-5M
dp --pt train input.json --finetune /path/to/DPA-3.2-5M.pt --use-pretrain-script --model-branch OMat24
Agent Responsibilities
- Determine the fine-tuning scenario:
- Does the user have a self-trained
.ptmodel? - Does the user want to use a built-in pretrained model (DPA-3.1-3M, DPA-3.2-5M, DPA-3.3-1M, etc.)?
- Is the pre-trained model single-task or multi-task?
- Does the user have a self-trained
- If using a built-in pretrained model, download it first with
dp pretrained download. - Collect the downstream training data paths and element types.
- Generate the fine-tuning
input.json. - Run fine-tuning and monitor the learning curve.
- Freeze and test the fine-tuned model.
Scenario 1: Fine-tune from a Self-trained Single-task Model
When you have trained a DPA3 model yourself and want to adapt it to new data.
Step 1: Prepare input.json
When using --use-pretrain-script, the model architecture is inherited from the pre-trained model. You only need to specify type_map, data paths, and training parameters:
{
"model": {
"type_map": [
"O",
"H"
],
"descriptor": {},
"fitting_net": {}
},
"learning_rate": {
"type": "exp",
"decay_steps": 5000,
"start_lr": 0.0001,
"stop_lr": 3e-06
},
"loss": {
"type": "ener",
"start_pref_e": 0.2,
"limit_pref_e": 20,
"start_pref_f": 100,
"limit_pref_f": 60,
"start_pref_v": 0.02,
"limit_pref_v": 1
},
"optimizer": {
"type": "AdamW",
"weight_decay": 0.001
},
"training": {
"training_data": {
"systems": [
"./downstream_data/train_0",
"./downstream_data/train_1"
],
"batch_size": 1
},
"validation_data": {
"systems": [
"./downstream_data/valid_0"
],
"batch_size": 1
},
"numb_steps": 200000,
"gradient_max_norm": 5.0,
"seed": 10,
"disp_file": "lcurve.out",
"disp_freq": 100,
"save_freq": 2000
}
}
Fine-tuning tips:
- Use a smaller
start_lr(e.g., 1e-4) than training from scratch (1e-3). - Use fewer
numb_stepssince the model is already pre-trained. - The elements in the downstream data must be a subset of the pre-trained model's
type_map.
Step 2: Run Fine-tuning
dp --pt train input.json --finetune pretrained.pt --use-pretrain-script
The --use-pretrain-script flag tells DeePMD-kit to inherit the model architecture from the pre-trained model, so the descriptor and fitting_net sections in input.json can be empty.
Without --use-pretrain-script, the model section in input.json must exactly match the pre-trained model's architecture.
Scenario 2: Fine-tune from a Multi-task Pre-trained Model
When the pre-trained model was trained with multiple datasets (multi-task training), you can select a specific branch to fine-tune from.
Check Available Branches
dp --pt show multitask_pretrained.pt model-branch
Run Fine-tuning from a Specific Branch
dp --pt train input.json --finetune multitask_pretrained.pt --model-branch CHOSEN_BRANCH --use-pretrain-script
If --model-branch is not set or set to RANDOM, a randomly initialized fitting net will be used.
Multi-task Fine-tuning (Prevent Forgetting)
To retain knowledge from the pre-trained datasets during fine-tuning, use multi-task fine-tuning. Prepare a multi-task input script:
{
"model": {
"shared_dict": {
"type_map_all": [
"O",
"H",
"C",
"N"
],
"dpa3_desc": {
"type": "dpa3",
"repflow": {}
}
},
"model_dict": {
"pre_data_1": {
"type_map": "type_map_all",
"descriptor": "dpa3_desc",
"fitting_net": {}
},
"pre_data_2": {
"type_map": "type_map_all",
"descriptor": "dpa3_desc",
"fitting_net": {}
},
"downstream": {
"finetune_head": "pre_data_1",
"type_map": "type_map_all",
"descriptor": "dpa3_desc",
"fitting_net": {}
}
}
},
"learning_rate": {
"type": "exp",
"decay_steps": 5000,
"start_lr": 0.0001,
"stop_lr": 3e-06
},
"loss_dict": {
"pre_data_1": {
"type": "ener",
"start_pref_e": 0.2,
"limit_pref_e": 20,
"start_pref_f": 100,
"limit_pref_f": 60
},
"pre_data_2": {
"type": "ener",
"start_pref_e": 0.2,
"limit_pref_e": 20,
"start_pref_f": 100,
"limit_pref_f": 60
},
"downstream": {
"type": "ener",
"start_pref_e": 0.2,
"limit_pref_e": 20,
"start_pref_f": 100,
"limit_pref_f": 60
}
},
"training": {
"model_prob": {
"pre_data_1": 0.3,
阅读完整来源 ↗