JeffDing/aimnet2-2025-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

AIMNet2-2025 昇腾NPU部署文档

1. 模型简介

模型名称: AIMNet2-2025

模型链接: https://ai.gitcode.com/hf_mirrors/isayevlab/aimnet2-2025

模型描述: AIMNet2-2025 是新一代神经网络势函数(Neural Network Potential),用于分子动力学模拟和高精度能量/力预测。该模型采用 AIMNet2 架构,支持 WB97M-D3 水平的量子化学精度,可处理有机分子、药物分子、材料体系等多种化学场景。模型支持 14 种元素(H, B, C, N, O, F, Si, P, S, Cl, As, Se, Br, I),适用于中性分子和离子体系的能量、电荷、偶极矩预测。

模型架构: AIMNet2(Atomic Interaction Network v2)神经网络势函数

参数规模: Ensemble 模型,包含 4 个成员(ensemble_0 ~ ensemble_3),每个成员约 16 维特征 + 3 层 MLP(512→380→380 隐藏层)

关键特性:

  • 支持 Coulomb(库仑)和 D3 色散校正
  • 支持自洽电荷迭代
  • 支持短程和长程相互作用
  • 截断半径:5.0 Å

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch2.1.0+PyTorch 框架
torch_npu2.9.0+华为昇腾 NPU 适配库
aimnet>= 0.2.0AIMNet2 模型库
numpy>= 1.24.0数值计算
PyYAML>= 6.0YAML 配置解析
safetensors>= 0.4.0安全张量格式
昇腾驱动CANN 8.0.RC2+推荐 CANN 8.5.1

安装命令:

# 1. 安装 Ascend CANN 驱动(从华为官网下载对应版本)
# CANN 安装后会自动配置 torch 和 torch_npu

# 2. 安装 AIMNet2 依赖
pip install aimnet>=0.2.0

# 3. 安装其他依赖
pip install numpy PyYAML safetensors

# 4. 验证安装
python3 -c "import torch, torch_npu; print('NPU available:', torch.npu.is_available())"

3. 推理步骤

3.1 环境准备

# 检查 NPU 设备状态
npu-smi info

# 检查 torch_npu 可用性
python3 -c "import torch, torch_npu; print('torch_npu:', torch_npu.__version__); print('NPU available:', torch.npu.is_available())"

3.2 下载模型权重

# 使用 atomgit_hub SDK 下载模型
pip install atomgit
python3 -c "
from atomgit_hub import snapshot_download
snapshot_download('hf_mirrors/isayevlab/aimnet2-2025', local_dir='/tmp/aimnet2-2025')
"

或使用 HuggingFace 镜像:

HF_ENDPOINT=https://hf-mirror.com huggingface-cli download "isayevlab/aimnet2-2025" --local-dir "/tmp/aimnet2-2025"

3.3 运行推理

# 在 NPU 上运行推理
cd aimnet2-2025-NPU

# 测试甲烷分子
python3 inference.py --input methane --model_path /tmp/aimnet2-2025

# 测试水分子
python3 inference.py --input water --model_path /tmp/aimnet2-2025

# 测试氨分子
python3 inference.py --input ammonia --model_path /tmp/aimnet2-2025

# 使用自定义 XYZ 文件
python3 inference.py --input_file molecule.xyz --model_path /tmp/aimnet2-2025

# 指定 NPU 设备
python3 inference.py --input methane --model_path /tmp/aimnet2-2025 --device npu:0

3.4 推理参数说明

参数类型默认值说明
--inputstrmethane预置分子名称(methane/water/ammonia)
--input_filestrNone输入 XYZ 文件路径
--model_pathstr/tmp/aimnet2-2025模型目录路径
--ensemble_memberint0Ensemble 成员索引(0-3)
--max_lengthintNone最大长度(保留参数,兼容接口)
--chargefloat0.0分子电荷
--multfloat1.0自旋多重度
--forcesflagFalse是否计算力
--devicestrauto推理设备(npu:0/cuda:0/cpu)

4. 测试样例及输出结果

样例 1:甲烷(Methane, CH₄)

输入:

5

C     0.000000    0.000000    0.000000
H     0.629000    0.629000    0.629000
H    -0.629000   -0.629000    0.629000
H    -0.629000    0.629000   -0.629000
H     0.629000   -0.629000   -0.629000

输出:

Energy: -1093.351708 eV
Energy: -40.179910 Hartree
Energy: -25213.674404 kcal/mol
Charges: [-0.06332842  0.02110948  0.02110948  0.02110946  0.        ]
Inference time: 0.167s

样例 2:水(Water, H₂O)

输入:

3

O     0.000000    0.000000    0.117000
H    -0.757000    0.000000   -0.468000
H     0.757000    0.000000   -0.468000

输出:

Energy: -2069.564488 eV
Energy: -76.055046 Hartree
Energy: -47726.019707 kcal/mol
Charges: [-0.14593379  0.14593375  0.        ]
Inference time: 0.173s

样例 3:氨(Ammonia, NH₃)

输入:

4

N     0.000000    0.000000    0.000000
H     0.940000    0.000000   -0.320000
H    -0.470000    0.814000   -0.320000
H    -0.470000   -0.814000   -0.320000

输出:

Energy: -1529.198920 eV
Energy: -56.196990 Hartree
Energy: -35264.703385 kcal/mol
Charges: [-0.16394138  0.08197104  0.08197035  0.        ]
Inference time: 0.168s

5. Agent适配截图

5.1 Agent适配全过程截图

Agent 适配流程

5.2 NPU设备调用截图

NPU 设备调用

5.3 模型适配结果截图

模型适配结果


6. NPU运行验证信息

验证项结果
NPU 设备Ascend910 (2 devices)
NPU HealthOK
torch_npu 版本2.9.0.post1+gitee7ba04
CANN 版本8.5.1
torch 版本2.9.0+cpu
推理设备npu:0
模型加载时间~1.13s
甲烷推理时间0.167s ✓
水推理时间0.173s ✓
氨推理时间0.168s ✓
NPU 运行状态成功运行 ✓

7. 注意事项

7.1 NPU 适配说明

本模型适配昇腾 NPU 时进行了以下关键修改:

  1. 设备检测链:支持 NPU → CUDA → CPU 自动降级,优先使用 NPU 设备
  2. Neighbor List 兼容:使用纯 PyTorch 实现的 compute_nbmat 替代 nvalchemiops 的 Warp 实现,解决 Warp 不支持 NPU 设备的问题
  3. 模型加载:直接从 safetensors 格式加载,无需 JIT 编译
  4. 数据类型:模型使用 float32,原子位移参数使用 float64 保证精度

7.2 性能优化建议

  • 对于小分子(<100 atoms),推理时间约 0.17s
  • 支持批量推理(通过 --input_file 指定多个分子)
  • 可使用 ensemble 平均(ensemble_member 0-3)提高精度
  • 大体系建议使用 --forces 标志计算力(需额外时间)

7.3 已知限制

  • 不支持 torch.compile(与 NPU inductor 存在兼容性问题)
  • 不支持 Hessian 矩阵计算(二阶导数)
  • 不支持周期性边界条件(PBC)体系
  • 当前版本仅支持能量和力计算,不支持应力张量

7.4 联系方式

  • 模型仓库:https://ai.gitcode.com/hf_mirrors/isayevlab/aimnet2-2025
  • 适配仓库:https://gitcode.com/JeffDing/aimnet2-2025-NPU
  • 官方文档:https://github.com/isayevlab/aimnetcentral