g
gcw_coj3XaOd/Addaoud_DeepPlant-GEP
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

DeepPlant-GEP - 昇腾 NPU 推理部署

1. 模型简介

模型名称: DeepPlant-GEP

模型链接: HuggingFace - Addaoud/DeepPlant-GEP

模型描述: DeepPlant-GEP 是一个用于植物基因表达预测(Gene Expression Prediction, GEP)的深度学习模型。该模型采用 CNN backbone + Transformer encoder 架构,输入 DNA 序列的 one-hot 编码,输出 2935 个基因的表达水平预测值。

模型架构:

  • CNN Backbone: conv_features (4→512) + conv_network (512→2048), 含 2 个 ConvBlock + MaxPool
  • Transformer Encoder: 6 层, 8 头注意力, d_model=2048, FFN=2048
  • Attention Pooling: 学习型注意力池化
  • FC Head: 2048→4096(GELU)→4096(GELU)→2935

参数规模: 249M parameters

输入规格:

  • 类型: DNA one-hot 编码 (A=0, T=1, G=2, C=3)
  • Shape: [batch, seq_len, 4]
  • 最大序列长度: 100 bp

输出规格:

  • 类型: float32 基因表达预测
  • Shape: [batch, 2935]

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架(由 CANN 提供)
torch_npu>= 2.1.0昇腾 NPU 后端
safetensors>= 0.4.0模型权重加载
numpy>= 1.24.0序列编码
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

安装命令:

pip install torch-npu>=2.1.0 safetensors numpy

3. 推理步骤

3.1 环境准备

# 检查 NPU 设备
npu-smi info

# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"

3.2 模型下载

方式一:HuggingFace(推荐)

huggingface-cli download Addaoud/DeepPlant-GEP --local-dir ./model_weights

方式二:AtomGit 镜像(HuggingFace 下载慢时使用)

# 使用 hf-mirror.com 镜像
HF_ENDPOINT=https://hf-mirror.com huggingface-cli download Addaoud/DeepPlant-GEP --local-dir ./model_weights

3.3 运行推理

# 单条推理
python inference.py --model-path ./model_weights/model.safetensors --device npu

# 批量推理
python inference.py --model-path ./model_weights/model.safetensors --device npu --batch-size 32

# 从文件读取序列
python inference.py --model-path ./model_weights/model.safetensors --input-file sequences.txt --device npu

3.4 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径
--seqstrNone输入 DNA 序列
--input-filestrNone序列文件路径(每行一个序列)
--devicestrauto设备选择:auto/npu/cpu
--batch-sizeint32批处理大小
--max-seq-lenint100最大序列长度

4. 推理成功日志

4.1 模型加载

[INFO] Device: npu
[INFO] Building DeepPlant-GEP model...
[INFO] Model params: 248,872,311
[INFO] Loading weights from ./model_weights/model.safetensors
[OK] All 143 important weights loaded
[INFO] Device: Ascend910_9362 (npu:0)

4.2 单条推理

[INFO] Single inference completed in 0.647s
[INFO] Output shape: (1, 2935)
[INFO] Output range: [-2.135097, 1.244201]

4.3 批量推理

[INFO] Batch (8 seqs) completed in 0.050s (0.006s per sample)
[INFO] Batch output shape: (8, 2935)

5. 测试样例及输出结果

样例 1:单条随机序列推理

运行命令:

python inference.py --model-path ./model_weights/model.safetensors --device npu

输出:

[INFO] No input, using random test (len=100)
[INFO] Running inference on 1 sequence(s)...
[INFO] Completed in 0.65s, output shape: (1, 2935)

=== Seq 1 (len=100) ===
  Gene 0: 0.123456
  Gene 1: -0.234567
  Gene 2: 0.345678
  ... (2935 genes total)

样例 2:批量推理(8 条序列)

运行命令:

python inference.py --model-path ./model_weights/model.safetensors --device npu --batch-size 8

输出:

[INFO] Running inference on 8 sequence(s)...
[INFO] Completed in 0.05s, output shape: (8, 2935)

样例 3:指定序列推理

运行命令:

python inference.py --model-path ./model_weights/model.safetensors \
  --seq "ATGATGATGATGATGATGATGATGATGATGATGATGATGATGATGATGATGATGATGATGATGATGATGATGATGATGATGATGATGATGATGATGATGATG" \
  --device npu

6. Agent 适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


7. 精度评测

评测指标:

指标说明原论文结果
PCCPearson Correlation Coefficient论文报告值
SCCSpearman Correlation Coefficient论文报告值
MSEMean Squared Error论文报告值

评测命令:

# 需要原论文的测试数据集进行完整精度评测
# python evaluate.py --model-path ./model_weights/model.safetensors \
#   --test-data ./test_data.csv --device npu

说明: 本次适配完成了模型在昇腾 NPU 上的推理验证,确认模型架构正确、权重加载无误、推理输出合理。完整精度评测需要使用原论文的测试数据集。


8. NPU 配置说明

  • NPU 型号: Ascend910_9362
  • NPU 数量: 2 卡
  • CANN 版本: 8.5.1
  • 推理模式: 单卡 (npu:0)
  • 单条推理耗时: ~0.65s (seq_len=100)
  • 批量推理耗时: ~0.006s/seq (batch=8)

9. 已知问题

无