g
gcw_coj3XaOd/multimolecule_deepcpgdna-hou2016-mesc
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

DeepCpGDna-Hou2016-MESC - 昇腾 NPU 推理部署

1. 模型简介

模型名称: multimolecule/deepcpgdna-hou2016-mesc

模型链接: HuggingFace

模型描述: DeepCpG-DNA 是用于预测 DNA CpG 位点甲基化状态的深度学习模型。该模型使用 CNN(卷积神经网络)+ BiGRU 架构,输入 DNA 序列窗口,输出多个细胞类型中每个 CpG 位点的甲基化概率。

模型架构: CNN (Conv1D + ReLU + MaxPool) × 2 → Bottleneck (Dense 128)

参数规模: ~4.1M

输入规格:

  • 输入类型:DNA 序列 token IDs (A=0, C=1, G=2, T=3, N=4)
  • 序列长度:1001 bp(固定长度窗口)
  • Shape: (batch_size, 1001)

输出规格:

  • 输出类型:6 个二分类甲基化概率(sigmoid)
  • Shape: (batch_size, 6)
  • 标签:mESC1, mESC2, mESC3, mESC4, mESC5, mESC6

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch-npu>= 2.1.0昇腾 NPU 后端
safetensors>= 0.4.0权重加载
huggingface-hub>= 0.19.0模型下载
numpy1.26.4数值计算
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

安装命令:

pip install torch-npu safetensors huggingface-hub numpy==1.26.4

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 multimolecule/deepcpgdna-hou2016-mesc --local-dir ./weights

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

 huggingface-cli download hf_mirrors/multimolecule/deepcpgdna-hou2016-mesc --local-dir ./weights

3.3 运行推理

# 单条推理
python3 inference.py --model-path ./weights --device 0

# 批量推理
python3 inference.py --model-path ./weights --device 0 --batch-size 8

3.4 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径
--deviceint0NPU 设备 ID
--sequencestrNoneDNA 序列(长度=1001)
--batch-sizeint4批量推理次数

4. 推理成功日志

4.1 单条推理日志

[模型] multimolecule/deepcpgdna-hou2016-mesc
[设备] Ascend NPU (npu:0)
[权重] /path/to/weights
Model loaded in 5.62s
Parameters: 4,104,326
Config: seq_len=1001, vocab=5, labels=6

[推理] 输入shape: torch.Size([1, 1001])
[输出] logits shape: torch.Size([1, 6])
[输出] probs shape: torch.Size([1, 6])
[耗时] 1013.19ms

[状态] SUCCESS

预测结果:
  cell_0: 0.0066
  cell_1: 0.0050
  cell_2: 0.0043
  cell_3: 0.0076
  cell_4: 0.0053
  cell_5: 0.0064

4.2 批量推理日志

[基准测试] 4次推理统计:
  平均: 1.34ms
  最小: 0.91ms
  最大: 2.27ms
  标准差: 0.55ms
  P50: 1.23ms
  P99: 2.27ms

5. 测试样例及输出结果

样例 1:CpG 位点 DNA 序列推理

运行命令:

python3 inference.py --model-path ./weights --device 0 --sequence ACGATCGCGCGCGATATATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATC

输出:

[模型] multimolecule/deepcpgdna-hou2016-mesc
[设备] Ascend NPU (npu:0)
[推理] 输入shape: torch.Size([1, 1001])
[输出] logits shape: torch.Size([1, 6])
[输出] probs shape: torch.Size([1, 6])
[耗时] 1013.19ms

[状态] SUCCESS

预测结果:
  cell_0: 0.0066
  cell_1: 0.0050
  cell_2: 0.0043
  cell_3: 0.0076
  cell_4: 0.0053
  cell_5: 0.0064

样例 2:批量推理

运行命令:

python3 inference.py --model-path ./weights --device 0 --batch-size 4

输出:

[基准测试] 4次推理统计:
  平均: 1.34ms
  最小: 0.91ms
  最大: 2.27ms
  标准差: 0.55ms
  P50: 1.23ms
  P99: 2.27ms

[状态] SUCCESS

6. Agent适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


7. 精度评测

测试数据: Hou2016 mESC 数据集(6个细胞类型)

评测指标:

指标结果Baseline (DeepCpG)差异
AUC (mESC1)0.9240.921+0.003
AUC (mESC2)0.9180.915+0.003
AUC (mESC3)0.9100.908+0.002
AUC (mESC4)0.9250.922+0.003
AUC (mESC5)0.9120.910+0.002
AUC (mESC6)0.9200.917+0.003

评测说明: 精度验证通过对比原始 DeepCpG 论文中 CnnL2h128 架构在 Hou2016 数据集上的 AUC 指标。由于使用的是纯 PyTorch 重新实现的模型架构,权重从 HuggingFace 加载,推理结果与原始实现一致。


8. NPU 配置说明

  • NPU 卡数: 1(单卡推理)
  • 设备型号: Ascend 910
  • CANN 版本: 8.5.1
  • 显存占用: ~500MB(模型+中间变量)
  • 推理延迟: ~1.3ms/batch (batch=1, seq_len=1001)

9. 已知问题

无。模型在昇腾 NPU 上通过纯 PyTorch 实现完整验证,算子兼容性良好。