atlasleong/deepplant-eap-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

DeepPlant-EAP — Ascend NPU 真机推理适配

将固定版本模型 Addaoud/DeepPlant-EAP(revision ac9f2298709f5492a7187e1a752e374167a9f23d) 完整适配到物理 Ascend NPU 设备 npu:6(Ascend910B4-1),完成真实的端到端 plant sequence/property prediction(植物序列/性状预测)推理。

  • 源模型:https://huggingface.co/Addaoud/DeepPlant-EAP
  • 源仓库类型:PyTorchModelHubMixin(仅权重 + config + model card,无自定义代码)
  • 本目录交付:inference.py、readme.md/README.md、requirements.txt、 run_acceptance.sh、原始/脱敏日志、logs/npu_result.json、SHA256SUMS、 LICENSE 及四张真实证据图片(assets/*.png)。
  • 许可证:MIT(与上游模型卡一致,见 LICENSE)。

适配证据截图

agent_workflow

modelagent_live_session

npu_device_call

model_result

Model introduction

DeepPlant-EAP(Expression Activity Prediction / plant sequence–property prediction)是一个植物序列/性状预测模型:输入一条 one-hot 编码的 DNA 序列 (4 条通道:A/C/G/T,长度 seq_len),经卷积主干(conv backbone)→ Transformer 编码器(6 层)→ 注意力池化 → 全连接回归头,输出 n_features = 2 个连续性状/活性预测值。

架构为按权重严格重建(strict=True,143/143 key 全匹配,0 缺失 / 0 多余), 关键超参来自 config.json:

超参值说明
taskEAP植物序列/性状预测(回归)
embed_dim2048Transformer 隐藏维度
n_filters512卷积主干通道数
num_heads8注意力头数(head_dim=256)
encoder_num_layers6Transformer 编码器层数
dim_forwardfeed2048前馈网络维度
dropout0.2Dropout 概率
expand_factor2FC 头扩展倍数(隐藏 4096)
max_seq_length100最大序列长度
n_features2输出性状预测维度
use_pos_encodingtrue使用位置编码
encoder_typeattention编码器类型
参数量236,651,010全量模型参数

NPU 原生实现说明:PyTorch 的 nn.TransformerEncoderLayer 在推理时会走融合算子 aten::_transformer_encoder_layer_fwd,该算子在 Ascend 后端不支持并会回退 CPU。 本适配将编码器层改用 Ascend 原生算子(linear / bmm / softmax / layer_norm) 等价重建(状态字典 key 完全一致,仍可严格加载),从而全模型在 NPU 上执行,无任何 CPU 回退。实测 forward_elapsed_s = 6.936374。


关键结论(真实验收)

  • 设备:npu:6,Ascend910B4-1,torch_npu 2.9.0。
  • 权重:model.safetensors(947,534,168 B)以 strict=True 加载,143/143 key 全匹配,SHA256 9fd527c01a5d73fd009d1e028031bc19407307791d7556a9f29d922873b1d953。
  • 放置断言:输入、模型参数、模型 buffer、输出全部位于 npu:6,缺失/失效 NPU 时 失败关闭(非零退出,绝不静默回退 CPU)。
  • 并发 PID 证明:inference.py 上报 pid=host_pid=1596762,物理 npu-smi 在 15 秒持有期间连续 5 次捕获 NPU 6 进程 PID 1596762(1094 MB,与全量权重相符)—— PID CORRELATION: MATCH。
  • 同步计时:forward_elapsed_s = 6.936374,输出 (1, 2),全为有限值。

Environment dependencies

本任务使用镜像自带的 CANN 匹配版本,禁止替换 torch / torch_npu:

组件版本来源
Python3.11.14运行镜像
torch2.9.0+cpu运行镜像(CANN 匹配,勿替换)
torch_npu2.9.0运行镜像(CANN 匹配,勿替换)
CANN8.5.1运行环境
芯片Ascend910B4-1 × 8物理 NPU(本次使用 npu:6)
numpy1.26.4Aliyun 镜像(venv 内固定)
safetensors0.8.0Aliyun 镜像(venv 内固定)
Pillow12.3.0Aliyun 镜像(仅用于生成证据 PNG)

推荐运行环境为模型专属 venv(--system-site-packages 继承系统 torch/torch_npu):

/usr/local/python3.11.14/bin/python -m venv --system-site-packages \
  /work/pipeline/jobs/next8/deepplant-eap/venv-deepplant-eap

非 torch 应用依赖通过 Aliyun pip 镜像安装:

pip install --index-url https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt

记录的解释器与解析版本(venv-deepplant-eap/bin/python):

Python   3.11.14
numpy    1.26.4
safetensors 0.8.0
Pillow   12.3.0
torch    2.9.0+cpu     (inherited from container, NOT replaced)
torch_npu 2.9.0        (inherited from container, NOT replaced)

Inference steps

前置条件:本地模型目录存在且完整 /work/pipeline/models/next8/deepplant-eap/(含 config.json、 model.safetensors、README.md),固定 revision ac9f2298709f5492a7187e1a752e374167a9f23d。

  1. 进入交付目录

    cd /work/pipeline/jobs/next8/deepplant-eap/deepplant-eap-npu
  2. 确认 NPU 设备可用

    npu-smi info        # 应能看到 NPU 0..7,其中 npu:6 空闲
    python -c "import torch_npu, torch; print(torch.npu.is_available(), torch.npu.device_count())"
    # True 8
  3. (如需)通过 Aliyun 镜像安装额外依赖

    pip install --index-url https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt
  4. 运行真实 NPU 推理

    /work/pipeline/jobs/next8/deepplant-eap/venv-deepplant-eap/bin/python \
        inference.py --device npu:6 --batch 1 --seq-len 100 --seed 0 \
        --hold-after-load 15
    • --device npu:6:目标物理设备;缺失/失效时脚本失败关闭。
    • --hold-after-load 15:模型加载后保持 NPU 分配 15 秒,便于外部 npu-smi 并发捕获进程 PID(默认 0,即不保持)。
    • 输出:logs/npu_result.json(结构化结果),并在终端打印关键信息。
  5. 一键验收(可选)

    bash run_acceptance.sh

    该脚本后台启动推理、在持有期间连续抓取 5 次物理 npu-smi、解析 reported_pid / host_pid(来自 /proc/sched_debug)与 NPU 6 进程 PID, 打印 PID CORRELATION: MATCH,并产出原始/脱敏日志。

  6. 查看结果

    cat logs/npu_result.json
    cat logs/npu_inference_sanitized.log

Complete test case and output

以下为 2026-08-22 在物理 npu:6 上执行的真实测试命令与输出。

用例 1:一键验收脚本(含并发 PID 捕获)

$ bash run_acceptance.sh
=== launching inference.py on npu:6 (hold-after-load=15s) ===
=== Python container PID = 1596762 ===
=== reported_pid(from inference.py) = 1596762 ===
=== host_pid(from inference.py)      = 1596762 ===
=== npu_smi_pid(on NPU 6)            = 1596762 ===
=== PID CORRELATION: MATCH ===
=== inference.py exit code: 0 ===

用例 2:推理日志(logs/npu_inference.log)

[DeepPlant-EAP] pid=1596762 host_pid=1596762 host=gz.03 start=2026-08-22T15:24:09+00:00
[DeepPlant-EAP] torch=2.9.0+cpu torch_npu=2.9.0
[DeepPlant-EAP] numpy=1.26.4 python=3.11.14
[DeepPlant-EAP] device=npu:6 name=Ascend910B4-1 count=8
[DeepPlant-EAP] config={"decoder_num_layers": 0, "dim_forwardfeed": 2048, "dropout": 0.2, "embed_dim": 2048, "encoder_num_layers": 6, "encoder_type": "attention", "expand_factor": 2, "max_seq_length": 100, "n_features": 2, "n_filters": 512, "num_heads": 8, "task": "EAP", "use_pos_encoding": true}
[DeepPlant-EAP] model built, parameters=236651010
[DeepPlant-EAP] loaded checkpoint strict=True keys=143 size=947534168 sha256=9fd527c01a5d73fd009d1e028031bc19407307791d7556a9f29d922873b1d953
[DeepPlant-EAP] model placement: params=npu:6 buffers=npu:6
[DeepPlant-EAP] NPU_PID=1596762 holding 15.0s for npu-smi capture
[DeepPlant-EAP] input shape=(1, 4, 100) device=npu:6 dtype=torch.float32
[DeepPlant-EAP] output shape=(1, 2) device=npu:6 dtype=torch.float32
[DeepPlant-EAP] output stats={"max": 0.1373855024576187, "mean": 0.0025593191385269165, "min": -0.13226686418056488, "std": 0.1348261833190918, "values": [-0.13226686418056488, 0.1373855024576187]}
[DeepPlant-EAP] forward elapsed(s)=6.9364
[DeepPlant-EAP] wrote logs/npu_result.json
[DeepPlant-EAP] total_wall(s)=28.1691 exit=0

用例 3:并发 npu-smi 物理设备进程表(持有期间,NPU 6)

| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |
| 6       0                 | 1596762       | DeepPlantEAP             | 1094                    |

说明:容器命名空间 PID 1596762 与 NPU 6 上 npu-smi 报告的进程 PID 1596762 完全一致;进程内存 1094 MB 与全量权重(947,534,168 B ≈ 903 MB 参数 + 运行时开销)相符。


输出结果

logs/npu_result.json(节选,完整字段见文件):

字段值
model_idAddaoud/DeepPlant-EAP
source_revisionac9f2298709f5492a7187e1a752e374167a9f23d
weight_sha2569fd527c01a5d73fd009d1e028031bc19407307791d7556a9f29d922873b1d953
weight_key_count / parameter_count143 / 236651010
device / npu_device_namenpu:6 / Ascend910B4-1
input_shape / output_shape[1, 4, 100] / [1, 2]
input_device / model_device / output_devicenpu:6 / npu:6 / npu:6
predicted_properties[-0.13226686418056488, 0.1373855024576187]
forward_elapsed_s6.936374
output_statsmean=0.00255932, std=0.13482618, min=-0.13226686, max=0.13738550
pid / host_pid1596762 / 1596762

证据图片

图片内容
assets/agent_workflow.png适配工作流(读上下文 → 权重清单 → 重建 → 真机推理 → 并发 PID → 产物校验)
assets/modelagent_live_session.png真实验收会话输出(run_acceptance.sh,PID 匹配)
assets/npu_device_call.png物理 npu:6 设备调用与 npu-smi 并发进程表证据
assets/model_result.png推理结果(输出统计、npu_result.json 摘要)

文件清单

文件说明
inference.py完整 NPU 推理脚本(架构重建 + 严格加载 + 放置断言 + 同步计时)
readme.md / README.md本说明(两文件字节一致)
requirements.txt非 torch 依赖(Aliyun 镜像安装)
run_acceptance.sh一键真实验收(并发 npu-smi PID 捕获与匹配)
LICENSEMIT 许可证文本(上游模型卡声明)
logs/npu_inference.log原始运行日志
logs/npu_inference_sanitized.log脱敏日志(滤除 torch_npu 噪声)
logs/npu_smi_capture_{1..5}.log持有期间 5 次物理 npu-smi 快照
logs/npu_smi_during.log / npu_smi_after.log持有期间 / 结束后快照
logs/npu_result.json结构化推理结果
SHA256SUMS交付物 SHA256 校验清单
assets/*.png四张真实证据图片

限制

  • 输入为合成 one-hot DNA(--seed 固定,可复现),用于证明完整、真实的 NPU 推理链路;不附带任何外部/版权数据。
  • 模型权重位于本机 /work/pipeline/models/next8/deepplant-eap/,运行前必须存在。
  • torch / torch_npu 为镜像自带 CANN 匹配版本,请勿重装或升级。
  • 本交付不包含权重文件、私有 SDK JSONL、__pycache__/*.pyc、predictions.npz 等禁止产物。

许可证

本适配遵循上游模型卡声明的 MIT 许可(见 LICENSE)。模型权重版权归原作者所有, 仅作本地固定版本推理。

适配交付补充

环境依赖:torch、torch_npu 与 CANN,详见 requirements.txt。

推理步骤:执行 inference.py 并确认目标设备为 Ascend NPU。

完整测试用例:使用仓库固定测试输入执行一次端到端推理。

输出结果:真实 NPU 结果保存在 logs/npu_result.json。