OneScience commited on
Commit
3244915
·
verified ·
1 Parent(s): 3a9e0aa

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <p align="center">
2
+ <strong>
3
+ <span style="font-size: 30px;">DeePMD</span>
4
+ </strong>
5
+ </p>
6
+
7
+ # Model Introduction
8
+
9
+ DeePMD is a Deep Potential Molecular Dynamics model ecosystem for machine-learning potential function training of atomic systems. It provides a minimal runnable training entry point based on PyTorch/TensorFlow backends.
10
+
11
+ Reference implementation: DeepMD-kit project
12
+
13
+ # Model Description
14
+
15
+ DeePMD is based on a deep neural network architecture and is trained on atomic-system data. It performs interatomic potential function training and molecular dynamics simulation for molecular and materials systems.
16
+
17
+ # Applicable Scenarios
18
+
19
+ | Scenario | Description |
20
+ | :---: | :--- |
21
+ | DeePMD water training | Train the water potential using configurations such as `demo/water_se_e2_a_pt/input_torch.json` |
22
+ | Multi-GPU SLURM submission | Refer to `demo/water_se_e2_a_pt/submit_4card.sh` and `submit_8card.sh` |
23
+ | Environment connectivity check | Run `dp_install.sh` to check whether DeepMD-kit can be installed |
24
+ | Custom data migration | Replace the `systems` paths in the configuration file with your own DeepMD npy data |
25
+
26
+ # Usage Instructions
27
+
28
+ ## 1. Using OneCode
29
+
30
+ You can try out intelligent one-click AI4S programming in the OneCode online environment:
31
+
32
+ [Try intelligent one-click AI4S programming](https://web-2069360198568017922-iaaj.ksai.scnet.cn:58043/home)
33
+
34
+ ## 2. Manual Installation and Usage
35
+
36
+ **Hardware Requirements**
37
+
38
+ - GPU or DCU is recommended for training.
39
+ - CPU can be used for installation checks and small-data connectivity verification; full training will be slow.
40
+ - DCU users need to install DTK in advance. DTK 25.04.2 or above, or the OneScience-recommended version matching the current cluster, is suggested.
41
+
42
+ ### Download the Model Package
43
+
44
+ ```bash
45
+ modelscope download --model OneScience/DeePMD --local_dir ./deepmd
46
+ cd deepmd
47
+ ```
48
+
49
+ ### Install the Runtime Environment
50
+
51
+ **DCU Environment**
52
+
53
+ ```bash
54
+ # Please activate DTK and CONDA first
55
+ conda create -n onescience311 python=3.11 -y
56
+ conda activate onescience311
57
+ # uv installation is also supported
58
+ pip install onescience[matchem-dcu] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai
59
+ ```
60
+
61
+ **GPU Environment**
62
+
63
+ ```bash
64
+ # Please activate CONDA first
65
+ conda create -n onescience311 python=3.11 -y libstdcxx-ng=12 libgcc-ng=12 gcc_linux-64=12 gxx_linux-64=12
66
+ conda activate onescience311
67
+ # uv installation is also supported
68
+ pip install onescience[matchem-gpu] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai
69
+ ```
70
+
71
+ ### Install DeepMD-kit
72
+
73
+ ```bash
74
+ # Uses the test_pip environment by default; if you use another conda environment name, please specify it first:
75
+ # export MATCHEM_CONDA_NAME=your_env
76
+ bash dp_install.sh
77
+ ```
78
+
79
+ ### Training Data Description
80
+
81
+ This repository does not include built-in training data. Taking the DeePMD water dataset as an example, download it from ModelScope and place it under `data/` in the repository root:
82
+
83
+ ```bash
84
+ modelscope download --dataset OneScience/DeePMD --local_dir ./data
85
+ ```
86
+
87
+ After downloading, the data path will be `data/DeePMD/water/data_0..3/`.
88
+
89
+ ### Training
90
+
91
+ Single-GPU:
92
+
93
+ ```bash
94
+ cd demo/water_se_e2_a_pt
95
+ dp --pt train input_torch.json
96
+ ```
97
+
98
+ Multi-GPU:
99
+
100
+ ```bash
101
+ cd demo/water_se_e2_a_pt
102
+ bash submit_4card.sh
103
+ ```
104
+
105
+ ### Training Weights
106
+
107
+ This repository currently does not include built-in trained weights. Weights can be obtained through the training steps above.
108
+
109
+ # OneScience Official Information
110
+
111
+ | Platform | OneScience Main Repository | Skills Repository |
112
+ | --- | --- | --- |
113
+ | Gitee | https://gitee.com/onescience-ai/onescience | https://gitee.com/onescience-ai/oneskills |
114
+ | GitHub | https://github.com/onescience-ai/OneScience | https://github.com/onescience-ai/oneskills |
115
+
116
+ # Citation and License
117
+
118
+ - The DeePMD example code comes from the matchem example implementation in the OneScience project and references the upstream DeepMD-kit project. For upstream DeepMD-kit licensing information, please refer to its official repository.
119
+ - If you use DeePMD training results in scientific research, we recommend citing DeepMD-kit, the relevant OneScience project information, and the sources of the datasets actually used.
demo/dpa3_finetune_CH/DPA-3.1-3M.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:86dd3a804d78ca5d203ebf98747e8f16dff9713ba8950097ceb760b161e19907
3
+ size 47176032
demo/dpa3_finetune_CH/convert_ase_to_dp.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Convert ASE LMDB database to DeepMD-kit numpy format, grouped by natoms.
3
+ Non-periodic molecules are placed in a cubic box large enough to avoid
4
+ self-images across the cutoff."""
5
+
6
+ import os
7
+ import numpy as np
8
+ from ase.db import connect
9
+
10
+ TYPE_MAP = ["H", "C"]
11
+ # Largest cutoff in the DPA-3 repflow config; add margin to avoid self-images
12
+ MAX_CUTOFF = 6.0
13
+ BOX_MARGIN = 2 * MAX_CUTOFF + 4.0 # ~16 Å margin on each side
14
+
15
+ def make_cubic_box(coords):
16
+ """Build a cubic box that contains the molecule with enough margin."""
17
+ min_pos = coords.min(axis=0)
18
+ max_pos = coords.max(axis=0)
19
+ extent = (max_pos - min_pos).max()
20
+ box_len = extent + BOX_MARGIN
21
+ # Place molecule centered in the box
22
+ shift = box_len / 2.0 - (min_pos + max_pos) / 2.0
23
+ return np.eye(3) * box_len, shift
24
+
25
+ def convert_aselmdb_to_deepmd(input_file, output_base):
26
+ db = connect(input_file)
27
+ frames_by_natoms = {}
28
+ for row in db.select():
29
+ atoms = row.toatoms()
30
+ natoms = len(atoms)
31
+ atoms_type = [TYPE_MAP.index(sym) for sym in atoms.get_chemical_symbols()]
32
+ coords = atoms.get_positions()
33
+ box, shift = make_cubic_box(coords)
34
+ coords = coords + shift
35
+ frames_by_natoms.setdefault(natoms, []).append({
36
+ "coords": coords,
37
+ "types": atoms_type,
38
+ "energy": atoms.get_potential_energy(),
39
+ "forces": atoms.get_forces(),
40
+ "box": box,
41
+ })
42
+
43
+ system_dirs = []
44
+ for natoms, frames in sorted(frames_by_natoms.items()):
45
+ nframes = len(frames)
46
+ system_dir = os.path.join(output_base, f"sys_{natoms}")
47
+ set_dir = os.path.join(system_dir, "set.000")
48
+ os.makedirs(set_dir, exist_ok=True)
49
+
50
+ coord = np.stack([f["coords"] for f in frames]).reshape(nframes, -1)
51
+ force = np.stack([f["forces"] for f in frames]).reshape(nframes, -1)
52
+ energy = np.array([f["energy"] for f in frames])
53
+ box = np.stack([f["box"] for f in frames])
54
+ types = np.array(frames[0]["types"])
55
+
56
+ np.save(os.path.join(set_dir, "coord.npy"), coord)
57
+ np.save(os.path.join(set_dir, "force.npy"), force)
58
+ np.save(os.path.join(set_dir, "energy.npy"), energy)
59
+ np.save(os.path.join(set_dir, "box.npy"), box)
60
+ with open(os.path.join(system_dir, "type.raw"), "w") as f:
61
+ f.write(" ".join(map(str, types)) + "\n")
62
+
63
+ system_dirs.append(system_dir)
64
+ print(f" {system_dir}: {nframes} frames, {natoms} atoms")
65
+
66
+ print(f"Converted {input_file} -> {output_base}: {sum(len(v) for v in frames_by_natoms.values())} frames in {len(frames_by_natoms)} systems")
67
+ return system_dirs
68
+
69
+ if __name__ == "__main__":
70
+ convert_aselmdb_to_deepmd("my_data_CH_3787_train.aselmdb", "train_CH")
71
+ convert_aselmdb_to_deepmd("my_data_CH_3787_val.aselmdb", "val_CH")
demo/dpa3_finetune_CH/input_finetune.json ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_comment": "DPA-3 fine-tune on CH polymer data",
3
+ "model": {
4
+ "type_map": [
5
+ "H",
6
+ "C"
7
+ ],
8
+ "descriptor": {
9
+ "type": "dpa3",
10
+ "repflow": {
11
+ "n_dim": 128,
12
+ "e_dim": 64,
13
+ "a_dim": 32,
14
+ "nlayers": 16,
15
+ "e_rcut": 6.0,
16
+ "e_rcut_smth": 5.3,
17
+ "e_sel": 1200,
18
+ "a_rcut": 4.0,
19
+ "a_rcut_smth": 3.5,
20
+ "a_sel": 300,
21
+ "axis_neuron": 4,
22
+ "fix_stat_std": 0.3,
23
+ "a_compress_rate": 1,
24
+ "a_compress_e_rate": 2,
25
+ "a_compress_use_split": true,
26
+ "update_angle": true,
27
+ "smooth_edge_update": true,
28
+ "use_dynamic_sel": true,
29
+ "sel_reduce_factor": 10.0,
30
+ "use_exp_switch": true,
31
+ "update_style": "res_residual",
32
+ "update_residual": 0.1,
33
+ "update_residual_init": "const"
34
+ },
35
+ "activation_function": "silut:3.0",
36
+ "use_tebd_bias": false,
37
+ "precision": "float32",
38
+ "concat_output_tebd": false,
39
+ "trainable": false
40
+ },
41
+ "fitting_net": {
42
+ "neuron": [
43
+ 240,
44
+ 240,
45
+ 240
46
+ ],
47
+ "dim_case_embd": 31,
48
+ "resnet_dt": true,
49
+ "precision": "float32",
50
+ "activation_function": "silut:3.0",
51
+ "seed": 1,
52
+ "_comment": " that's all"
53
+ },
54
+ "_comment": " that's all"
55
+ },
56
+ "learning_rate": {
57
+ "type": "exp",
58
+ "decay_steps": 5000,
59
+ "start_lr": 0.0001,
60
+ "stop_lr": 3e-6,
61
+ "_comment": "that's all"
62
+ },
63
+ "loss": {
64
+ "type": "ener",
65
+ "start_pref_e": 0.2,
66
+ "limit_pref_e": 20,
67
+ "start_pref_f": 100,
68
+ "limit_pref_f": 60,
69
+ "start_pref_v": 0.02,
70
+ "limit_pref_v": 1,
71
+ "_comment": " that's all"
72
+ },
73
+ "training": {
74
+ "stat_file": "./dpa3.hdf5",
75
+ "training_data": {
76
+ "systems": [
77
+ "$/public/share/sugonhpcapp01/onestore/onedatasets/matchem/dpa3/CH_3787/train_CH"
78
+ ],
79
+ "rglob_patterns": [
80
+ "sys_*"
81
+ ],
82
+ "batch_size": 1,
83
+ "_comment": "that's all"
84
+ },
85
+ "validation_data": {
86
+ "systems": [
87
+ "$/public/share/sugonhpcapp01/onestore/onedatasets//matchem/dpa3/CH_3787/val_CH"
88
+ ],
89
+ "rglob_patterns": [
90
+ "sys_*"
91
+ ],
92
+ "batch_size": 1,
93
+ "_comment": "that's all"
94
+ },
95
+ "numb_steps": 10000,
96
+ "warmup_steps": 0,
97
+ "gradient_max_norm": 5.0,
98
+ "seed": 10,
99
+ "disp_file": "lcurve.out",
100
+ "disp_freq": 1000,
101
+ "save_freq": 10000,
102
+ "_comment": "that's all"
103
+ }
104
+ }
demo/dpa3_finetune_CH/submit.sh ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ #SBATCH --job-name=dpa3_finetune
3
+ #SBATCH --partition=hx1hdexclu12
4
+ #SBATCH --nodes=1
5
+ #SBATCH --ntasks-per-node=1
6
+ #SBATCH --gres=dcu:1
7
+ #SBATCH --cpus-per-task=16
8
+ #SBATCH --time=2:00:00
9
+ #SBATCH --output=slurm_%j.out
10
+ #SBATCH --error=slurm_%j.err
11
+
12
+ if [[ -n "${SCRIPT_DIR}" ]]; then
13
+ :
14
+ elif [[ -n "${SLURM_SUBMIT_DIR}" ]]; then
15
+ SCRIPT_DIR="${SLURM_SUBMIT_DIR}"
16
+ else
17
+ echo "ERROR: 未检测到外部 SCRIPT_DIR 变量,也不在 Slurm 任务环境(SLURM_SUBMIT_DIR 为空)"
18
+ exit 1
19
+ fi
20
+ export MATCHEM_CONDA_NAME="${MATCHEM_CONDA_NAME:-test_pip}"
21
+ source "${SCRIPT_DIR}/matchem_env.sh"
22
+ echo $ONESCIENCE_DATASETS_DIR
23
+ # 限制并行度,规避 ROCm kernel launch 问题
24
+ export DP_INTRA_OP_PARALLELISM_THREADS=1
25
+ export DP_INTER_OP_PARALLELISM_THREADS=1
26
+ export OMP_NUM_THREADS=1
27
+
28
+ # 输入 JSON 使用环境变量,运行前展开为临时文件
29
+ INPUT_JSON="input_finetune.json"
30
+ EXPANDED_JSON=".${INPUT_JSON%.json}_expanded_$$.json"
31
+ trap 'rm -f "$EXPANDED_JSON"' EXIT
32
+ python3 -c "import os; open('$EXPANDED_JSON','w').write(os.path.expandvars(open('$INPUT_JSON').read()))"
33
+
34
+ dp --pt train "$EXPANDED_JSON" --finetune ./DPA-3.1-3M.pt
demo/water_se_atten_pt/input_torch.json ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model": {
3
+ "type_map": [
4
+ "O",
5
+ "H"
6
+ ],
7
+ "descriptor": {
8
+ "type": "dpa1",
9
+ "sel": 120,
10
+ "rcut_smth": 0.5,
11
+ "rcut": 6.0,
12
+ "neuron": [
13
+ 25,
14
+ 50,
15
+ 100
16
+ ],
17
+ "tebd_dim": 8,
18
+ "axis_neuron": 16,
19
+ "type_one_side": true,
20
+ "attn": 128,
21
+ "attn_layer": 2,
22
+ "attn_dotr": true,
23
+ "attn_mask": false,
24
+ "activation_function": "tanh",
25
+ "scaling_factor": 1.0,
26
+ "normalize": true,
27
+ "temperature": 1.0
28
+ },
29
+ "fitting_net": {
30
+ "neuron": [
31
+ 240,
32
+ 240,
33
+ 240
34
+ ],
35
+ "resnet_dt": true,
36
+ "seed": 1,
37
+ "_comment": " that's all"
38
+ },
39
+ "data_stat_nbatch": 20,
40
+ "_comment": " that's all"
41
+ },
42
+ "learning_rate": {
43
+ "type": "exp",
44
+ "decay_steps": 5000,
45
+ "start_lr": 0.001,
46
+ "stop_lr": 3.51e-8,
47
+ "_comment": "that's all"
48
+ },
49
+ "loss": {
50
+ "type": "ener",
51
+ "start_pref_e": 0.02,
52
+ "limit_pref_e": 1,
53
+ "start_pref_f": 1000,
54
+ "limit_pref_f": 1,
55
+ "_comment": " that's all"
56
+ },
57
+ "training": {
58
+ "stat_file": "./dpa1.hdf5",
59
+ "training_data": {
60
+ "systems": [
61
+ "/public/share/sugonhpcapp01/onestore/onedatasets/matchem/dp/water/data_0",
62
+ "/public/share/sugonhpcapp01/onestore/onedatasets/matchem/dp/water/data_1",
63
+ "/public/share/sugonhpcapp01/onestore/onedatasets/matchem/dp/water/data_2"
64
+ ],
65
+ "batch_size": 4,
66
+ "_comment": "that's all"
67
+ },
68
+ "validation_data": {
69
+ "systems": [
70
+ "/public/share/sugonhpcapp01/onestore/onedatasets/matchem/dp/water/data_3"
71
+ ],
72
+ "batch_size": 4,
73
+ "numb_btch": 3,
74
+ "_comment": "that's all"
75
+ },
76
+ "numb_steps": 1000,
77
+ "seed": 10,
78
+ "disp_file": "lcurve.out",
79
+ "disp_freq": 100,
80
+ "save_freq": 1000,
81
+ "_comment": "that's all"
82
+ },
83
+ "_comment": "that's all"
84
+ }
demo/water_se_atten_pt/submit_1card.sh ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ #SBATCH --job-name=dp_pt_atten
3
+ #SBATCH --partition=hx1hdexclu12
4
+ #SBATCH --nodes=1
5
+ #SBATCH --ntasks-per-node=1
6
+ #SBATCH --gres=dcu:1
7
+ #SBATCH --cpus-per-task=16
8
+ #SBATCH --time=2:00:00
9
+ #SBATCH --output=slurm_%j.out
10
+ #SBATCH --error=slurm_%j.err
11
+
12
+ if [[ -n "${SCRIPT_DIR}" ]]; then
13
+ :
14
+ elif [[ -n "${SLURM_SUBMIT_DIR}" ]]; then
15
+ SCRIPT_DIR="${SLURM_SUBMIT_DIR}"
16
+ else
17
+ echo "ERROR: 未检测到外部 SCRIPT_DIR 变量,也不在 Slurm 任务环境(SLURM_SUBMIT_DIR 为空)"
18
+ exit 1
19
+ fi
20
+ echo $SCRIPT_DIR
21
+
22
+ source "$SCRIPT_DIR/matchem_env.sh"
23
+
24
+ # DeepMD 训练环境已由 matchem_env.sh 覆盖
25
+
26
+ # 单卡训练
27
+
28
+ # 输入 JSON 使用环境变量,运行前展开为临时文件
29
+ INPUT_JSON="input_torch.json"
30
+ EXPANDED_JSON=".${INPUT_JSON%.json}_expanded_$$.json"
31
+ trap 'rm -f "$EXPANDED_JSON"' EXIT
32
+ python3 -c "import os; open('$EXPANDED_JSON','w').write(os.path.expandvars(open('$INPUT_JSON').read()))"
33
+
34
+ dp --pt train "$EXPANDED_JSON"
demo/water_se_atten_pt/submit_4card.sh ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ #SBATCH --job-name=dp_pt_atten_4card
3
+ #SBATCH --partition=hx1hdexclu12
4
+ #SBATCH --nodes=1
5
+ #SBATCH --ntasks-per-node=1
6
+ #SBATCH --gres=dcu:4
7
+ #SBATCH --cpus-per-task=16
8
+ #SBATCH --time=2:00:00
9
+ #SBATCH --output=slurm_4card_%j.out
10
+ #SBATCH --error=slurm_4card_%j.err
11
+
12
+ if [[ -n "${SCRIPT_DIR}" ]]; then
13
+ :
14
+ elif [[ -n "${SLURM_SUBMIT_DIR}" ]]; then
15
+ SCRIPT_DIR="${SLURM_SUBMIT_DIR}"
16
+ else
17
+ echo "ERROR: 未检测到外部 SCRIPT_DIR 变量,也不在 Slurm 任务环境(SLURM_SUBMIT_DIR 为空)"
18
+ exit 1
19
+ fi
20
+ echo $SCRIPT_DIR
21
+
22
+ source "$SCRIPT_DIR/matchem_env.sh"
23
+
24
+ # DeepMD 训练环境已由 matchem_env.sh 覆盖
25
+
26
+ # 多卡训练(4卡)
27
+ cd "$SCRIPT_DIR"
28
+
29
+ # 输入 JSON 使用环境变量,运行前展开为临时文件
30
+ INPUT_JSON="input_torch.json"
31
+ EXPANDED_JSON=".${INPUT_JSON%.json}_expanded_$$.json"
32
+ trap 'rm -f "$EXPANDED_JSON"' EXIT
33
+ python3 -c "import os; open('$EXPANDED_JSON','w').write(os.path.expandvars(open('$INPUT_JSON').read()))"
34
+
35
+ torchrun --nproc_per_node=4 -m deepmd --pt train "$EXPANDED_JSON"
demo/water_se_atten_pt/submit_8card.sh ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ #SBATCH --job-name=dp_pt_atten_8card
3
+ #SBATCH --partition=hx1hdexclu12
4
+ #SBATCH --nodes=1
5
+ #SBATCH --ntasks-per-node=1
6
+ #SBATCH --gres=dcu:8
7
+ #SBATCH --cpus-per-task=16
8
+ #SBATCH --time=2:00:00
9
+ #SBATCH --output=slurm_8card_%j.out
10
+ #SBATCH --error=slurm_8card_%j.err
11
+
12
+ if [[ -n "${SCRIPT_DIR}" ]]; then
13
+ :
14
+ elif [[ -n "${SLURM_SUBMIT_DIR}" ]]; then
15
+ SCRIPT_DIR="${SLURM_SUBMIT_DIR}"
16
+ else
17
+ echo "ERROR: 未检测到外部 SCRIPT_DIR 变量,也不在 Slurm 任务环境(SLURM_SUBMIT_DIR 为空)"
18
+ exit 1
19
+ fi
20
+ echo $SCRIPT_DIR
21
+
22
+ export MATCHEM_CONDA_NAME="${MATCHEM_CONDA_NAME:-test_pip}"
23
+ source "$SCRIPT_DIR/matchem_env.sh"
24
+
25
+ # DeepMD 训练环境已由 matchem_env.sh 覆盖
26
+
27
+ # 多卡训练(8卡)
28
+ cd "$SCRIPT_DIR"
29
+
30
+ # 输入 JSON 使用环境变量,运行前展开为临时文件
31
+ INPUT_JSON="input_torch.json"
32
+ EXPANDED_JSON=".${INPUT_JSON%.json}_expanded_$$.json"
33
+ trap 'rm -f "$EXPANDED_JSON"' EXIT
34
+ python3 -c "import os; open('$EXPANDED_JSON','w').write(os.path.expandvars(open('$INPUT_JSON').read()))"
35
+
36
+ torchrun --nproc_per_node=8 -m deepmd --pt train "$EXPANDED_JSON"
demo/water_se_e2_a_pt/input_torch.json ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model": {
3
+ "type_map": [
4
+ "O",
5
+ "H"
6
+ ],
7
+ "descriptor": {
8
+ "type": "se_e2_a",
9
+ "sel": [
10
+ 46,
11
+ 92
12
+ ],
13
+ "rcut_smth": 0.5,
14
+ "rcut": 6.0,
15
+ "neuron": [
16
+ 25,
17
+ 50,
18
+ 100
19
+ ],
20
+ "resnet_dt": false,
21
+ "axis_neuron": 16,
22
+ "type_one_side": true,
23
+ "seed": 1,
24
+ "_comment": " that's all"
25
+ },
26
+ "fitting_net": {
27
+ "neuron": [
28
+ 240,
29
+ 240,
30
+ 240
31
+ ],
32
+ "resnet_dt": true,
33
+ "seed": 1,
34
+ "_comment": " that's all"
35
+ },
36
+ "data_stat_nbatch": 20,
37
+ "_comment": " that's all"
38
+ },
39
+ "learning_rate": {
40
+ "type": "exp",
41
+ "decay_steps": 5000,
42
+ "start_lr": 0.001,
43
+ "stop_lr": 3.51e-08,
44
+ "_comment": "that's all"
45
+ },
46
+ "loss": {
47
+ "type": "ener",
48
+ "start_pref_e": 0.02,
49
+ "limit_pref_e": 1,
50
+ "start_pref_f": 1000,
51
+ "limit_pref_f": 1,
52
+ "_comment": " that's all"
53
+ },
54
+ "training": {
55
+ "stat_file": "./se_e2_a.hdf5",
56
+ "training_data": {
57
+ "systems": [
58
+ "/public/share/sugonhpcapp01/onestore/onedatasets/matchem/dp/water/data_0",
59
+ "/public/share/sugonhpcapp01/onestore/onedatasets/matchem/dp/water/data_1",
60
+ "/public/share/sugonhpcapp01/onestore/onedatasets/matchem/dp/water/data_2"
61
+ ],
62
+ "batch_size": 4,
63
+ "_comment": "that's all"
64
+ },
65
+ "validation_data": {
66
+ "systems": [
67
+ "/public/share/sugonhpcapp01/onestore/onedatasets/matchem/dp/water/data_3"
68
+ ],
69
+ "batch_size": 4,
70
+ "numb_btch": 3,
71
+ "_comment": "that's all"
72
+ },
73
+ "numb_steps": 10000,
74
+ "seed": 10,
75
+ "disp_file": "lcurve.out",
76
+ "disp_freq": 1000,
77
+ "save_freq": 10000,
78
+ "_comment": "that's all"
79
+ },
80
+ "_comment": "that's all"
81
+ }
demo/water_se_e2_a_pt/submit_1card.sh ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ #SBATCH --job-name=dp_pt_se_e2_a
3
+ #SBATCH --partition=hpctest02
4
+ #SBATCH --nodes=1
5
+ #SBATCH --ntasks-per-node=1
6
+ #SBATCH --gres=dcu:1
7
+ #SBATCH --cpus-per-task=16
8
+ #SBATCH --time=2:00:00
9
+ #SBATCH --output=slurm_%j.out
10
+ #SBATCH --error=slurm_%j.err
11
+
12
+ if [[ -n "${SCRIPT_DIR}" ]]; then
13
+ :
14
+ elif [[ -n "${SLURM_SUBMIT_DIR}" ]]; then
15
+ SCRIPT_DIR="${SLURM_SUBMIT_DIR}"
16
+ else
17
+ echo "ERROR: 未检测到外部 SCRIPT_DIR 变量,也不在 Slurm 任务环境(SLURM_SUBMIT_DIR 为空)"
18
+ exit 1
19
+ fi
20
+ echo $SCRIPT_DIR
21
+
22
+ source "$SCRIPT_DIR/matchem_env.sh"
23
+
24
+ # DeepMD 训练环境已由 matchem_env.sh 覆盖
25
+
26
+ # 单卡训练
27
+ cd "$SCRIPT_DIR"
28
+
29
+ # 输入 JSON 使用环境变量,运行前展开为临时文件
30
+ INPUT_JSON="input_torch.json"
31
+ EXPANDED_JSON=".${INPUT_JSON%.json}_expanded_$$.json"
32
+ trap 'rm -f "$EXPANDED_JSON"' EXIT
33
+ python3 -c "import os; open('$EXPANDED_JSON','w').write(os.path.expandvars(open('$INPUT_JSON').read()))"
34
+
35
+ dp --pt train "$EXPANDED_JSON"
demo/water_se_e2_a_pt/submit_4card.sh ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ #SBATCH --job-name=dp_pt_4card
3
+ #SBATCH --partition=hpctest02
4
+ #SBATCH --nodes=1
5
+ #SBATCH --ntasks-per-node=1
6
+ #SBATCH --gres=dcu:4
7
+ #SBATCH --cpus-per-task=16
8
+ #SBATCH --time=2:00:00
9
+ #SBATCH --output=slurm_4card_%j.out
10
+ #SBATCH --error=slurm_4card_%j.err
11
+
12
+ if [[ -n "${SCRIPT_DIR}" ]]; then
13
+ :
14
+ elif [[ -n "${SLURM_SUBMIT_DIR}" ]]; then
15
+ SCRIPT_DIR="${SLURM_SUBMIT_DIR}"
16
+ else
17
+ echo "ERROR: 未检测到外部 SCRIPT_DIR 变量,也不在 Slurm 任务环境(SLURM_SUBMIT_DIR 为空)"
18
+ exit 1
19
+ fi
20
+ echo $SCRIPT_DIR
21
+
22
+ source "$SCRIPT_DIR/matchem_env.sh"
23
+
24
+ # DeepMD 训练环境已由 matchem_env.sh 覆盖
25
+
26
+ # 多卡训练(4卡)
27
+ cd "$SCRIPT_DIR"
28
+
29
+ # 输入 JSON 使用环境变量,运行前展开为临时文件
30
+ INPUT_JSON="input_torch.json"
31
+ EXPANDED_JSON=".${INPUT_JSON%.json}_expanded_$$.json"
32
+ trap 'rm -f "$EXPANDED_JSON"' EXIT
33
+ python3 -c "import os; open('$EXPANDED_JSON','w').write(os.path.expandvars(open('$INPUT_JSON').read()))"
34
+
35
+ torchrun --nproc_per_node=4 -m deepmd --pt train "$EXPANDED_JSON"
demo/water_se_e2_a_pt/submit_8card.sh ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ #SBATCH --job-name=dp_pt_8card
3
+ #SBATCH --partition=hpctest02
4
+ #SBATCH --nodes=1
5
+ #SBATCH --ntasks-per-node=1
6
+ #SBATCH --gres=dcu:8
7
+ #SBATCH --cpus-per-task=16
8
+ #SBATCH --time=2:00:00
9
+ #SBATCH --output=slurm_8card_%j.out
10
+ #SBATCH --error=slurm_8card_%j.err
11
+
12
+ if [[ -n "${SCRIPT_DIR}" ]]; then
13
+ :
14
+ elif [[ -n "${SLURM_SUBMIT_DIR}" ]]; then
15
+ SCRIPT_DIR="${SLURM_SUBMIT_DIR}"
16
+ else
17
+ echo "ERROR: 未检测到外部 SCRIPT_DIR 变量,也不在 Slurm 任务环境(SLURM_SUBMIT_DIR 为空)"
18
+ exit 1
19
+ fi
20
+ echo $SCRIPT_DIR
21
+
22
+ source "$SCRIPT_DIR/matchem_env.sh"
23
+
24
+ # DeepMD 训练环境已由 matchem_env.sh 覆盖
25
+
26
+ # 多卡训练(8卡)
27
+ cd "$SCRIPT_DIR"
28
+
29
+ # 输入 JSON 使用环境变量,运行前展开为临时文件
30
+ INPUT_JSON="input_torch.json"
31
+ EXPANDED_JSON=".${INPUT_JSON%.json}_expanded_$$.json"
32
+ trap 'rm -f "$EXPANDED_JSON"' EXIT
33
+ python3 -c "import os; open('$EXPANDED_JSON','w').write(os.path.expandvars(open('$INPUT_JSON').read()))"
34
+
35
+ torchrun --nproc_per_node=8 -m deepmd --pt train "$EXPANDED_JSON"
demo/water_se_e2_a_tf/input_tf.json ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_comment1": " model parameters",
3
+ "model": {
4
+ "type_map": [
5
+ "O",
6
+ "H"
7
+ ],
8
+ "descriptor": {
9
+ "type": "se_e2_a",
10
+ "sel": [
11
+ 46,
12
+ 92
13
+ ],
14
+ "rcut_smth": 0.50,
15
+ "rcut": 6.00,
16
+ "neuron": [
17
+ 25,
18
+ 50,
19
+ 100
20
+ ],
21
+ "resnet_dt": false,
22
+ "axis_neuron": 16,
23
+ "type_one_side": true,
24
+ "precision": "float64",
25
+ "seed": 1,
26
+ "_comment2": " that's all"
27
+ },
28
+ "fitting_net": {
29
+ "neuron": [
30
+ 240,
31
+ 240,
32
+ 240
33
+ ],
34
+ "resnet_dt": true,
35
+ "precision": "float64",
36
+ "seed": 1,
37
+ "_comment3": " that's all"
38
+ },
39
+ "_comment4": " that's all"
40
+ },
41
+
42
+ "learning_rate": {
43
+ "type": "exp",
44
+ "decay_steps": 5000,
45
+ "start_lr": 0.001,
46
+ "stop_lr": 3.51e-8,
47
+ "_comment5": "that's all"
48
+ },
49
+
50
+ "loss": {
51
+ "type": "ener",
52
+ "start_pref_e": 0.02,
53
+ "limit_pref_e": 1,
54
+ "start_pref_f": 1000,
55
+ "limit_pref_f": 1,
56
+ "start_pref_v": 0,
57
+ "limit_pref_v": 0,
58
+ "_comment6": " that's all"
59
+ },
60
+
61
+ "training": {
62
+ "training_data": {
63
+ "systems": [
64
+ "/public/share/sugonhpcapp01/onestore/onedatasets/matchem/dp/water/data_0/",
65
+ "/public/share/sugonhpcapp01/onestore/onedatasets/matchem/dp/water/data_1/",
66
+ "/public/share/sugonhpcapp01/onestore/onedatasets/matchem/dp/water/data_2/"
67
+ ],
68
+ "batch_size": "auto",
69
+ "_comment7": "that's all"
70
+ },
71
+ "validation_data": {
72
+ "systems": [
73
+ "/public/share/sugonhpcapp01/onestore/onedatasets/matchem/dp/water/data_3"
74
+ ],
75
+ "batch_size": 1,
76
+ "numb_btch": 3,
77
+ "_comment8": "that's all"
78
+ },
79
+ "numb_steps": 10000,
80
+ "seed": 10,
81
+ "disp_file": "lcurve.out",
82
+ "disp_freq": 1000,
83
+ "save_freq": 10000,
84
+ "_comment9": "that's all"
85
+ },
86
+
87
+ "_comment10": "that's all"
88
+ }
demo/water_se_e2_a_tf/submit.sh ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ #SBATCH --job-name=dp_tf_train
3
+ #SBATCH --partition=hx1hdexclu12
4
+ #SBATCH --nodes=1
5
+ #SBATCH --ntasks-per-node=1
6
+ #SBATCH --gres=dcu:1
7
+ #SBATCH --cpus-per-task=16
8
+ #SBATCH --time=2:00:00
9
+ #SBATCH --output=slurm_%j.out
10
+ #SBATCH --error=slurm_%j.err
11
+
12
+ if [[ -n "${SCRIPT_DIR}" ]]; then
13
+ :
14
+ elif [[ -n "${SLURM_SUBMIT_DIR}" ]]; then
15
+ SCRIPT_DIR="${SLURM_SUBMIT_DIR}"
16
+ else
17
+ echo "ERROR: 未检测到外部 SCRIPT_DIR 变量,也不在 Slurm 任务环境(SLURM_SUBMIT_DIR 为空)"
18
+ exit 1
19
+ fi
20
+ echo $SCRIPT_DIR
21
+
22
+ export MATCHEM_CONDA_NAME="${MATCHEM_CONDA_NAME:-test_pip}"
23
+ source "$SCRIPT_DIR/matchem_env.sh"
24
+
25
+ # DeepMD 训练环境已由 matchem_env.sh 覆盖
26
+
27
+ # 限制 batch size 和线程数,规避 ROCm kernel launch 失败
28
+ export DP_INFER_BATCH_SIZE=4096
29
+ export DP_INTRA_OP_PARALLELISM_THREADS=1
30
+ export DP_INTER_OP_PARALLELISM_THREADS=1
31
+ export OMP_NUM_THREADS=1
32
+ export TF_XLA_FLAGS=""
33
+ export TF_ENABLE_XLA=0
34
+ # TF 后端单卡训练
35
+
36
+ # 输入 JSON 使用环境变量,运行前展开为临时文件
37
+ INPUT_JSON="input_tf.json"
38
+ EXPANDED_JSON=".${INPUT_JSON%.json}_expanded_$$.json"
39
+ trap 'rm -f "$EXPANDED_JSON"' EXIT
40
+ python3 -c "import os; open('$EXPANDED_JSON','w').write(os.path.expandvars(open('$INPUT_JSON').read()))"
41
+
42
+ dp --tf train "$EXPANDED_JSON"
dp_install.sh ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # -----------------------------------------------------------------------------
3
+ # DeepMD-kit DCU 一键安装脚本
4
+ # 流程:源码拉取 → 编译安装 → 安装验证
5
+ # 用法:bash dp_install.sh
6
+ # DEEPMD_SRC_DIR=/path/to/src bash dp_install.sh # 指定源码路径
7
+ # -----------------------------------------------------------------------------
8
+
9
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10
+ cd "$SCRIPT_DIR"
11
+
12
+ # 1. 环境准备
13
+ echo ">>> Step 1: 加载环境"
14
+ source "$SCRIPT_DIR/../matchem_env.sh"
15
+ module load sghpc-mpi-gcc/26.3
16
+
17
+ # 1.5 确保 gflags/glog 运行库存在(torch cmake 与 lmp_mpi 的运行时依赖,pip 环境通常缺失)
18
+ echo ">>> Step 1.5: 检查 gflags/glog 运行库"
19
+ MISSING_PKGS=""
20
+ ls "$CONDA_PREFIX"/lib/libgflags.so* >/dev/null 2>&1 || MISSING_PKGS="${MISSING_PKGS} gflags"
21
+ ls "$CONDA_PREFIX"/lib/libglog.so* >/dev/null 2>&1 || MISSING_PKGS="${MISSING_PKGS} glog"
22
+ if [ -n "${MISSING_PKGS}" ]; then
23
+ echo ">>> 安装缺失的运行库:${MISSING_PKGS}(conda-forge)"
24
+ conda install -y -c conda-forge ${MISSING_PKGS}
25
+ else
26
+ echo ">>> gflags/glog 已存在,跳过"
27
+ fi
28
+
29
+ # 下载辅助:优先 curl,失败时回退 wget(部分节点 curl 存在 TLS/代理问题)
30
+ download_file() {
31
+ local url="$1" out="$2"
32
+ if command -v curl >/dev/null 2>&1 && curl -fL -o "$out" "$url"; then
33
+ return 0
34
+ fi
35
+ echo "[提示] curl 下载失败,改用 wget: $url"
36
+ if command -v wget >/dev/null 2>&1 && wget -O "$out" "$url"; then
37
+ return 0
38
+ fi
39
+ echo "[错误] 下载失败: $url"
40
+ return 1
41
+ }
42
+
43
+ # 2. 源码准备
44
+ # 说明:
45
+ # - 开发/测试阶段:自动通过 HTTPS + 代理拉取源码
46
+ # - 生产/客户场景:建议提前上传源码到集群,通过 DEEPMD_SRC_DIR 指定
47
+ DEEPMD_SRC="${DEEPMD_SRC_DIR:-${SCRIPT_DIR}/deepmd-kit}"
48
+ if [ ! -d "$DEEPMD_SRC/.git" ] && [ ! -f "$DEEPMD_SRC/setup.py" ]; then
49
+ echo ">>> Step 2: 拉取 DeepMD-kit 源码"
50
+ # 当前集群需通过 HTTP 代理访问外网,配置 git 代理
51
+ git config --global http.proxy "http://jsyadmin:1cdf8f60@10.13.17.166:3128"
52
+ git clone --depth 1 "https://oauth2:${GITEE_TOKEN}@gitee.com/wang-rui-sugon/deepmd-kit_dcu.git" "$DEEPMD_SRC"
53
+ else
54
+ echo ">>> Step 2: 源码已存在,跳过拉取"
55
+ fi
56
+
57
+ # 3. 预先锁定 numpy 版本,避免 deepmd-kit 安装过程中短暂升级到不兼容版本
58
+ echo ">>> Step 3: 预先锁定 numpy 版本"
59
+ pip install numpy==1.26.3 --no-deps -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
60
+
61
+ # 4. 修复 Torch cmake 硬编码 DTK 路径
62
+ echo ">>> Step 4: 修复 Torch cmake 硬编码 DTK 路径"
63
+ TORCH_PATH=$(python -c "import importlib.util, os; spec = importlib.util.find_spec('torch'); print(os.path.dirname(spec.origin) if spec and spec.origin else '')")
64
+ CAFFE2_CMAKE="${TORCH_PATH}/share/cmake/Caffe2/Caffe2Targets.cmake"
65
+ DTK_REAL_PATH="/public/software/sghpc_sdk.bak/Linux_x86_64/26.3/dtk/dtk-25.04.4"
66
+ if [ -f "$CAFFE2_CMAKE" ] && grep -q '/opt/dtk' "$CAFFE2_CMAKE"; then
67
+ echo ">>> 替换 Caffe2Targets.cmake 中的 /opt/dtk 为实际路径"
68
+ sed -i "s|/opt/dtk|${DTK_REAL_PATH}|g" "$CAFFE2_CMAKE"
69
+ fi
70
+
71
+ # 5. 编译安装(PyTorch + TensorFlow 双后端)
72
+ echo ">>> Step 5: 编译安装 Python 包(PyTorch + TensorFlow 双后端)"
73
+ cd "$DEEPMD_SRC"
74
+ DP_VARIANT=rocm \
75
+ ROCM_ROOT="$ROCM_PATH" \
76
+ DP_ENABLE_TENSORFLOW=1 \
77
+ DP_ENABLE_PYTORCH=1 \
78
+ PYTORCH_ROOT="${TORCH_PATH}" \
79
+ pip install . "numpy==1.26.3" -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
80
+
81
+ # 6. 验证
82
+ echo ">>> Step 6: 验证安装"
83
+ dp -h | head -n 5
84
+
85
+ echo "========================================"
86
+ echo " DeepMD-kit Python 包安装完成"
87
+ echo "========================================"
88
+
89
+ # 7. C++ 接口安装(含 LAMMPS 插件)
90
+ # 说明:默认从预编译包下载解压,快速部署;如需自行源码编译,设置 COMPILE_DP_CPP=1。
91
+ DP_CPP_URL="https://download.sourcefind.cn:65024/file/9/onesicence/dtk-25.04.2/deep_lammps/dp_cpp_dcu.tar.gz"
92
+
93
+ if [ "${COMPILE_DP_CPP:-0}" = "1" ]; then
94
+ echo ">>> Step 7: 源码编译 C++ 接口(含 LAMMPS 插件)"
95
+
96
+ # 7.1 Patch Gelu op:TensorFlow 2.18+ 已内置 Gelu,与 deepmd-kit 自定义 op 冲突,
97
+ # 需在编译前注释掉 source/op/tf/gelu_multi_device.cc 中的 REGISTER_OP("Gelu")
98
+ # 和 REGISTER_OP("GeluGrad") 及其属性链。(GeluGradGrad / GeluCustom 系列不受影响)
99
+ GELU_FILE="$DEEPMD_SRC/source/op/tf/gelu_multi_device.cc"
100
+ if grep -q '^REGISTER_OP("Gelu")' "$GELU_FILE"; then
101
+ echo ">>> Step 7.1: Patch Gelu op 注册,避免 TF 2.18+ 冲突"
102
+ sed -i '/^REGISTER_OP("Gelu")$/,/^);$/{ /^$/!s/^/\/\/ /; }' "$GELU_FILE"
103
+ sed -i '/^REGISTER_OP("GeluGrad")$/,/^);$/{ /^$/!s/^/\/\/ /; }' "$GELU_FILE"
104
+ fi
105
+
106
+ cd "$DEEPMD_SRC/source"
107
+ mkdir -p build && cd build
108
+
109
+ cmake -DENABLE_TENSORFLOW=ON \
110
+ -DENABLE_PYTORCH=ON \
111
+ -DUSE_ROCM_TOOLKIT=ON \
112
+ -DTENSORFLOW_ROOT="${CONDA_PREFIX}/lib/python3.11/site-packages/tensorflow" \
113
+ -DTensorFlow_INCLUDE_DIRS="${CONDA_PREFIX}/lib/python3.11/site-packages/tensorflow/include" \
114
+ -DTorch_DIR="${CONDA_PREFIX}/lib/python3.11/site-packages/torch/share/cmake/Torch" \
115
+ -DHIP_ROOT_DIR="${ROCM_PATH}/hip" \
116
+ -DCMAKE_PREFIX_PATH="${CONDA_PREFIX};${ROCM_PATH}/lib/cmake" \
117
+ -DLAMMPS_SOURCE_ROOT="${LAMMPS_SRC_DIR}" \
118
+ -DCMAKE_INSTALL_PREFIX="${DP_CPP_DIR}" \
119
+ ..
120
+
121
+ make -j$(nproc)
122
+ make install
123
+
124
+ # 后处理:创建 dpplugin.so 符号链接
125
+ cd "${DP_CPP_DIR}/lib"
126
+ if [ -f "deepmd_lmp/dpplugin.so" ] && [ ! -e "dpplugin.so" ]; then
127
+ ln -s deepmd_lmp/dpplugin.so ./
128
+ fi
129
+ else
130
+ echo ">>> Step 7: 下载预编译 C++ 接口包"
131
+ mkdir -p "${DP_CPP_DIR}"
132
+ cd "${DP_CPP_DIR}"
133
+ download_file "${DP_CPP_URL}" dp_cpp_dcu.tar.gz || exit 1
134
+ tar -xzf dp_cpp_dcu.tar.gz --strip-components=1
135
+ rm -f dp_cpp_dcu.tar.gz
136
+ echo ">>> Step 7: C++ 接口安装完成(${DP_CPP_DIR})"
137
+ fi
matchem_env.sh ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # ==========================================
3
+ # MatChem 统一环境配置脚本
4
+ # 用途:加载模块、激活 conda、导出各组件路径
5
+ # 用法:source matchem_env.sh
6
+ # 注意:默认激活 conda 环境 test_pip;若使用其他环境名,请执行:
7
+ # MATCHEM_CONDA_NAME=your_env source matchem_env.sh
8
+ # ==========================================
9
+
10
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11
+
12
+ # ---------- 1. 基础环境配置 ----------
13
+ export MATCHEM_CONDA_NAME="${MATCHEM_CONDA_NAME:-test_pip}"
14
+
15
+ # ---------- 2. OneScience 运行时环境变量 ----------
16
+ export ONESCIENCE_DATASETS_DIR="/public/share/sugonhpcapp01/onestore/onedatasets"
17
+ export ONESCIENCE_MODELS_DIR="/public/share/sugonhpcapp01/onestore/onemodels"
18
+ export device="gpu" # 根据实际平台改为 gpu 或 dcu
19
+ export LD_LIBRARY_PATH="${CONDA_PREFIX:-}/lib:${LD_LIBRARY_PATH:-}"
20
+
21
+ # ---------- 3. 外部软件路径(使用 dp_install.sh / matpl_install.sh / lmp_install.sh 时会自动更新) ----------
22
+ # DeepMD-kit 源码目录
23
+ export DEEPMD_SRC_DIR="${SCRIPT_DIR}/deepmd-kit"
24
+
25
+ # MatPL 源码目录
26
+ export MATPL_SRC_DIR="${SCRIPT_DIR}/matpl_dcu"
27
+
28
+ # LAMMPS 安装目录
29
+ export LAMMPS_INSTALL_DIR="${SCRIPT_DIR}/lammps_dcu"
30
+
31
+ # DeepMD C++ 接口目录
32
+ export DP_CPP_DIR="${SCRIPT_DIR}/dp_cpp_dcu"
33
+
34
+ # ---------- 4. 加载集群模块与 conda ----------
35
+ set +u
36
+ source ~/.bashrc
37
+ set -u
38
+ module load sghpcdas/25.6 # DTK / PyTorch 等 SDK
39
+ module load sghpc-mpi-gcc/26.3 # MPI 与 GCC 编译器
40
+
41
+ conda activate "$MATCHEM_CONDA_NAME"
42
+
43
+ # ---------- 6. LAMMPS 运行时环境 ----------
44
+ export LD_LIBRARY_PATH=${LAMMPS_INSTALL_DIR}/lib64:${LD_LIBRARY_PATH:-}
45
+ export LD_LIBRARY_PATH=${LAMMPS_INSTALL_DIR}/lib_override:${LD_LIBRARY_PATH:-}
46
+ export LAMMPS_PLUGIN_PATH=${DP_CPP_DIR}/lib
47
+
48
+ echo "✅ MatChem 环境已激活: ${MATCHEM_CONDA_NAME}"