liucu/pangolin-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

multimolecule/pangolin on Ascend NPU

模型与任务

  • 模型:multimolecule/pangolin
  • Revision:39f9ff44ed65f773099c363712934d13c277c8d0
  • 适配路线:splicing
  • 设备:npu:0

环境依赖

{
  "torch": "2.9.0+cpu",
  "torch_npu": "2.9.0.post1+gitee7ba04",
  "torch_npu_available": true,
  "npu_device_name": "Ascend910_9362",
  "device_count": 2,
  "cann": "8.5.1",
  "hf_endpoint": "https://hf-mirror.com",
  "multimolecule": "0.2.1",
  "python": "3.11",
  "transformers": "5.9.0"
}

安装:pip install -r requirements.txt

NPU 推理

默认执行:python inference.py

真实输入

{
  "route": "splicing",
  "alphabet": "RNA A/C/G/U/N (vocab 5, pad N id4, replace_T_with_U true)",
  "strand": "5'->3' forward",
  "sequence_length": 500,
  "vocab_size": 5,
  "batch": 1,
  "primary_sequence_name": "long_500",
  "primary_sha256": "90635e342b8b4e7b951d7a68a87e2be05046768aba036d393c2cc62cf39db4cc",
  "primary_seq_preview": "ACUGACUGACUGACUGACUGACUGACUGACUGACUGACUGACUGACUGACUGACUGACUGACUGACUGACUGACUGACUG...",
  "all_sequences": {
    "mir21_22": {
      "length": 22,
      "sha256": "9c1b1cd23c45d39dd0b1fb28d72c49c0edcc57a16cb61c96119f84676c4b5b1c",
      "preview": "UAGCUUAUCAGACUGAUGUUGA"
    },
    "mir146a_22": {
      "length": 22,
      "sha256": "69b373dd39e7a0ddc08a8a20a893900cc1bdccbf181b135d55459789829d006a",
      "preview": "UGAGAACUGAAUUCCAUGGGUU"
    },
    "insulin_333": {
      "length": 333,
      "sha256": "f94af5b8cf66600fae963521f441dcb6c933e2d93165ba93bcafa3941ca946fc",
      "preview": "AUGGCCCUGUGGAUGCGCCUCCUGCCCCUGCUGGCGCUGCUGGCCCUCUGGGGACCUGACCCAGCCGCAGCCUUUGUGAA..."
    },
    "myc_5utr_363": {
      "length": 363,
      "sha256": "94627a13baef9ae201b956d3c9692e0511fafdf1b6143d4d552de2a7ee9c8756",
      "preview": "AACUCGCUGUAGUAAUUCCAGCGAGAGGCAGAGGGAGCGAGCGGGCGGCCGGCUAGGGUGGAAGAGCCGGGCGAGCAGAG..."
    },
    "long_500": {
      "length": 500,
      "sha256": "90635e342b8b4e7b951d7a68a87e2be05046768aba036d393c2cc62cf39db4cc",
      "preview": "ACUGACUGACUGACUGACUGACUGACUGACUGACUGACUGACUGACUGACUGACUGACUGACUGACUGACUGACUGACUG..."
    },
    "var_ref_200": {
      "length": 200,
      "sha256": "a7574c0a524f62983d9b3817317ddd4e67bc3f8bafade0c0fe84fe24456099ec",
      "preview": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA..."
    },
    "var_alt_200": {
      "length": 200,
      "sha256": "20b77c15249130076640656e74ba034e7025ea86ab0d19fd1e13d953ea786121",
      "preview": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA..."
    },
    "dna_18_T2U": {
      "length": 18,
      "sha256": "6739014a2c0cbad13515a348c6ad3d69151cc67a0661f314153ac7587387b8db",
      "preview": "AGCAGTCATTATGGCGAA (DNA->RNA valid)"
    }
  },
  "tokenizer": "RnaTokenizer 1-mer, pad=N id4, replace_T_with_U true, model_max_length huge",
  "model_dir": "/tmp/pangolin_model",
  "revision": "39f9ff44ed65f773099c363712934d13c277c8d0",
  "species": "human (and cross-species: rhesus, rat, mouse via multitissue training)",
  "task": "tissue-specific splice site strength: per-nucleotide 12 channels = 4 tissues x 3 (no_splice, splice_site, usage)",
  "output_contract": "probabilities shape (batch, L, 12) float32, channels heart/liver/brain/testis, softmax for splice_site, sigmoid for usage",
  "source": "model card widget ncRNA/mRNA + synthetic 500 nt ACUG repeat with GUGAGU donor motif + variant delta demo",
  "contexts": "Embedding adds context//2=5000 N padding each side internally, then trimmed; variable length supported"
}

真实推理结果

{
  "probabilities_shape": [
    1,
    500,
    12
  ],
  "last_hidden_shape": [
    1,
    500,
    32
  ],
  "probabilities_dtype": "float32",
  "device": "npu:0",
  "channel_names": [
    "heart_no_splice",
    "heart_splice_site",
    "heart_usage",
    "liver_no_splice",
    "liver_splice_site",
    "liver_usage",
    "brain_no_splice",
    "brain_splice_site",
    "brain_usage",
    "testis_no_splice",
    "testis_splice_site",
    "testis_usage"
  ],
  "tissue_names": [
    "heart",
    "liver",
    "brain",
    "testis"
  ],
  "per_tissue_stats": {
    "heart": {
      "no_splice_mean": 0.9461,
      "no_splice_max": 0.951,
      "splice_site_mean": 0.0539,
      "splice_site_max": 0.1096,
      "usage_mean": 0.036,
      "usage_max": 0.0663,
      "usage_min": 0.0231
    },
    "liver": {
      "no_splice_mean": 0.9501,
      "no_splice_max": 0.9542,
      "splice_site_mean": 0.0499,
      "splice_site_max": 0.0901,
      "usage_mean": 0.0116,
      "usage_max": 0.0267,
      "usage_min": 0.0058
    },
    "brain": {
      "no_splice_mean": 0.9444,
      "no_splice_max": 0.9503,
      "splice_site_mean": 0.0556,
      "splice_site_max": 0.1149,
      "usage_mean": 0.0203,
      "usage_max": 0.0491,
      "usage_min": 0.0132
    },
    "testis": {
      "no_splice_mean": 0.948,
      "no_splice_max": 0.952,
      "splice_site_mean": 0.052,
      "splice_site_max": 0.1071,
      "usage_mean": 0.0071,
      "usage_max": 0.0296,
      "usage_min": 0.0041
    }
  },
  "center_position": 250,
  "center_probabilities": [
    0.945673,
    0.054327,
    0.026739,
    0.949003,
    0.050997,
    0.010204,
    0.941149,
    0.058852,
    0.020969,
    0.948441,
    0.051559,
    0.005238
  ],
  "top3_splice_sites": {
    "heart": {
      "indices": [
        498,
        246,
        499
      ],
      "scores": [
        0.10959748178720474,
        0.09874288737773895,
        0.09633336961269379
      ]
    },
    "liver": {
      "indices": [
        499,
        246,
        498
      ],
      "scores": [
        0.09007583558559418,
        0.08999583125114441,
        0.08840451389551163
      ]
    },
    "brain": {
      "indices": [
        498,
        499,
        246
      ],
      "scores": [
        0.11491343379020691,
        0.10831553488969803,
        0.08374091237783432
      ]
    },
    "testis": {
      "indices": [
        499,
        498,
        246
      ],
      "scores": [
        0.10707277059555054,
        0.09573191404342651,
        0.08178021013736725
      ]
    }
  },
  "variant_effect": {
    "position": 100,
    "ref_motif": "GUAAGU",
    "alt_motif": "GCAAGU",
    "ref_probs": [
      0.9542083740234375,
      0.045791663229465485,
      0.04045270383358002,
      0.9419341087341309,
      0.05806594341993332,
      0.02658834308385849,
      0.9538190364837646,
      0.046181004494428635,
      0.015404590405523777,
      0.9501606225967407,
      0.049839407205581665,
      0.013318940997123718
    ],
    "alt_probs": [
      0.951728880405426,
      0.04827111214399338,
      0.03718547150492668,
      0.9421825408935547,
      0.0578174814581871,
      0.024086251854896545,
      0.9536075592041016,
      0.04639248177409172,
      0.015210933983325958,
      0.9500598907470703,
      0.049940094351768494,
      0.011568084359169006
    ],
    "delta": [
      -0.0024794936180114746,
      0.002479448914527893,
      -0.0032672323286533356,
      0.0002484321594238281,
      -0.0002484619617462158,
      -0.0025020912289619446,
      -0.00021147727966308594,
      0.00021147727966308594,
      -0.00019365642219781876,
      -0.00010073184967041016,
      0.00010068714618682861,
      -0.001750856637954712
    ],
    "max_abs_delta": 0.050442,
    "mean_abs_delta": 0.001103
  },
  "multi_length_validation": {
    "mir21_22": [
      1,
      22,
      12
    ],
    "insulin_333": [
      1,
      333,
      12
    ],
    "long_500": [
      1,
      500,
      12
    ]
  },
  "dtype": "torch.float32",
  "id2label": null,
  "problem_type": "regression"
}

CPU-NPU 一致性

{
  "passed": true,
  "probabilities": {
    "passed": true,
    "shape": [
      1,
      500,
      12
    ],
    "elements": 6000,
    "max_abs_diff": 0.00010498613119125366,
    "mean_abs_diff": 1.8174082040786744e-05,
    "atol": 0.001,
    "rtol": 0.001
  },
  "note": "CPU and NPU use identical weights, tokenizer, 500 nt ACUG repeat long_500, float32 probabilities (biological output), tissue channels preserved",
  "tolerance": {
    "atol": 0.001,
    "rtol": 0.001
  },
  "max_abs_diff": 0.00010498613119125366,
  "mean_abs_diff": 1.8174082040786744e-05,
  "shape": [
    1,
    500,
    12
  ],
  "elements": 6000
}

性能

{
  "avg_ms_per_iter": 1009.77,
  "p50_ms_per_iter": 1009.73,
  "throughput_seq_per_s": 0.99,
  "throughput_bases_per_s": 495.2,
  "batch": 1,
  "sequence_length": 500,
  "tracks": 12,
  "tissue_channels": "4 tissues x 3 =12",
  "dtype": "float32",
  "warmup": 3,
  "stable_iters": 10,
  "synchronize": "torch.npu.synchronize before/after timing",
  "peak_hbm_mb": 3254,
  "device": "npu:0"
}

自验证截图

Agent workflow

NPU device call

Model result

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

已知限制

  • 仅对本次记录的模型 revision、输入契约、dtype 与 Ascend 环境完成验证。
  • Pangolin 输出为 per-nucleotide 12通道概率 (softmax/sigmoid 已激活),非 logits;变异效应 delta 基于同一参考/替代对计算。
  • 长序列上下文 10000 导致内部 padding 开销大,500 nt 已触发 ~1s/iter;更长序列需显存预判。

标签

#NPU #Ascend #Ascend910