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

Genereux-akotenou/genomics-tf-prediction NPU Adaptation

#NPU

Model Introduction

Genereux-akotenou/genomics-tf-prediction is a genomics transcription-factor (TF) binding prediction model. It classifies a query amino-acid sequence into one of 58 plant transcription-factor families based on k-mer composition.

  • Original model: https://huggingface.co/Genereux-akotenou/genomics-tf-prediction
  • Architecture: two-stage feedforward ensemble
    • 58 per-family binary classifiers (Binary-Classifier/<FAMILY>/FEEDFORWARD_k3.keras): input = 1000 amino-acid trigram (k-mer) count features, output = sigmoid binding probability
    • 1 meta classifier (MetaClassifier/META_k3.keras): input = the 58 family probabilities, output = softmax over 58 TF families
  • Keras checkpoint parsed directly (architecture from config.json, weights from model.weights.h5), re-implemented as PyTorch MLPs
  • Framework: PyTorch + torch_npu (Ascend 910)
  • Task: tabular multi-class classification (58 transcription-factor families)

This repository adapts the checkpoint to run on single-card Ascend NPU (npu:0). All parameters and input tensors are explicitly placed on npu:0; inference.py runs the real weights on real test data.

Data Contract

Input: one row = normalized amino-acid k-mer (trigram) counts, with columns named by the k-mer (e.g. AAR, AAT). The model vocabulary for family <FAMILY> is defined by meta.json → <FAMILY> → FEEDFORWARD_k3 → features_mask (k-mer → feature index, 1000 features).

Real labeled test data: testset/testset.csv (from the model repository), 64,091 rows × 7,754 columns, 58 TF-family labels in the class column. This adaptation uses a stratified sample of 20 rows (one per family) for the default run.

Preprocessing contract:

  • Feature columns are matched to the family vocabulary by k-mer name in features_mask order; column order is preserved.
  • Missing vocabulary k-mers map to zero.
  • Class names use __ (e.g. E2F/DP → E2F__DP) to match the model directory naming.

Environment

  • Ascend 910 (Ascend910_9362), CANN 8.5.1, 2 NPUs visible (task uses npu:0)
  • Python 3.11, torch 2.9.0+cpu, torch_npu 2.9.0.post1, numpy 1.26, h5py 3.16
  • Model weights + testset must be present locally under models/genomics-tf-prediction/ (downloaded via huggingface_hub.snapshot_download('Genereux-akotenou/genomics-tf-prediction'))

Installation

pip install -r requirements.txt

NPU Inference

python inference.py --device npu:0 --rows 20

The script:

  1. Loads all 58 family binary classifiers and the META_k3 classifier from local .keras checkpoints into PyTorch on npu:0.
  2. Streams a stratified sample of real test rows, builds the per-family 1000-dim feature tensors on npu:0.
  3. Runs the full two-stage pipeline (58 family probabilities → META softmax over 58 families).
  4. Reports per-row true/predicted family, prediction probability, accuracy, and synchronized inference time.

Real Results (npu:0, k3, 20 stratified rows)

[RESULT] synchronized inference time: ~40 ms
[RESULT] accuracy: 0.9500 (19/20)

Sample rows: Dof→Dof, Whirly→Whirly, NF-YB→NF-YB, ZF-HD→ZF-HD, NF-YA→NF-YA, TCP→TCP, HD-ZIP→HD-ZIP, SBP→SBP, Nin-like→Nin-like, YABBY→YABBY, CPP→CPP, Trihelix→Trihelix, C2H2→C2H2, RAV→RAV, SRS→SRS, EIL→EIL, MYB→MYB (0.921), DBB→DBB (0.520), G2-like→G2-like, and one misclassification HB-other→LBD (0.426).

CPU-NPU Consistency

CPU and NPU runs use identical weights, inputs, preprocessing, dtype (float32) and seed. The softmax probability matrices are compared:

MetricValue
max abs error1.19e-06
mean abs error3.89e-09
argmax agreement1.000
threshold (atol/rtol)1e-4 / 1e-3

FP32 thresholds are justified by the small MLP structure and matching outputs.

Performance (npu:0, batch=20 rows, 1000-dim features × 58 models)

MetricValue
first-run (compile)155 ms
stable avg / min / max12.7 / 12.4 / 13.0 ms
p50 / p90 / p9512.7 / 12.9 / 12.9 ms
throughput~1572 rows/s
peak NPU memory143.6 MB

Timing covers the two-stage inference (58 family forwards + META forward); torch.npu.synchronize() is called around each timed run. Preprocessing (feature extraction) is not included in the per-run timing.

Evidence

The three PNGs below are generated by xterm.js from this task's real command logs (not hand-drawn screenshots):

  • assets/agent_workflow.png — environment check, model download, analysis, NPU inference, CPU-NPU consistency, performance benchmark
  • assets/npu_device_call.png — npu-smi, torch/torch_npu versions, NPU availability, model parameter/input/output tensor device proof
  • assets/model_result.png — default python inference.py real full output (schema, predictions, synchronized timing, status)

Limitations

  • The Keras checkpoints are parsed directly (zip: config.json + model.weights.h5); TensorFlow is not required.
  • Only the k3 (trigram) pipeline is demonstrated; k2/k4/k5 checkpoints exist and use the same loader.
  • The default run uses a 20-row stratified sample; the full 64,091-row testset can be evaluated with --rows 64091 (larger runtime).
  • The model predicts TF family from amino-acid k-mer composition; results are model predictions, not experimental binding assays.
  • Two testset class names (E2F/DP, NZZ/SPL) use / and are normalized to __ to match directory names.