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

multimolecule/spotrna on Ascend NPU

模型与任务

  • 模型:multimolecule/spotrna
  • Revision:ea6e067d459da10f3e9154c90dd822ece47cf522
  • 适配路线:rna-secondary-structure
  • 设备:npu:0

环境依赖

{
  "torch": "2.9.0+cpu",
  "torch_npu": "2.9.0.post1+gitee7ba04",
  "transformers": "5.9.0",
  "multimolecule": "0.2.1",
  "device_name": "Ascend910_9362",
  "npu_available": true,
  "device_count": 2
}

安装:pip install -r requirements.txt

NPU 推理

默认执行:python inference.py

真实输入

{
  "primary_sequence": {
    "name": "tRNA_yeast_Phe",
    "length": 74,
    "sha256": "f5014cfb7b1ff718df070139c8fe937414f7a8de7396b7e2a0faed0f405b3d6f",
    "alphabet": "ACGU",
    "sequence_preview": "GGGCUAUUAGCUCAGUUGGUUAGAGCGCACCCCUGAUAAGGGUGAG"
  },
  "secondary_sequences": [
    {
      "name": "microRNA_21",
      "length": 22,
      "sha256": "9c1b1cd23c45d39dd0b1fb28d72c49c0edcc57a16cb61c96119f84676c4b5b1c"
    },
    {
      "name": "SARS_fragment_100",
      "length": 130,
      "sha256": "58e34fbf500673f967d7610c67cad1cecd1a788383d060b1525929c5959f3537"
    }
  ],
  "tokenizer": {
    "vocab": [
      "A",
      "C",
      "G",
      "U",
      "N"
    ],
    "replace_T_with_U": true,
    "vocab_size": 5
  },
  "input_ids_shape": [
    1,
    74
  ],
  "output_is_LxL": true
}

真实推理结果

{
  "logits_shape": [
    1,
    74,
    74
  ],
  "contact_map_shape": [
    1,
    74,
    74
  ],
  "dtype": "torch.float32",
  "device": "npu:0",
  "threshold": 0.335,
  "stats": {
    "contact_map_mean": 0.0051430147,
    "contact_map_max": 0.9991629,
    "contact_map_min": 0.0,
    "binary_pairs_count": 26,
    "example_pairs_upper": [
      [
        0,
        72
      ],
      [
        1,
        71
      ],
      [
        2,
        70
      ],
      [
        3,
        69
      ],
      [
        4,
        68
      ],
      [
        5,
        67
      ],
      [
        6,
        66
      ],
      [
        7,
        21
      ],
      [
        9,
        25
      ],
      [
        10,
        24
      ]
    ]
  }
}

CPU-NPU 一致性

{
  "method": "cpu_vs_npu_same_weights_seq",
  "shape": [
    1,
    74,
    74
  ],
  "elements": 5476,
  "max_abs_diff": 6.619095802307129e-05,
  "mean_abs_diff": 1.1858038817535999e-07,
  "atol": 0.001,
  "rtol": 0.001,
  "passed": true,
  "secondary_checks": [
    {
      "name": "microRNA_21_len22",
      "max_abs_diff": 0.0001192689
    },
    {
      "name": "SARS_fragment_130",
      "max_abs_diff": 0.0001694858
    }
  ]
}

性能

{
  "input_length": 74,
  "output_shape": [
    1,
    74,
    74
  ],
  "dtype": "torch.float32",
  "warmup_iters": 3,
  "stable_iters": 10,
  "avg_ms": 242.95,
  "min_ms": 240.23,
  "max_ms": 243.37,
  "sequences_per_sec": 4.12,
  "bases_per_sec": 304.6,
  "device": "npu:0",
  "peak_memory_mb": 206.1,
  "compile_note": "hybrid CPU fallback for BiLSTM; otherwise fully NPU with torch.npu.synchronize"
}

自验证截图

Agent workflow

NPU device call

Model result

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

已知限制

  • 仅对本次记录的模型 revision、输入契约、dtype 与 Ascend 环境完成验证。
  • SPOT-RNA 的 2D-BiLSTM 模块在当前 CANN 上通过固定 hybrid CPU 回退处理,其余卷积模块在 npu:0 真实运行;已显式记录且不属于静默回退。

标签

#NPU #Ascend #Ascend910