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

multimolecule/basset on Ascend NPU

模型与任务

  • 模型:multimolecule/basset
  • Revision:c5c82a89eec1ef04ba31017c4108f62da89086ac
  • 适配路线:regulatory-sequence
  • 设备:npu:0

环境依赖

{
  "torch": "2.9.0+cpu",
  "torch_npu": "2.9.0.post1+gitee7ba04",
  "transformers": "5.9.0",
  "multimolecule": "0.2.1",
  "python": "3.11.14",
  "npu_name": "Ascend910_9362",
  "device": "npu:0",
  "dtype": "float32",
  "hf_endpoint": "https://hf-mirror.com"
}

安装:pip install -r requirements.txt

NPU 推理

默认执行:python inference.py

真实输入

{
  "route": "regulatory-sequence",
  "sequence_length": 600,
  "alphabet": "A/C/G/T/N",
  "tokenizer": "DnaTokenizer",
  "pad_token_id": 4,
  "sequences": [
    {
      "name": "ACGT_repeat",
      "raw_length": 600,
      "padded_length": 600,
      "sha256": "e4a387752a4865282071c8f2f26b4d990db42b00a357a5080766f61ba6f02dbd",
      "preview": "ACGTACGTACGTACGTACGTACGTACGTACGTACGTACGT"
    },
    {
      "name": "p53_ENCODE_example",
      "raw_length": 184,
      "padded_length": 600,
      "sha256": "7a04b9f182884881e3dc7870767e85cf13f1ef93901512f927ca48ef8271903d",
      "preview": "ACTCCCCTGCCCTCAACAAGATGTTTTGCCAACTGGCCAA",
      "attention_mask_sum": 184
    }
  ],
  "batch_size": 1,
  "input_ids_shape": [
    1,
    600
  ],
  "attention_mask_shape": [
    1,
    600
  ]
}

真实推理结果

{
  "model": "BassetForSequencePrediction",
  "num_labels": 164,
  "logits_shape": [
    1,
    164
  ],
  "output_dtype": "float32",
  "logits_sample_cpu_first5": [
    -33.99782180786133,
    -52.76028060913086,
    -30.10908317565918,
    -38.293758392333984,
    -17.012758255004883
  ],
  "logits_sample_npu_first5": [
    -33.997249603271484,
    -52.75730895996094,
    -30.10797119140625,
    -38.292991638183594,
    -17.01207160949707
  ],
  "top5_cpu_indices": [
    108,
    148,
    147,
    26,
    131
  ],
  "top5_npu_indices": [
    108,
    148,
    147,
    26,
    131
  ],
  "probabilities_via_sigmoid": true
}

CPU-NPU 一致性

{
  "p53_max_abs_diff": 0.00344085693359375,
  "p53_mean_abs_diff": 0.001299703993448397,
  "acgt_max_abs_diff": 0.053066253662109375,
  "acgt_mean_abs_diff": 0.030979,
  "atol": 0.1,
  "rtol": 1e-05,
  "passed": true,
  "comparison": "logits 164-dim multilabel, same weights/inputs/seed, CPU vs npu:0",
  "device_mismatch": false
}

性能

{
  "device": "npu:0",
  "dtype": "float32",
  "sequence_length": 600,
  "batch_size": 1,
  "first_compile_ms": 186.04,
  "stable_avg_ms": 2.58,
  "stable_min_ms": 1.96,
  "stable_max_ms": 2.97,
  "windows_per_second": 387.6,
  "bases_per_second": 232558.1,
  "warmup_iters": 3,
  "stable_iters": 10,
  "synchronize": "torch.npu.synchronize() before/after timing",
  "peak_memory_mb": "not measured separately, ~3GB HBM used"
}

自验证截图

Agent workflow

NPU device call

Model result

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

已知限制

  • 仅对本次记录的模型 revision、输入契约、dtype 与 Ascend 环境完成验证。
  • 固定600 bp输入, 输出164维 logits, 使用DnaTokenizer N-pad到600。

标签

#NPU #Ascend #Ascend910