gcw_6a3w2yXz/DeepPlant-EAP-NPU-model
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

DeepPlant-EAP-NPU (Ascend 910B)

Ascend NPU adapted version of Addaoud/DeepPlant-EAP — plant genomic Expression-Associated Polymorphism predictor (EAP). Original model: https://huggingface.co/Addaoud/DeepPlant-EAP

Model Info

AttributeValue
ModelAddaoud/DeepPlant-EAP
TaskEAP (plant regulatory genomics, 2-feature regression)
ArchitectureCNN backbone (Conv1d 4→512 + 2 residual blocks 512→2048) + Transformer encoder (6 layers, 8 heads, 2048 dim) + Attention pooling + FC (2048→4096→4096→2)
Configembed_dim=2048, n_filters=512, encoder_num_layers=6, num_heads=8, max_seq_length=100, expand_factor=2, dropout=0.2, n_features=2
Weightsmodel.safetensors 947 MB, 143 tensors, strict load PASS (0 missing, 0 unexpected)
Original CodePyTorchModelHubMixin (no extra code in HF repo) — reproduced in model.py

Hardware

PropertyValue
NPUAscend910_9362 (Ascend910_9391 SOC, CANN 8.5.1, npu-smi 25.5.5)
NPU Devices14,15 (logical 0,1) • tested on npu:0
CPUx86_64 / aarch64
Python3.11.14
PyTorch2.9.0+cpu
torch_npu2.9.0.post1+gitee7ba04
safetensors0.6.x
HWHBM 3107/65536 MB idle

Adaptation

  • Exact key mapping for NPU/CPU compatibility:
    • backbone.conv_features.0.conv (512,4,11) + backbone.conv_features.1 BN
    • backbone.conv_network.0 (512→512→512→2048, proj 512→2048 k9) and backbone.conv_network.2 (2048→1024→1024→2048, proj 2048→2048 k5) with layers layer.0/1/3/4/6/7 + project.0/1
    • transformer.encoder.encoder_layers.{0..5}.self_attn.in_proj_weight/bias, out_proj.weight/bias, linear1/2, norm1/2 + transformer.pos_encoder.pe (1,100,2048)
    • attention_pool.to_attn_logits as Parameter (2048,2048) — matches safetensors key without .weight suffix (fixed vs nn.Linear)
    • fc.linear.0 (4096,2048), fc.linear.3 (4096,4096), fc.prediction_head.0 (2,4096)
    • All 143 tensors load with strict=True → 0 missing, 0 unexpected
  • NPU device handling: torch.npu.is_available(), torch.npu.get_device_name(0), model.to("npu:0"), input.to("npu:0"), torch.npu.synchronize() around timing
  • Adaptive pooling to max_seq_length=100 before Transformer (supports any input length 100–2000, e.g. 512, 600, 1000)
  • Attention pooling using learned to_attn_logits matrix (x @ W → softmax → weighted sum)
  • No torch.compile / quantization — pure float32 for deterministic CPU/NPU comparison

Usage

pip install -r requirements.txt
# NPU
python inference.py --device npu:0
# CPU
python inference.py --device cpu

Programmatic:

import torch
from model import DeepPlantEAP
import json

config = json.load(open("/path/to/config.json"))
model = DeepPlantEAP(config)
model.load_pretrained("/path/to/model.safetensors", device="cpu")
device = torch.device("npu:0" if torch.npu.is_available() else "cpu")
model = model.to(device).eval()

# One-hot DNA: (B,4,L), L e.g. 600
# A=0,C=1,G=2,T=3
import numpy as np
def random_one_hot(batch=2, L=600):
    bases = np.random.randint(0,4,size=(batch,L))
    arr = np.zeros((batch,4,L), dtype=np.float32)
    for b in range(batch):
        for l in range(L):
            arr[b, bases[b,l], l] = 1.0
    return torch.from_numpy(arr).to(device)

with torch.no_grad():
    out = model(random_one_hot(2,600))  # (2,2)
print(out)

Input / Output Contract

FieldShapeDtypeDevice
Input x(B,4,L) one-hot DNA, B>=1, L arbitrary (tested 512,600,1000)float32npu:0 / cpu
Output(B,2) EAP predictions (2-dim regression)float32same device

Example (batch 2, L 600):

CPU: [[-0.1315, 0.1368], [-0.1314, 0.1368]]
NPU: [[-0.1315, 0.1368], [-0.1314, 0.1368]]
mae 2.3e-07 cosine 0.9999998

Verification

Device Proof

[DEVICE_PROOF] model param device: npu:0
[DEVICE_PROOF] target device: npu:0
[INFO] npu name 0: Ascend910_9362
[INFO] npu.is_available True device_count 2
torch.npu.is_available() True

Consistency (CPU vs NPU, same seed 42, float32, batch2 L600)

MetricValue
MAE2.31e-07
Max diff4.47e-07
Cosine0.99999982
Thresholdmae < 1e-5, cosine > 0.999 → PASS
Strict load143/143 tensors, 0 missing, 0 unexpected

Performance (synchronized, npu:0 vs cpu)

DeviceBatchLengthAvg latencyMinMax
CPU26004045 ms39274234
NPU (npu:0)26007.71 ms7.667.74
Speedup——525×——

NPU synchronized timing via torch.npu.synchronize() before/after.

NPU Memory

  • Idle: 3107 / 65536 MB
  • Under inference: ~3120 MB (model 947 MB + activations)

Evidence

npu device call perf comparison output distribution

Files

.
├── model.py          # NPU-adapted architecture (exact key mapping)
├── inference.py      # load + NPU/CPU verify + benchmark + asset generation
├── requirements.txt
├── config.json       # HF config (copied for reference)
├── npu_output.json   # NPU verification result
├── cpu_output.json   # CPU baseline
└── assets/
    ├── npu_device_call.png
    ├── perf_comparison.png
    └── output_distribution.png

Limitations

  • Supports fixed n_features=2 (EAP). GEP variant (different n_features) needs config change.
  • Input must be one-hot (4-channel). Raw string preprocessing (A/C/G/T) shown in one_hot_encode() utility.
  • Transformer pinned to max_seq_length=100 via adaptive pooling — longer inputs truncated via pooling, not sliding window.

Citation

Original model: Addaoud/DeepPlant-EAP — https://huggingface.co/Addaoud/DeepPlant-EAP