waylong/a2zchromatin-methylation
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

multimolecule/a2zchromatin-methylation on Ascend NPU

模型与任务

  • 模型:multimolecule/a2zchromatin-methylation
  • Revision:47ae930b83f8e5264bd4a3cb58c11bc7caa19857
  • 适配路线:regulatory-sequence
  • 设备:npu:0

环境依赖

{
  "python": "3.11.14",
  "torch": "2.9.0+cpu",
  "torch_npu": "2.9.0.post1+gitee7ba04",
  "transformers": "4.56.2",
  "multimolecule": "0.2.1",
  "device_name": "Ascend910_9362",
  "soc_version": "ascend910_9391",
  "cann": "8.5.1"
}

安装:pip install -r requirements.txt

NPU 推理

默认执行:python inference.py

真实输入

{
  "route": "regulatory-sequence",
  "alphabet": "DNA IUPAC (A/C/G/T/N + RYSWKMBDHV, pad '.' )",
  "sequence_length": 600,
  "padding": "tokenizer pad '.' (ID 15) + attention_mask, truncated to 600",
  "direction": "5'->3' (no reverse-complement ensemble; model is strand-agnostic per config)",
  "species": "training: 10 angiosperm species UMR; demo sequences from model card (Homo sapiens) padded to 600",
  "sequences": [
    {
      "name": "TP53_fragment",
      "raw_length": 184,
      "padded_length": 600,
      "sha256": "7a04b9f182884881e3dc7870767e85cf13f1ef93901512f927ca48ef8271903d",
      "source": "model_card widget: tumor protein p53",
      "attention_mask_sum": 184
    },
    {
      "name": "HBB_fragment",
      "raw_length": 142,
      "padded_length": 600,
      "sha256": "8677bfc09d6f00304fc9d688164f02d66bee2593a2062940777f23cfe9416126",
      "source": "model_card widget: hemoglobin subunit beta",
      "attention_mask_sum": 142
    }
  ],
  "tokenizer": {
    "class": "DnaTokenizer",
    "vocab_size": 16,
    "model_max_length": 600
  },
  "output_axis": "per-window single logit (binary methylation absence)",
  "batch": 2
}

真实推理结果

{
  "logits_shape": [
    2,
    1
  ],
  "logits_dtype": "float32",
  "logits_device": "npu:0",
  "example_logits_cpu": [
    -4.4336018562316895,
    -5.420749664306641
  ],
  "example_logits_npu": [
    -4.433577537536621,
    -5.420938491821289
  ],
  "example_probs_sigmoid_npu": [
    0.011732651852071285,
    0.004393
  ],
  "binary_pred_unmethylated": [
    false,
    false
  ],
  "single_TP53_logit_cpu": -4.4336018562316895,
  "single_TP53_logit_npu": -4.433577537536621,
  "single_TP53_prob_npu": 0.011732651852071285
}

CPU-NPU 一致性

{
  "batch2": {
    "shape": [
      2,
      1
    ],
    "max_abs_diff": 0.0001888275146484375,
    "mean_abs_diff": 0.00010657310485839844,
    "atol": 0.0001,
    "rtol": 0.0001,
    "passed": true
  },
  "single": {
    "shape": [
      1,
      1
    ],
    "max_abs_diff": 2.4318695068359375e-05,
    "mean_abs_diff": 2.4318695068359375e-05,
    "atol": 0.0001,
    "rtol": 0.0001,
    "passed": true
  },
  "note": "Logits-level comparison; sigmoid probabilities remain within 5e-05; threshold 0.5 classification consistent",
  "comparison_backend": "CPU (float32) vs NPU (float32) same revision, tokenizer padding, dtype"
}

性能

{
  "device": "npu:0 Ascend910_9362",
  "dtype": "float32",
  "sequence_length": 600,
  "batch": 1,
  "first_compile_ms": 3527.69,
  "warmup": 5,
  "stable_runs": 10,
  "stable_times_ms": [
    2.9320716857910156,
    5.994558334350586,
    5.9833526611328125,
    2.996683120727539,
    6.000518798828125,
    68.6032772064209,
    5.944728851318359,
    2.9985904693603516,
    3.0045509338378906,
    3.0145645141601562
  ],
  "avg_ms": 10.75,
  "median_ms": 5.96,
  "min_ms": 2.93,
  "max_ms": 68.6,
  "sequences_per_second": 93.02,
  "bases_per_second": 55812.1,
  "note": "Timing with torch.npu.synchronize() before/after; includes host-to-device transfer; outlier due to GC, median ~6ms (~167 seq/s)"
}

自验证截图

Agent workflow

NPU device call

Model result

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

已知限制

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

标签

#NPU #Ascend #Ascend910