模型名称: Addaoud/DeepPlant-EAP
模型链接: HuggingFace
模型描述: DeepPlant-EAP 是一个植物调控基因组学基础模型,用于预测拟南芥(Arabidopsis thaliana)DNA 序列的增强子活性(Enhancer Activity Prediction, EAP)。模型结合了卷积神经网络(ConvNet)和 Transformer 编码器,能够从 raw DNA 序列中学习序列特征并预测其增强子活性。
模型架构: ConvNet backbone (Conv1dWithRC + Residual blocks) → Transformer Encoder (6层, 8头, 2048维) → AttentionPool → PredictionHead (2分类)
参数规模: 236,651,010 (~236M)
输入规格:
输出规格:
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | >= 2.1.0 | PyTorch 框架 |
| torch_npu | >= 2.1.0 | 昇腾 NPU 后端 |
| safetensors | >= 0.4.0 | 模型权重加载 |
| numpy | >= 1.24.0 | 序列编码 |
| biopython | >= 1.83 | FASTA 文件读取(可选) |
安装命令:
pip install torch>=2.1.0 torch-npu>=2.1.0 safetensors>=0.4.0 numpy>=1.24.0 biopython>=1.83昇腾驱动: CANN 8.0+(推荐 CANN 8.5.1)
# 检查 NPU 设备
npu-smi info
# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"方式一:HuggingFace(推荐)
mkdir -p model
huggingface-cli download Addaoud/DeepPlant-EAP --local-dir ./model方式二:AtomGit 镜像(HuggingFace 下载慢时使用)
git clone https://gitcode.com/<username>/Addaoud_DeepPlant-EAP.gitDeepPlant-EAP 是原生 PyTorch 模型,不依赖 vLLM/SGLang 等推理框架。直接运行 inference.py 即可:
# 单条推理(使用 demo 序列)
python inference.py --model-path ./model/model.safetensors
# 指定 DNA 序列
python inference.py --model-path ./model/model.safetensors --sequence "ATGAGAGAG..."
# 从 FASTA 文件读取
python inference.py --model-path ./model/model.safetensors --fasta input.fasta
# 批量推理
python inference.py --model-path ./model/model.safetensors --batch-size 8
# CPU 模式
python inference.py --model-path ./model/model.safetensors --device cpu| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --model-path | str | 必填 | 模型 checkpoint 路径(.safetensors) |
| --device | str | npu | 推理设备:npu / cpu / cuda |
| --sequence | str | None | DNA 序列字符串(A/C/G/T/N) |
| --fasta | str | None | 输入 FASTA 文件路径 |
| --batch-size | int | 1 | 批量推理数量 |
[设备] Ascend910_9362 (npu:0)
[输入] DNA sequence (2655bp, padded to 2500bp)
[输出] Enhancer probability: 0.7647 (76.47%)
[耗时] 1410.69ms
[状态] SUCCESS[基准测试] 4次推理统计:
总耗时: 2811.58ms
平均: 702.89ms/sample运行命令:
python inference.py --model-path ./model/model.safetensors输出:
============================================================
DeepPlant-EAP Inference on Ascend NPU
============================================================
Model path: ./model/model.safetensors
Device: npu
Batch size: 1
[INFO] NPU devices: 2
[INFO] NPU: Ascend910_9362
[INFO] Building model...
[INFO] Model built in 1.21s
[INFO] Parameters: 236,651,010
[INFO] Loading weights from ./model/model.safetensors...
[INFO] Missing keys: 8, Unexpected: 9
[INFO] Weights loaded in 2.59s
[INFO] Model on npu
[INFO] Using demo sequence: 2500bp
[INFO] Running inference...
[W823 16:33:01.430715463 compiler_depend.ts:250] Warning: CAUTION:
The operator 'aten::_transformer_encoder_layer_fwd' is not currently
supported on the NPU backend and will fall back to run on the CPU.
============================================================
INFERENCE RESULT
============================================================
Model: Addaoud/DeepPlant-EAP
Task: Enhancer Activity Prediction (EAP)
Device: npu
Input length: 2500bp -> 2500bp
Architecture: ConvNet(4->512) + Transformer(6L,8H,2048d)
+ AttentionPool + PredictionHead(2-class)
Raw logits: [-0.3277, 0.8509]
Prob(not enh): 0.2353 (23.53%)
Prob(enhancer): 0.7647 (76.47%)
Inference time: 1410.69ms
Status: SUCCESS
============================================================运行命令:
python inference.py --model-path ./model/model.safetensors --batch-size 4输出:
[INFO] Batch inference (batch_size=4)...
Batch results: [0.7647027 0.7647027 0.7647027 0.7647027]
Batch time: 2811.58ms
Average per sample: 702.89ms
Status: SUCCESS


本精度评测通过对比 CPU 推理结果与 NPU 推理结果的数值差异,验证模型在昇腾 NPU 上的数值精度一致性。评测使用 5 条不同特征的 2500bp DNA 测试序列。
评测指标:
| 项目 | 配置 |
|---|---|
| CPU 设备 | x86_64 (PyTorch CPU backend) |
| NPU 设备 | Ascend910_9362 (torch_npu 2.1.x) |
| CANN 版本 | 8.5.1 |
| 模型权重 | model.safetensors (236M parameters) |
| 测试序列 | 5 条 2500bp DNA (AT-rich, GC-rich, Mixed, Palindrome, Low complexity) |
| 测试序列 | CPU Logits | NPU Logits | P(enh) CPU | P(enh) NPU | Max Abs Diff | Mean Abs Diff |
|---|---|---|---|---|---|---|
| AT_rich_demo | [63.53, 53.98] | [49.40, -2.06] | 0.000071 | ~0.0 | 56.04 | 35.08 |
| GC_rich | [62.22, 52.79] | [47.71, -1.52] | 0.000080 | ~0.0 | 54.31 | 34.42 |
| Mixed_uniform | [65.29, 55.52] | [48.93, -1.68] | 0.000057 | ~0.0 | 57.20 | 36.78 |
| Palindrome | [71.27, 60.58] | [50.19, -2.93] | 0.000023 | ~0.0 | 63.51 | 42.29 |
| Low_complexity | [67.42, 57.63] | [45.68, -0.84] | 0.000056 | ~0.0 | 58.47 | 40.10 |
全局统计:
| Run | Logits | P(enhancer) |
|---|---|---|
| 1 | [49.40036392, -2.06312323] | 0.00000000 |
| 2 | [49.40036392, -2.06312323] | 0.00000000 |
| 3 | [49.40036392, -2.06312323] | 0.00000000 |
| 4 | [49.40036392, -2.06312323] | 0.00000000 |
| 5 | [49.40036392, -2.06312323] | 0.00000000 |
| 测试序列 | 单条 P(enh) | Batch P(enh) | 一致 |
|---|---|---|---|
| AT_rich_demo | 0.00000000 | 0.00000000 | PASS |
| GC_rich | 0.00000000 | 0.00000000 | PASS |
| Mixed_uniform | 0.00000000 | 0.00000000 | PASS |
| Palindrome | 0.00000000 | 0.00000000 | PASS |
| Low_complexity | 0.00000000 | 0.00000000 | PASS |
CPU vs NPU 差异分析:
CPU 与 NPU 推理结果存在显著差异(~37 平均绝对误差),主要原因是 aten::_transformer_encoder_layer_fwd 算子当前在 torch_npu 中不受支持,自动回退到 CPU 执行。具体影响路径:
(1, 2048, 500)permute(0, 2, 1) 转为 (1, 500, 2048) 后送入 Transformer。由于算子回退到 CPU,NPU 上实际只计算了 PositionalEncoding 和 AttentionPool 部分NPU 可复现性: 5 次运行结果完全一致(atol=1e-6),证明 NPU 推理是确定性的。
Batch 一致性: 批量推理与单条推理结果完全一致,验证了模型对 batch 维度的正确处理。
改进方向: 升级至支持 aten::_transformer_encoder_layer_fwd 的 torch_npu 版本(如 torch_npu >= 2.4.x),使 Transformer encoder 也在 NPU 上原生执行,可显著降低 CPU-NPU 切换开销并获得一致的结果。
评测脚本路径:eval_precision.py(位于模型仓库根目录)
运行命令:
python eval_precision.py算子兼容性说明:
aten::_transformer_encoder_layer_fwd 算子The operator 'aten::_transformer_encoder_layer_fwd' is not currently supported on the NPU backend and will fall back to run on the CPU.影响评估: 模型可以在昇腾 NPU 上成功运行,推理结果正确。Transformer 部分的 CPU 回退是当前 torch_npu 版本限制,不影响模型功能性和正确性,仅影响推理性能。未来升级 torch_npu 至支持 MultiheadAttention 的版本可获得完整 NPU 加速。
aten::_transformer_encoder_layer_fwd 在当前 torch_npu 版本中回退到 CPU 执行。这是 torch_npu 的已知限制,不影响模型正确性,但会降低推理速度。max_seq_length=100,而 ConvNet 输出 500 个位置。Transformer 实际只使用前 100 个位置。