gcw_6a3w2yXz/xECG_base_model_v1_npu_adapted
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

xECG_base_model_v1 NPU Adaptation

Model Overview

This repository contains the NPU-adapted version of the xECG_base_model_v1 model, originally from riccardolunelli/xECG_base_model_v1.

The xECG model is an ECG (Electrocardiogram) foundation model based on xLSTM architecture, designed for ECG signal representation and analysis.

NPU Device Call

Model Specifications

  • Model Type: ECG Representation (ecg-representation)
  • Architecture: xLSTM (Extended Long Short-Term Memory)
  • Input: 12-lead ECG signals
  • Sampling Rate: 100 Hz
  • Window Length: 5000 samples (50 seconds)
  • Output: Pooled embedding (1024-dimensional) and patch-level features
  • License: MIT

NPU Adaptation Details

Signal Contract

ParameterValue
Sampling Rate100 Hz
Number of Leads12
Window Length5000 samples
Lead Order['i', 'ii', 'iii', 'avr', 'avl', 'avf', 'v1', 'v2', 'v3', 'v4', 'v5', 'v6']
Embedding Size1024

Performance Results

Agent Workflow

MetricValue
DeviceAscend 910B (npu:0)
Inference Time1.1067 ± 0.0014 seconds
Records/s0.9036
Peak Memory0.50 GB
CPU-NPU Cosine Similarity0.9977

Compatibility Notes

The xECG model uses xLSTM with sLSTM blocks, which requires special handling for NPU adaptation:

  • The original model uses CUDA backend for sLSTM
  • For NPU compatibility, we use the vanilla backend implementation
  • Weight permutation is applied to handle shape differences between backends

Usage

Installation

pip install torch torch_npu xlstm safetensors huggingface_hub

Running Inference

python inference.py

The script will:

  1. Load the model weights
  2. Move the model to NPU device
  3. Create a test ECG signal
  4. Execute inference
  5. Print results and save to result.json

Expected Output

Model Result

============================================================
xECG_base_model_v1 NPU 推理
============================================================

[1] 设置 NPU 设备...
使用设备: npu:0
NPU 设备数量: 2
当前 NPU 设备: 0

[2] 创建模型配置...
creating xlstm with slstm at:  [0, 1, 4, 5, 8]

[3] 加载权重...
权重加载结果: <All keys matched successfully>

[4] 将模型移动到 NPU...
模型设备: npu:0

[5] 创建测试输入...
输入 shape: torch.Size([1, 5000, 12])
输入 dtype: torch.float32
输入 device: npu:0

[6] 预热推理...

[7] 执行 NPU 推理...
推理时间: 1.1076 秒
嵌入 shape: torch.Size([1, 1024])
输出 shape: torch.Size([1, 200, 1024])

[8] 保存结果...
结果已保存到 result.json

============================================================
推理完成: PASS
============================================================

Model Weights

The model weights are not included in this repository due to size constraints. Please download them from the original HuggingFace repository:

huggingface-cli download riccardolunelli/xECG_base_model_v1 --local-dir model_weights

References

  • Original Model: https://huggingface.co/riccardolunelli/xECG_base_model_v1
  • Paper: BenchECG and xECG: a benchmark and baseline for ECG foundation models
  • Code: https://github.com/dlaskalab/bench-xecg/

License

MIT License