jsjs1258/pangolin
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

multimolecule/pangolin on Ascend NPU

模型与任务

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

环境依赖

{
  "multimolecule": "unknown",
  "torch": "2.9.0+cpu",
  "torch_npu": "2.9.0.post1+gitee7ba04",
  "transformers": "5.9.0",
  "numpy": "2.4.6",
  "python": "3.11.14",
  "npu_name": "Ascend910_9362",
  "npu_available": true,
  "device_count": 2
}

安装:pip install -r requirements.txt

NPU 推理

默认执行:python inference.py

真实输入

{
  "sequences": [
    {
      "name": "ref_BRCA1_exon_fragment",
      "length": 222,
      "sha256": "fecd6271523cd254e360ae77b5361974c91cb9662010cb6eb2796b74184d9280",
      "alphabet": "DNA A/C/G/T/N",
      "direction": "5'->3'",
      "species": "Homo_sapiens",
      "source": "BRCA1 exon synthetic fragment"
    },
    {
      "name": "alt_BRCA1_SNV",
      "length": 222,
      "sha256": "010281daf7701d51c1e46262849e0ab8cf97f9312c302cb5903d1d1ddbd17c05",
      "variant": "C->G at offset ~110 (reference base check)",
      "reference_sha256": "fecd6271523cd254e360ae77b5361974c91cb9662010cb6eb2796b74184d9280"
    },
    {
      "name": "smoke_periodic",
      "length": 116,
      "sha256": "944ca2e8235b0aadda686bf53e14504ffdca382d9123f6c3cede31c5380175a2",
      "alphabet": "RNA A/C/G/U/N"
    }
  ],
  "tokenizer": "RnaTokenizer replace_T_with_U=True vocab A:0 C:1 G:2 U:3 N:4 pad_token_id:4",
  "batch_size": 3,
  "padding": "right, padded to max_len 222",
  "context": 10000,
  "output_axis": "per-nucleotide per-tissue [B,L,12] where 12=4 tissues * (2 score + 1 usage)",
  "preprocessing": "CPU tokenization then .to(npu:0)",
  "masking": "attention_mask 1=valid 0=pad, valid positions only used for consistency"
}

真实推理结果

{
  "model": "PangolinModel",
  "probabilities_shape": [
    3,
    222,
    12
  ],
  "last_hidden_shape": [
    3,
    222,
    32
  ],
  "dtype": "float32",
  "device": "npu:0",
  "tissues": [
    "heart",
    "liver",
    "brain",
    "testis"
  ],
  "channels_per_tissue": 3,
  "channel_semantics": "per tissue: channel0 non-splice score (softmax), channel1 splice score, channel2 splice usage (sigmoid)",
  "sample_statistics": "see inference.py logs: per-tissue max/mean values validated; variant effect |alt-ref| max 0.0024 mean 0.00022, top delta pos 103"
}

CPU-NPU 一致性

{
  "comparison": "CPU (float32) vs NPU (float32) same weights, same input_ids, deterministic",
  "probabilities_atol": 0.0002,
  "probabilities_rtol": 0.001,
  "probabilities_max_abs_diff": 0.00011563301086425781,
  "probabilities_mean_abs_diff": 1.88e-05,
  "masked_elements": 6720,
  "total_elements": 7992,
  "passed": true,
  "valid_mask": "attention_mask broadcast to [B,L,12]",
  "variant_effect_consistency": "top delta position identical between CPU and NPU, delta direction preserved"
}

性能

{
  "device": "Ascend910_9362 npu:0",
  "dtype": "float32",
  "batch_size": 3,
  "sequence_lengths": [
    222,
    222,
    116
  ],
  "padded_length": 222,
  "warmup_iters": 3,
  "stable_iters": 10,
  "avg_ms_per_batch": 3791.66,
  "min_ms": 3787.93,
  "max_ms": 3793.17,
  "seq_per_s": 0.79,
  "bases_per_s": 148,
  "notes": "timing with torch.npu.synchronize() before and after each iteration; includes model forward only, excludes CPU tokenization",
  "peak_memory": "not measured, model ~33MB + activations negligible for L=222"
}

自验证截图

Agent workflow

NPU device call

Model result

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

已知限制

  • 仅对本次记录的模型 revision、输入契约、dtype 与 Ascend 环境完成验证。
  • 长序列上下文 10000 已验证短窗口 smoke,不建议直接外推到最大上下文而不做显存预判。

标签

#NPU #Ascend #Ascend910