将固定版本模型 Addaoud/DeepPlant-GEP(revision 57d02f6e9bfee46c98c8a0cbc1b835095898a3b6)
完整适配到物理 Ascend NPU 设备 npu:0(Ascend910B4-1),完成真实的端到端推理。
本轮(2026-08-22 turn-2)固定直连物理 npu:0,不设置 ASCEND_RT_VISIBLE_DEVICES,
全程不进行任何 CPU 推理或回退。
inference.py、readme.md/README.md、requirements.txt、.gitignore、
run_acceptance.sh、原始/脱敏日志、logs/npu_result.json、logs/predictions.npz、
logs/npu_device_call.log、logs/modelagent_transcript.log、SHA256SUMS
及四张真实证据图片(assets/*.png)。



DeepPlant-GEP(Gene Expression Prediction)是一个基因表达预测模型:输入一条
one-hot 编码的 DNA 序列(4 条通道:A/C/G/T,长度 seq_len),经卷积主干
(conv backbone)→ Transformer 编码器(6 层)→ 注意力池化 → 全连接回归头,
输出 n_features = 2935 个连续基因表达值。
架构为按权重严格重建(strict=True,0 缺失 / 0 多余 key),关键超参来自
config.json:
| 超参 | 值 | 说明 |
|---|---|---|
task | GEP | 基因表达预测(回归) |
embed_dim | 2048 | Transformer 隐藏维度 |
n_filters | 512 | 卷积主干通道数 |
num_heads | 8 | 注意力头数(head_dim=256) |
encoder_num_layers | 6 | Transformer 编码器层数 |
dim_forwardfeed | 2048 | 前馈网络维度 |
dropout | 0.2 | Dropout 概率 |
expand_factor | 2 | FC 头扩展倍数(隐藏 4096) |
max_seq_length | 100 | 最大序列长度 |
n_features | 2935 | 输出基因表达维度 |
| 参数量 | 248,667,511 | 全量模型参数 |
NPU 原生实现说明:PyTorch 的 nn.TransformerEncoderLayer 在推理时会走融合算子
aten::_transformer_encoder_layer_fwd,该算子在 Ascend 后端不支持并会回退 CPU。
本适配将编码器层改用 Ascend 原生算子(linear / bmm / softmax / layer_norm)
等价重建(状态字典 key 完全一致,仍可严格加载),从而全模型在 NPU 上执行,无任何
CPU 回退。实测 forward_elapsed_s = 7.2358。
npu:0(物理设备 0),Ascend910B4-1,torch_npu 2.9.0。ASCEND_RT_VISIBLE_DEVICES,逻辑设备号等于物理设备号;
requested_device=npu:0、physical_device=0。model.safetensors(995,600,180 B)以 strict=True 加载,143/143 key 全匹配,
SHA256 75456915b0b6d09b444b43ab1ef803a0b129a9a1938d9d92ccaae4d7592def90。npu:0;
缺失/失效 NPU 时失败关闭(非零退出,绝不静默回退 CPU)。inference.py 上报容器 pid=322092、宿主 host_pid=3673958,
物理 npu-smi 在持有期间捕获 NPU 0 进程 PID 3673958(1140 MB,与全量权重相符)——
PID CORRELATION: MATCH。forward_elapsed_s = 7.235773,输出 (1, 2935),全为有限值。本任务使用镜像自带的 CANN 匹配版本,禁止替换 torch / torch_npu:
| 组件 | 版本 | 来源 |
|---|---|---|
| Python | 3.11.14 | 运行镜像 |
| torch | 2.9.0+cpu | 运行镜像(CANN 匹配,勿替换) |
| torch_npu | 2.9.0 | 运行镜像(CANN 匹配,勿替换) |
| CANN | 8.5.1 | 运行环境 |
| 芯片 | Ascend910B4-1 × 8 | 物理 NPU(本次使用 npu:0) |
| numpy | 1.26.4 | 运行镜像 |
| safetensors | 0.6.2 | 运行镜像 |
| Pillow | 12.3.0 | Aliyun 镜像补充安装(仅用于生成证据 PNG) |
非 torch 应用依赖通过 Aliyun pip 镜像安装:
pip install --index-url https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt前置条件:本地模型目录存在且完整
/work/pipeline/models/other40/metadata/deepplant-gep/(含 config.json、
model.safetensors、README.md)。
进入交付目录
cd /work/pipeline/jobs/other40/deepplant-gep/deepplant-gep-npu确认 NPU 设备可用(不设置 ASCEND_RT_VISIBLE_DEVICES)
npu-smi info # 应能看到 NPU 0..7,其中 npu:0 空闲
python -c "import torch_npu, torch; print(torch.npu.is_available(), torch.npu.device_count())"
# True 8(如需)通过 Aliyun 镜像安装额外依赖
pip install --index-url https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt运行真实 NPU 推理
python inference.py --device npu:0 --batch 1 --seq-len 100 --seed 0 \
--hold-after-load 15--device npu:0:目标物理设备;缺失/失效时脚本失败关闭。ASCEND_RT_VISIBLE_DEVICES,直接连接物理 npu:0;
若环境中已设置该变量,脚本会失败关闭。--hold-after-load 15:模型加载后保持 NPU 分配 15 秒,便于外部 npu-smi
并发捕获进程 PID(默认 0,即不保持)。logs/npu_result.json(结构化结果)、logs/predictions.npz
((1, 2935) 全量预测与输入种子)、logs/npu_device_call.log
(运行时真实设备调用日志),并在终端打印关键信息。一键验收(可选)
bash run_acceptance.sh该脚本后台启动推理、在持有期间连续抓取 5 次物理 npu-smi、解析
host_pid(来自 /proc/sched_debug)与 NPU 0 进程 PID,打印
PID CORRELATION: MATCH,并把进程表证据追加到 logs/npu_device_call.log,
同时产出原始/脱敏日志。
查看结果
cat logs/npu_result.json
cat logs/npu_inference_sanitized.log
cat logs/npu_device_call.log以下为 2026-08-22 在物理 npu:0 上执行的真实测试命令与输出。
用例 1:一键验收脚本(含并发 PID 捕获)
$ bash run_acceptance.sh
=== launching inference.py on npu:0 (hold-after-load=15s) ===
=== Python container PID = 322092 ===
[DeepPlant-GEP] pid=322092 host_pid=3673958 host=gz.03 start=2026-08-22T19:55:43+00:00
[DeepPlant-GEP] torch=2.9.0+cpu torch_npu=2.9.0
[DeepPlant-GEP] numpy=1.26.4 python=3.11.14
[DeepPlant-GEP] device=npu:0 name=Ascend910B4-1 count=8
[DeepPlant-GEP] 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": 2935, "n_filters": 512, "num_heads": 8, "task": "GEP", "use_pos_encoding": true}
[DeepPlant-GEP] model built, parameters=248667511
[DeepPlant-GEP] loaded checkpoint strict=True keys=143 size=995600180
[DeepPlant-GEP] model placement: params=npu:0 buffers=npu:0
[DeepPlant-GEP] NPU_PID=322092 holding 15.0s for npu-smi capture
[DeepPlant-GEP] input shape=(1, 4, 100) device=npu:0 dtype=torch.float32
[DeepPlant-GEP] output shape=(1, 2935) device=npu:0 dtype=torch.float32
[DeepPlant-GEP] output stats={"first_10": [-0.878240168, -0.478556484, -0.737186432, -0.888940215, -0.685564578, -0.833527267, -0.795461774, -0.863647461, -0.809061170, -0.443870455], "max": 1.39734375, "mean": -0.81550092, "min": -2.1797881, "std": 0.40524673}
[DeepPlant-GEP] forward elapsed(s)=7.2358
[DeepPlant-GEP] wrote logs/npu_result.json
[DeepPlant-GEP] total_wall(s)=26.9548 exit=0
=== host_pid(from inference.py) = 3673958 ===
=== npu_smi_pid(on NPU 0) = 3673958 ===
=== PID CORRELATION: MATCH ===
=== inference.py exit code: 0 ===用例 2:并发 npu-smi 物理设备进程表(持有期间)
| NPU Chip | Process id | Process name | Process memory(MB) |
+===========================+===============+====================================================+
| 0 0 | 3673958 | | 1140 |
| No running processes found in NPU 1 |
| No running processes found in NPU 2 |说明:容器命名空间 PID 322092 对应的宿主命名空间 PID 3673958,与 NPU 0 上
npu-smi 报告的进程 PID 3673958 完全一致;进程内存 1140 MB 与全量权重
(995,600,180 B ≈ 950 MB 参数 + 运行时开销)相符。
用例 3:直接运行
python inference.py --device npu:0 --batch 1 --seq-len 100 --seed 0预期退出码 0,logs/npu_result.json 中 exit_code=0、forward_elapsed_s 约 7.24。
logs/npu_result.json(节选,完整字段见文件):
| 字段 | 值 |
|---|---|
model_id | Addaoud/DeepPlant-GEP |
source_revision | 57d02f6e9bfee46c98c8a0cbc1b835095898a3b6 |
weight_sha256 | 75456915b0b6d09b444b43ab1ef803a0b129a9a1938d9d92ccaae4d7592def90 |
weight_key_count / parameter_count | 143 / 248667511 |
engine / npu_available | torch_npu / true |
requested_device / physical_device | npu:0 / 0 |
device / device_name | npu:0 / Ascend910B4-1 |
input_shape / output_shape | [1, 4, 100] / [1, 2935] |
input_device / model_device / output_device | npu:0 / npu:0 / npu:0 |
forward_elapsed_s | 7.235773 |
output_stats | mean=-0.81550092, std=0.40524673, min=-2.1797881, max=1.39734375 |
host_pid / pid | 3673958 / 322092 |
logs/predictions.npz:predictions (1, 2935) float32(前 10 个值:
[-0.87824017, -0.47855648, -0.73718643, -0.88894022, -0.68556458, -0.83352727, -0.79546177, -0.86364746, -0.80906117, -0.44387046]),
输入种子 input_seed=0、input_shape=[1,4,100]。
| 图片 | 内容 |
|---|---|
assets/agent_workflow.png | 适配工作流(读上下文 → 权重清单 → 真机推理 → 并发 PID → 产物校验) |
assets/modelagent_live_session.png | 本轮真实脱敏 Agent 会话输出(run_acceptance.sh,PID 匹配) |
assets/npu_device_call.png | 物理 npu:0 设备调用日志与 npu-smi 并发进程表证据 |
assets/model_result.png | 推理结果(输出统计、npu_result.json 摘要) |
| 文件 | 说明 |
|---|---|
inference.py | 完整 NPU 推理脚本(架构重建 + 严格加载 + 放置断言 + 同步计时) |
readme.md / README.md | 本说明(两文件字节一致) |
requirements.txt | 非 torch 依赖(Aliyun 镜像安装) |
.gitignore | 忽略字节码/临时产物 |
run_acceptance.sh | 一键真实验收(并发 npu-smi PID 捕获与匹配) |
scripts/validate_metadata.py | 本地元数据/证据校验(上游事实、README、结果 JSON 交叉核对) |
logs/npu_inference.log | 原始运行日志 |
logs/npu_inference_sanitized.log | 脱敏日志(滤除 torch_npu 噪声) |
logs/npu_device_call.log | 真实设备调用日志(运行时由 inference.py 追加写入) |
logs/modelagent_transcript.log | 本轮真实脱敏 Agent 会话文本 |
logs/npu_smi_before.log / npu_smi_capture_{1..5}.log | 运行前 / 持有期间 5 次物理 npu-smi 快照 |
logs/npu_smi_during.log / npu_smi_after.log | 持有期间 / 结束后快照 |
logs/npu_result.json | 结构化推理结果 |
logs/predictions.npz | 全量预测((1, 2935)) |
SHA256SUMS | 交付物 SHA256 校验清单 |
assets/*.png | 四张真实证据图片 |
--seed 固定,可复现),用于证明完整、真实的 NPU
推理链路;不附带任何外部/版权数据。/work/pipeline/models/other40/metadata/deepplant-gep/,运行前必须存在。__pycache__/*.pyc、fusion_result.json
等禁止产物。本适配遵循上游模型卡声明的 MIT 许可。模型权重版权归原作者所有,仅作本地固定版本推理。
环境依赖:torch、torch_npu 与 CANN,详见 requirements.txt。
推理步骤:执行 inference.py 并确认目标设备为 Ascend NPU。
完整测试用例:使用仓库固定测试输入执行一次端到端推理。
输出结果:真实 NPU 结果保存在 logs/npu_result.json。