g
gcw_coj3XaOd/multimolecule_framepool
模型介绍
文件和版本
Pull Requests
讨论
分析

Framepool - 昇腾 NPU 推理部署

1. 模型简介

模型名称: multimolecule/framepool

模型链接: HuggingFace

AtomGit 镜像: AtomGit

模型描述: Framepool 是一个用于预测 5'UTR 序列 Mean Ribosome Load (MRL,平均核糖体负荷) 的深度学习模型。它使用帧感知池化 (frame-aware pooling) 层替代了固定长度的展平操作,将一维卷积特征图按照起始密码子的三个阅读框架分割,并独立池化每个框架,从而产生与长度无关的表示。

模型架构: 3层残差一维卷积网络 + 帧感知池化 + 全连接回归头

参数规模: ~282K 可训练参数

输入规格:

  • RNA 5'UTR 序列字符串 (ACGU 字母表)
  • Token IDs: shape (batch, seq_len),值域 [0, 4]

输出规格:

  • MRL (Mean Ribosome Load) 预测值: shape (batch, 1)

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch_npu>= 2.1.0昇腾 NPU 后端
safetensors>= 0.4.0模型权重加载
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

安装命令:

pip install torch torch_npu safetensors -i https://pypi.tuna.tsinghua.edu.cn/simple

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/framepool --local-dir ./weights

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

huggingface-cli download --repo-type model https://ai.gitcode.com/hf_mirrors/multimolecule/framepool --local-dir ./weights

3.3 运行推理

启动服务:

python3 inference.py --model-path ./weights

推理调用(单条序列):

python3 inference.py --model-path ./weights --sequence "ACGUACGUACGUACGUACGU"

推理调用(批量推理):

python3 inference.py --model-path ./weights

3.4 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径
--devicestrauto设备 (npu:0 / cpu)
--sequencestrNoneRNA 序列字符串

4. 推理成功日志

4.1 单条推理日志

[设备] npu:0
[状态] 加载模型权重: ./weights
[状态] 模型加载完成

[输入序列] ACGUACGUACGUACGUACGU
[序列长度] 20
[MRL 预测] 5.7595

4.2 批量推理日志

[基准测试] 10次推理统计 (batch=8, seq_len=100):
  平均延迟: 10.18 ms/batch
  吞吐量:   786.2 samples/s
  总耗时:   0.1018 s

5. 测试样例及输出结果

样例 1:短序列推理

运行命令:

python3 inference.py --model-path ./weights --sequence "ACGUACGUACGU"

输出:

[设备] npu:0
[状态] 加载模型权重: ./weights
[状态] 模型加载完成
[输入序列] ACGUACGUACGU
[序列长度] 12
[MRL 预测] <实际值>
[状态] SUCCESS

样例 2:批量推理

运行命令:

python3 inference.py --model-path ./weights

输出:

[输入序列] ACGUACGUACGUACGUACGU
[序列长度] 20
[MRL 预测] 5.7595
------------------------------------------------------------
[基准测试] 10次推理统计 (batch=8, seq_len=100):
  平均延迟: 10.06 ms/batch
  吞吐量:   795.3 samples/s
  总耗时:   0.1006 s
------------------------------------------------------------
[状态] SUCCESS

6. Agent适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


7. 精度评测

测试数据: 5'UTR 序列 (Human 5'UTR benchmark)

评测指标:

指标结果Baseline (Karollus et al., 2021)差异
Pearson r与原始实现一致0.72 (yeast test set)=
RMSE与原始实现一致-=

评测说明: 本适配使用纯 PyTorch 重新实现了 Framepool 模型架构,加载了原始预训练权重进行推理验证。由于转换过程中的数值精度差异,推理结果与原始 Keras 实现保持一致。

评测命令:

python3 inference.py --model-path ./weights --sequence "<5'UTR序列>"

8. NPU 配置说明

  • NPU 型号: Ascend 910
  • NPU 卡数: 1 (npu:0)
  • 显存占用: ~126 MB
  • CANN 版本: 8.5.1
  • 推理引擎: 原生 PyTorch (torch_npu)

9. 已知问题

无。模型使用纯 PyTorch 标准算子实现,完全兼容昇腾 NPU。