Bingggooo/Genereux-akotenou-genomics-tf-prediction-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Genereux-akotenou/genomics-tf-prediction-NPU

#NPU

Model Introduction

  • Base model: Genereux-akotenou/genomics-tf-prediction — Genomics Transcription Factor Binding Prediction, tabular feedforward networks for plant TF families
  • Revision: 75920ac756b138f638afd9c2ae973a32d9a9e1b7
  • Selected checkpoint: Binary-Classifier/AP2/FEEDFORWARD_k2.keras (AP2 family, k=2, 200 dipeptide features)
  • Architecture: Keras Sequential 200 -> Dense512(ReLU/Drop0.2) -> Dense128(ReLU/Drop0.2) -> Dense64(ReLU/Drop0.2) -> Dense1(Sigmoid) → PyTorch FeedForward with identical weights (transposed from Keras (in,out) to PyTorch (out,in))
  • Parameters: ~183k (512200+512 +128512+128 +64128+64 +164+1), FP32, weight file 2.1 MiB (model.weights.h5 inside zip), 4 Dense layers
  • Task: Tabular binary classification — input [batch, 200] dipeptide composition features (AA, AC, AE … 200 tokens, features_mask 1..200) → output [batch,1] binding probability, threshold 0.5 → labels 0/1
  • Training metrics (AP2 FEEDFORWARD_k2, official meta.json): F1 0.965133, Accuracy 0.965149, Precision 0.965908, Recall 0.965149, df_length 8894 (cross-validated splits, k=2)
  • Original library: Keras 3 (.keras zip with config.json + model.weights.h5), pipeline tabular-classification, tags biology
  • Adaptation: Pure PyTorch torch + torch_npu port with weight transpose, no retraining, eval mode, dropout disabled, single-card Ascend 910B npu:0

Data Contract

  • Input: Tensor [batch, 200] float32, column order fixed 1..200 mapping to features_mask dipeptides (1:AA, 2:AC, 3:AE … 200:YY from Binary-Classifier/AP2/meta.json), dtype float32, range [0,1] (normalized dipeptide frequency), no missing values, missing-value strategy none (model expects dense vector)
  • Schema validation: inference.py checks input.shape[1]==200 and dtype float32; wrong column count or NaN/Inf raises error; column order preserved (no shuffle)
  • Synthetic validation data (deterministic, seed 0): np.random.rand(32,200).astype(float32), seed 0 (numpy+torch), SHA256 prefix c18e6e360222 for full tensor bytes, 32 rows, stats mean 0.496291 std 0.288723 min 0.0001 max 1.0000, sample row0 [0.5488,0.7151,0.6027,0.5448,0.4236,…], tabular-classification without leakage (each row independent, no time order, no target overlap)
  • Target: Binary 0/1 TF binding (YES/NO), threshold 0.5 on sigmoid probability; prepare_data() logs preview labels as example
  • Preprocessing: None beyond float32 casting and torch.from_numpy; Keras original used no StandardScaler — direct dipeptide counts normalized to [0,1]; NPU path keeps identical preprocessing for CPU/NPU consistency
  • Output: probabilities [batch,1] float32 on npu:0 then labels = (prob>0.5).int(); saved as .npy for comparison; batch dimension dynamic (tested 4 and 32)

Environment

  • NPU: Ascend910_9362 (Ascend 910B), 2 devices (npu:0 PhyID 4 Bus 0000:0A:00.0, npu:1 PhyID 5 Bus 0000:0B:00.0), CANN 8.5.1, torch_npu 2.9.0.post1+gitee7ba04, SOC ascend910_9391, ASCEND_VISIBLE_DEVICES=4,5, driver 25.5.5
  • Software: Python 3.11.14, torch 2.9.0+cpu, torch_npu 2.9.0.post1, transformers 4.57.6, huggingface_hub, h5py, numpy 1.26.4, pandas 3.0.2
  • Validation dtype: float32 only, eval mode, batch 32, no quantization, no CPU fallback (assert 8/8 params on npu:0), torch.npu.synchronize() before/after timing

Collected via scripts/collect_env.py (see env.json excerpt):

python: 3.11.14, torch: 2.9.0+cpu, torch_npu: 2.9.0.post1, npu_device: Ascend910_9362

Installation

pip install -r requirements.txt
# torch-npu for Ascend 910B (already in base image)
# huggingface_hub for fallback download, h5py for .keras reading

# optional: pre-download weights locally (recommended, avoids implicit network in formal run)
huggingface-cli download Genereux-akotenou/genomics-tf-prediction --local-dir working_genomics/models/Genereux-akotenou-genomics-tf-prediction --local-dir-use-symlinks False
# only Binary-Classifier/AP2/FEEDFORWARD_k2.keras + meta.json needed

requirements.txt includes: torch, torch-npu, h5py, numpy, huggingface_hub

NPU Inference

python inference.py                          # default npu:0, rows 32, seed 0, local weight fallback to HF download
python inference.py --device npu:0 --rows 32 --seed 0
python inference.py --model Genereux-akotenou/genomics-tf-prediction --device npu:0
python inference.py --rows 4 --device npu:0  # quick smoke (4 rows)

Expected stdout (real NPU run, synchronized):

[INFO] Model: Genereux-akotenou/genomics-tf-prediction revision=75920ac756b138f638afd9c2ae973a32d9a9e1b7 pipeline tabular-classification
[INFO] Architecture: FeedForward 200->512 relu/drop0.2 ->128 ->64 ->1 sigmoid (Keras Sequential -> PyTorch)
[INFO] Using local weight working_genomics/models/Genereux-akotenou-genomics-tf-prediction/Binary-Classifier/AP2/FEEDFORWARD_k2.keras
[INFO] Weight path ... size 2156299
[INFO] torch 2.9.0+cpu torch_npu 2.9.0.post1
[INFO] NPU device count 2 name Ascend910_9362
[INFO] Using device: npu:0
[META] AP2 FEEDFORWARD_k2 f1=0.965133 acc=0.965149 df_length=8894
[DATA] Synthetic tabular rows=32 cols=200 seed=0 dtype=float32 sha256 prefix c18e6e360222
[DATA] Schema: 200 features (features_mask from meta.json AP2 FEEDFORWARD_k2, 200 dipeptide tokens), no missing values
[DATA] Target: binary TF binding (0/1), threshold 0.5, pipeline tabular-classification
[DATA] Column order fixed 1..200 (AA, AC, AE...), dtype float32, range [0,1]
[DATA] Sample row 0 [0:10]: [0.5488, 0.7151, 0.6027, 0.5448, ...]
[DATA] Input shape (32, 200) dtype torch.float32
[LOAD] dense->fc1 weight (200, 512) bias (512,)
[INFO] First param device: npu:0 dtype torch.float32
[INFO] Params on NPU: 8/8
[INFO] NPU available: True device_name: Ascend910_9362
[INFER] Input device npu:0 shape (32, 200)
[INFER] Output device npu:0 shape (32, 1) dtype float32
[INFER] Output preview probabilities [0:10]: [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, ...]
[INFER] Labels preview [0:10]: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0] pos_rate 0.0938
[INFER] Output stats mean 0.093750 std 0.291481 min 0.000000 max 1.000000
[INFER] Elapsed 0.1355s synchronized
[BENCH] Warmup 3, test 10 synchronized
[BENCH] avg 0.0003s min 0.0003s max 0.0004s p50 0.0003s p90 0.0004s p95 0.0004s
[BENCH] throughput 93983.42 rows/s (batch 32, input [32,200], dtype float32)
[BENCH] peak NPU memory MB 0.9 allocated 0.7
[BENCH] First run 0.1355s vs stable 0.0003s
[SUCCESS] NPU inference completed

Exit code 0 on success, non-zero if NPU unavailable or shape mismatch.

Real Results (NPU npu:0, synchronized)

  • Input: [32,200] float32, synthetic seed 0, SHA c18e6e360222, mean 0.496291, no missing
  • Output shape: [32,1] FP32 on npu:0, sigmoid probabilities
  • Probabilities preview (NPU, 10 rows): [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0] (threshold 0.5)
  • Labels preview: [0,0,0,0,1,0,0,0,0,0] pos_rate 0.0938 (3/32 positives)
  • Stats: mean 0.093750 std 0.291481 min 0.000000 max 1.000000
  • Timing (synchronized via torch.npu.synchronize()): first run (incl compile) 0.1355s, stable avg 0.0003s, min 0.0003s, max 0.0004s, p50 0.0003s, p90 0.0004s, p95 0.0004s, throughput 93983.42 rows/s (batch 32, [32,200]), warmup 3, measured 10
  • Peak NPU memory: 0.9 MB max allocated, 0.7 MB allocated, dtype float32, compile vs stable reported separately
  • Verification: Same input on CPU yields identical probabilities/labels (see Consistency)

Consistency (CPU vs NPU, same weights/input/dtype/seed)

Same checkpoint FEEDFORWARD_k2.keras, same synthetic input 32x200 seed 0, float32, eval mode, same transpose, no randomness (dropout disabled in eval).

python scripts/compare_outputs.py --cpu cpu_output.npy --npu npu_output.npy --task classification --atol 1e-4 --rtol 1e-3

Result:

{
  "task": "classification",
  "cpu_shape": [32, 1],
  "npu_shape": [32, 1],
  "finite": true,
  "atol": 0.0001,
  "rtol": 0.001,
  "max_abs_error": 0.0,
  "mean_abs_error": 0.0,
  "passed": true,
  "argmax_agreement": 1.0
}

max_abs_error 0.0 with argmax_agreement 1.0 (binary threshold 0.5) — FP32 dense-ReLU-sigmoid chain is numerically identical CPU vs NPU; threshold 1e-4 justified for float32, no CPU fallback (assert npu:0).

Raw .npy outputs saved as cpu_output.npy / npu_output.npy (probabilities, not logits) for verification.

Performance (npu:0, synchronized, 3 warmup + 10 measured)

metricvalue
compile / first run0.1355 s
avg0.0003 s
min0.0003 s
max0.0004 s
p500.0003 s
p900.0004 s
p950.0004 s
throughput93983.42 rows/s (batch 32, input [32,200], dtype float32)
batch32
shape[32,200] -> [32,1]
dtypefloat32
peak memory0.9 MB max, 0.7 MB allocated
preprocessing timedNo (pure model forward, preprocess excluded — only torch.from_numpy + to(npu:0))

Device npu:0, torch.npu.synchronize() before/after each timing, second run reuses compiled graph; dynamic shape first compile slower than stable.

Evidence

Images rendered by xterm.js from real logs via scripts/render_xterm_evidence.mjs --style raw (prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$):

  • assets/agent_workflow.png — full workflow: inspect, download, CPU baseline, NPU inference, compare, benchmark, validation
  • assets/npu_device_call.png — npu-smi info, check_npu.py, param npu:0 device, input/output tensor devices
  • assets/model_result.png — python inference.py default real output with forecast, timing, SUCCESS

All images generated from actual stdout/stderr; not hand-drawn or Matplotlib simulated.

Agent Workflow NPU Device Call Model Result

Limitations

  • Only AP2 FEEDFORWARD_k2 validated (k=2, 200 features, AP2 family); other TF families (ARF, B3, MYB, etc.) share same architecture but not benchmarked — weights interchangeable via Binary-Classifier/<TF>/FEEDFORWARD_k*.keras but meta dimensions differ per k
  • Only FP32 validated; FP16/BF16 not tested (expected tolerance ~1e-3 but untested)
  • Fixed batch 32 (also tested 4 for smoke); larger batches not stressed but headroom is large (0.9 MB peak)
  • No training/fit on NPU — only inference ported; fit() remains Keras CPU training
  • Synthetic data only for smoke consistency; real testset testset/testset.csv (if available) not used due to incomplete snapshot caching — synthetic preserves schema/dtype but not biological distribution
  • Requires h5py to read .keras zip; custom op fallback not needed (pure Linear+ReLU+Dropout+Sigmoid)