s
stella4528/DeepPlant-EAP-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

DeepPlant-EAP 植物调控基因组学预测 · 昇腾 NPU 适配

模型简介

DeepPlant 是序列级植物调控基因组学基础模型(bioRxiv 2026,Deep-Plant: a supervised foundation model for plant regulatory genomics)。本仓为其中 EAP(Expression Associated Polymorphisms / 调控相关预测)子任务权重(Addaoud/DeepPlant-EAP,PyTorchModelHubMixin 保存)。

  • 任务类型:EAP 特征预测(tabular regression,输出 2 个 EAP 特征)
  • 架构:ConvNet backbone(Conv1dWithRC 反向互补卷积 + BN + MaxPool + 残差卷积塔)→ TransformerEncoder(6 层 attention,embed 2048,8 头)→ AttentionPool(可学习注意力池化)→ EAP 预测头(裸 Linear 4096→2)
  • 输入:DNA 序列,固定 2500 bp(居中 pad/crop),one-hot 编码 [4, 2500]
  • 输出:2 个 EAP 特征(裸 Linear 原始输出,无激活)
  • 参数量:236.65M(实测加载打印)
  • 权重大小:model.safetensors 947,534,168 B(约 903 MiB)
  • 许可证:MIT

环境要求

  • Python 3.9+
  • PyTorch + torch_npu(昇腾 CANN 环境)
  • 依赖安装:
pip install -r requirements.txt

torch_npu 请按本机 CANN 版本安装对应版本,例如: pip install torch-npu==2.1.0.post6 -i https://repo.huaweicloud.com/repository/pypi/simple

权重准备

本仓库根目录已内置 config.json + model.safetensors;推理脚本会优先使用本地权重。若本地权重缺失,脚本会自动从 HuggingFace(Addaoud/DeepPlant-EAP,HF 镜像)下载,失败则从 ModelScope 兜底。

推理

# 默认示例(ACGT 重复 2500 bp,验证前向 + EAP 特征预测)
python inference.py --device npu:0

# 自定义 DNA 序列(< 2500 bp 自动居中补 N,> 2500 bp 居中裁剪)
python inference.py --device npu:0 --seq "ACGT"*600

# 指定权重目录与输出目录
python inference.py --device npu:0 --weights-dir ./weights --output ./results

参数说明

参数默认值说明
--seqACGT×625(2500bp)DNA 序列,自动 pad/crop 到 2500 bp
--weights-dir仓库根目录权重目录(含 config.json + model.safetensors)
--output<weights-dir>/results验证证据输出目录
--deviceauto(npu:0→cuda:0→cpu)推理设备

输出说明

运行后在输出目录生成:

  • npu_result.json:推理摘要(参数量、输入/输出形状、预测统计、finite、耗时、NPU_INFERENCE_PASS)
  • inference_evidence.txt:一屏证据文本
  • model_sha256.txt:权重 SHA256
  • npu_smi.txt:NPU 状态

昇腾 NPU 适配说明

  • 纯 PyTorch 算子(conv1d / batch_norm / TransformerEncoderLayer / einsum+softmax / Linear),无 CUDA 专属内核,可无缝运行于 Ascend NPU;
  • vendored 源码 src/ 中 EAP prediction_head 已按 HF 权重结构修正为裸 nn.Linear(key: fc.prediction_head.0.weight,GitHub 源码为 Sequential(Linear));
  • NPU 关键修复:官方 nn.TransformerEncoderLayer 在 mask 为 None 时走 fused kernel torch._transformer_encoder_layer_fwd,该算子 torch_npu 不支持会导致整层回退 CPU;vendored src/transformer.py 新增纯算子实现 TransformerEncoderLayerNPU(F.scaled_dot_product_attention 手写等价前向,参数命名与官方一致,权重严格加载),实测全模型在 NPU 执行、无 CPU fallback;
  • 全 F32,eager 模式。

验证结果

  • 设备:Ascend 910(Ascend910_9362,2 卡)
  • 用例:默认 2500 bp 示例序列(ACGT×625)
  • 参数量:236.65M(实测加载打印)
  • 结果:输出 (1, 2) EAP 特征全 finite,无 NaN/Inf,NPU_INFERENCE_PASS=True,推理耗时见 results/npu_result.json

参考资料

  • 模型权重:https://huggingface.co/Addaoud/DeepPlant-EAP
  • GitCode 镜像:https://ai.gitcode.com/hf_mirrors/Addaoud/DeepPlant-EAP
  • DeepPlant:序列级植物调控基因组学基础模型(bioRxiv 2026)