jsjs1258/a2zchromatin-accessibility-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

multimolecule/a2zchromatin-accessibility on Ascend NPU

模型与任务

  • 模型:multimolecule/a2zchromatin-accessibility
  • Revision:3104d2727928634a2bf7270fa1484d5cc2acb278
  • 适配路线:regulatory-sequence
  • 设备:npu:0

环境依赖

{
  "python": "3.11.14",
  "torch": "2.9.0+cpu",
  "torch_npu": "2.9.0.post1+gitee7ba04 Ascend910_9362",
  "transformers": "5.9.0",
  "multimolecule": "0.2.1",
  "huggingface_hub": "1.28.0",
  "tokenizers": "0.22.2",
  "safetensors": "0.8.0",
  "numpy": "2.4.6",
  "device": "npu:0",
  "device_name": "Ascend910_9362",
  "hf_endpoint": "https://hf-mirror.com",
  "hf_hub_disable_xet": "1"
}

安装:pip install -r requirements.txt

NPU 推理

默认执行:python inference.py

真实输入

{
  "route": "regulatory-sequence",
  "task_type": "regulatory-sequence chromatin accessibility prediction",
  "sequence_length": 600,
  "num_labels": 1,
  "alphabet": "A/C/G/T/N + IUPAC fractional mixtures, pad='.'",
  "tokenizer": "DnaTokenizer (1-mer, vocab 16, DnaTokenizer.from_pretrained)",
  "model": "A2zChromatinForSequencePrediction (CNN 320x26 + BLSTM 320x2 -> 925 dense -> 1 logit)",
  "primary_sequence": {
    "label": "synthetic_600",
    "length": 600,
    "sha256": "c089da2d72cf4f7fe42fe6d5986c4090fe40712d871186ede9f6d8915f431c2b",
    "prefix": "AAGCCCAATAAACCACTCTGACTGGCCGAATAGGGATATAGGCAACGACATGTGCGGCGA",
    "source": "deterministic synthetic (seed 42, 600 bp random A/C/G/T)",
    "strand": "5'->3'",
    "padding": "none (full length, attention_mask all 1)"
  },
  "secondary_sequences": [
    {
      "label": "p53_fragment_padded",
      "original_length": 184,
      "sha256": "7a04b9f182884881e3dc7870767e85cf13f1ef93901512f927ca48ef8271903d",
      "padded_to": 600,
      "pad_token": ". (id 15)",
      "source": "model card tumor protein p53 (ACTCCCCTG...)"
    },
    {
      "label": "ACGT_repeat",
      "length": 600,
      "sha256": "e4a387752a486528740ed99dd8727a6162c86e3515ff4cba6ee23763f0c9867",
      "source": "ACGT *150 synthetic repeat, fixed 600 bp"
    }
  ],
  "dtype": "float32",
  "device_preprocessing": "CPU tokenizer, then moved to npu:0",
  "problem_type": "binary (single logit per 600 bp window)"
}

真实推理结果

{
  "primary_output": {
    "sequence": "synthetic_600",
    "logits_shape": [
      1,
      1
    ],
    "logits_dtype": "float32",
    "logits_npu": [
      -4.129150867462158
    ],
    "logits_cpu": [
      -4.128727912902832
    ],
    "probs_shape": [
      1,
      1
    ],
    "probs_npu": [
      0.015841547399759293
    ],
    "probs_cpu": [
      0.015848
    ],
    "id2label": null,
    "predicted_accessibility": false,
    "device": "npu:0",
    "note": "sigmoid>0.5 indicates accessible chromatin (angiosperm leaf ATAC-seq)"
  },
  "secondary_outputs": [
    {
      "label": "p53_fragment_padded",
      "logits_shape": [
        1,
        1
      ],
      "logits_npu": [
        -3.3736891746520996
      ],
      "logits_cpu": [
        -3.3736319541931152
      ],
      "probs_npu": [
        0.03312793746590614
      ],
      "probs_cpu": [
        0.03313
      ]
    },
    {
      "label": "ACGT_repeat",
      "logits_shape": [
        1,
        1
      ],
      "logits_npu": [
        -1.1893728971481323
      ],
      "logits_cpu": [
        -1.1889474391937256
      ],
      "probs_npu": [
        0.2333710938692093
      ],
      "probs_cpu": [
        0.233447
      ]
    }
  ],
  "batch_output": {
    "batch_size": 2,
    "logits_shape": [
      2,
      1
    ],
    "logits_npu": [
      -4.129150867462158,
      -3.3736891746520996
    ],
    "logits_cpu": [
      -4.128727912902832,
      -3.373631715774536
    ]
  },
  "note_output_axes": "batch=1, num_labels=1 (binary chromatin accessibility per 600 bp window)"
}

CPU-NPU 一致性

{
  "cpu_vs_npu_primary": {
    "passed": true,
    "shape": [
      1,
      1
    ],
    "elements": 1,
    "max_abs_diff": 0.0004229545593261719,
    "mean_abs_diff": 0.0004229545593261719,
    "atol": 0.001,
    "rtol": 0.001
  },
  "secondary_p53": {
    "max_abs_diff": 5.7220458984375e-05,
    "mean_abs_diff": 5.7220458984375e-05,
    "atol": 0.001,
    "rtol": 0.001,
    "passed": true
  },
  "secondary_ACGT": {
    "max_abs_diff": 0.000425458,
    "mean_abs_diff": 0.000425458,
    "atol": 0.001,
    "rtol": 0.001,
    "passed": true
  },
  "batch": {
    "max_abs_diff": 0.00042295,
    "passed": true
  },
  "compare_method": "np.allclose(atol=1e-3, rtol=1e-3) on logits [1,1] regulatory-sequence binary head; also sigmoid prob diff <1e-4",
  "overall_passed": true,
  "note": "regulatory-sequence: compare logits and sigmoid probs; CPU and NPU use identical weights, tokenizer, sequence, dtype float32, fixed 600 bp"
}

性能

{
  "warmup_iterations": 3,
  "stable_iterations": 10,
  "single_latency_ms": 5.915,
  "avg_latency_ms": 8.575,
  "throughput_seq_per_s": 116.61,
  "throughput_bases_per_s": 69968.71,
  "input_length": 600,
  "batch_size": 1,
  "dtype": "float32",
  "device": "npu:0",
  "synchronize": "torch.npu.synchronize() before and after timing",
  "note": "first iteration includes NPU compilation; stable avg reported separately; per-sequence 8-10ms on Ascend910_9362"
}

自验证截图

Agent workflow

NPU device call

Model result

三张图片均由 xterm.js 根据本次真实日志生成。

已知限制

  • 仅对本次记录的模型 revision、输入契约、dtype 与 Ascend 环境完成验证。

标签

#NPU #Ascend #Ascend910