AtomGit / metadata tags:
ascend,npu,torch_npu,hardware: NPU,Ascend910B4-1,npu:2,CANN 8.5.1,signal-compression,ECG,RVQ,PyTorch,Ambiq,compressionkit-ecg-2x,compressionkit-ecg-2x-v1.0
| Field | Value |
|---|---|
| Original alias | Ambiq/compressionkit-ecg-2x |
| Official successor (pinned) | Ambiq/compressionkit-ecg-2x-v1.0 |
| Pinned upstream revision | 4d07900f24978ee3830ee2a6a4e2becaa0880645 |
| Source URL | https://huggingface.co/Ambiq/compressionkit-ecg-2x-v1.0 |
| Task | Signal compression — ECG residual-vector-quantization (RVQ) codec, 2x |
| Engine | torch_npu on physical device npu:2 (Ascend 910B4-1) |
| Local artifacts | /work/pipeline/models/other40/compressionkit-ecg-2x |
compressionkit-ecg-2x-v1.0 is the official successor of Ambiq's
compressionkit-ecg-2x neural ECG signal codec. It is a complete signal
codec:
encoder.keras) that maps a 512-sample ECG frame
(B, 1, 512, 1) (NHWC) to a 16-dimensional-per-step latent
(B, 1, 256, 16),codebook.npz,
four (256, 16) codebooks) that quantise the latent into per-stage
codebook indices (B, 4, 256),decoder.keras) that reconstructs the frame back to
(B, 1, 512, 1).This delivery is a faithful PyTorch reimplementation of the Keras float32
reference codec, adapted to run entirely on the Ascend NPU via torch_npu.
Every neural layer, every distance / nearest-codebook computation, every latent
and reconstruction tensor, and every output executes on physical device
npu:2. CPU is used only for reading artifact files, metadata, and layout
bookkeeping (Keras NHWC ↔ PyTorch NCHW). There is no TensorFlow/TFLite
CPU execution, no CPU fallback, no mock model, no partial layer, no
reinitialised weight, and no copied reference output.
The official sample_stimulus.npz input is already per-frame layer-norm
normalized (see codec_spec.json preprocessing_contract.kind = per_frame_layer_norm), so it is fed to the codec directly and never
normalized a second time (reported as preprocessing.normalization_applied = false in logs/npu_result.json).
| Keras (NHWC) weight | PyTorch (NCHW) layout |
|---|---|
Conv2D kernel (kh, kw, in, out) | (out, in, kh, kw) |
DepthwiseConv2D (kh, kw, in, depth_mult) | (in*depth_mult, 1, kh, kw) |
BatchNorm [gamma, beta, moving_mean, moving_var] | eval-mode BN applied manually |
LayerNorm [gamma, beta] (over last axis) | biased variance, applied on NHWC |
UpSampling2D nearest (1, 2) | repeat_interleave(2, dim=width) |
| SAME padding | exact TF formula with asymmetric padding |
Every tensor stored in encoder.keras / decoder.keras and every array in
codebook.npz is registered in a WeightRegistry and marked "consumed" only at
the exact point it is used in the forward graph. At the end the script asserts
consumed == loaded (no missing, no unused, no double-use); otherwise it exits
non-zero. The final run consumed 21 / 21 tensors:
{
"total_tensors_loaded": 21,
"total_tensors_consumed": 21,
"per_source": {
"codebook": { "tensors": 4, "elements": 16384 },
"encoder": { "tensors": 8, "elements": 1360 },
"decoder": { "tensors": 9, "elements": 8161 }
}
}This project is a user-authorized academic migration experiment that adapts
the Ambiq compressionkit-ecg-2x-v1.0 model to a non-Ambiq (Ascend NPU)
platform for research / evaluation / benchmarking purposes.
The upstream Ambiq Model Weights License (see LICENSE-MODEL-WEIGHTS.md
in the source repository) states, in particular:
The Model Artifacts may only be deployed, executed, or otherwise used in production on hardware manufactured by or for Ambiq Micro, Inc. Research, evaluation, and benchmarking on non-Ambiq hardware is permitted for the sole purpose of assessing suitability for eventual Ambiq deployment.
Redistribution is permitted provided this license notice is retained and modified versions are clearly marked as such. Any public use, publication, or demonstration of results must include attribution to Ambiq Micro, Inc. and reference the originating HuggingFace repository.
This delivery does not imply any upstream (Ambiq) permission beyond the text
of that license. The runtime model weights are not shipped in this public
delivery; they remain outside and are supplied at run time via --model-dir.
The code here is an independent PyTorch reimplementation executed for
evaluation only, consistent with the license's research / evaluation clause.
Matched CANN / PyTorch / torch_npu runtime (preserve; do not install torch / torch_npu from ordinary PyPI):
| Package | Version |
|---|---|
| CANN (Ascend toolkit) | 8.5.1 |
| Ascend driver | 25.5.1 |
| torch | 2.9.0+cpu (torch_npu patched runtime) |
| torch_npu | 2.9.0 |
| numpy | 1.26.4 |
| h5py | 3.16.0 |
requirements.txt documents the non-torch packages (numpy==1.26.4,
h5py==3.16.0); install them from the configured Aliyun mirror only. See
requirements.txt for the full install hint.
# 0) Environment (Ascend CANN)
source /usr/local/Ascend/ascend-toolkit/set_env.sh
# 1) Syntax check
cd /work/pipeline/jobs/other40/compressionkit-ecg-2x/compressionkit-ecg-2x-npu
python3 -m py_compile inference.py && echo PY_COMPILE_OK
# 2) Fresh real NPU inference on npu:2 (holds 8 s after the forward so host
# `npu-smi info` can correlate the PID; final raw log -> logs/npu_inference.log)
python3 inference.py --model-dir /work/pipeline/models/other40/compressionkit-ecg-2x \
--device npu:2 --hold-after-forward 8.0
# 3) Evidence
cat logs/npu_result.jsonCaptured verbatim from logs/npu_inference.log (genuine sanitised run,
PID 1300556):
==============================================================================
compressionkit-ecg-2x-v1.0 -- Ascend NPU real inference
==============================================================================
pinned_revision : 4d07900f24978ee3830ee2a6a4e2becaa0880645
source_url : https://huggingface.co/Ambiq/compressionkit-ecg-2x-v1.0
original_alias : Ambiq/compressionkit-ecg-2x
successor_repo : Ambiq/compressionkit-ecg-2x-v1.0
task : signal-compression (ECG RVQ 2x codec)
pid : 1300556
engine : torch_npu
device : npu:2
npu_available : True
device_name : Ascend910B4-1
CANN : cann-8.5.1;driver-25.5.1
torch : 2.9.0+cpu
torch_npu : 2.9.0
model_dir : /work/pipeline/models/other40/compressionkit-ecg-2x
preprocessing : official stimulus used directly (additional normalization applied = False)
------------------------------------------------------------------------------
Running full codec: encoder -> 4x RVQ -> decoder on npu:2 ...
forward_seconds : 6.133106
------------------------------------------------------------------------------
OUTPUT / METRICS (all computed on npu:2)
input shape : (10, 1, 512, 1) device=npu:2
latent shape : (10, 1, 256, 16) device=npu:2
rvq_in shape : (10, 1, 256, 16) device=npu:2
indices shape : (10, 4, 256) device=npu:2 dtype=torch.int64
recon shape : (10, 1, 512, 1) device=npu:2
ref shape : (10, 1, 512, 1) device=npu:2
MAE(recon,ref) : 0.004429
RMSE(recon,ref) : 0.009139
MAE(recon,input) : 0.015483
RMSE(recon,input) : 0.021675
PRD(recon,input) % : 2.2696
deterministic sample values (frame 0, first 8):
recon : -0.325524 -0.292956 -0.307021 -0.237372 -0.320424 -0.476936 -0.463812 -0.443465
ref : -0.329405 -0.291074 -0.304383 -0.236205 -0.318066 -0.473904 -0.461163 -0.442332
------------------------------------------------------------------------------
STRICT WEIGHT-CONSUMPTION PROOF: OK (21/21 tensors)
------------------------------------------------------------------------------
Holding 8.0s after forward with PID 1300556 alive on npu:2 so host `npu-smi info` can correlate the process ...
npu-smi during hold (pid=1300556):
| 2 0 | 1300556 | python3 | 162 |
(PID 1300556 on NPU 2, 162 MB process memory)
------------------------------------------------------------------------------
Wrote result JSON : .../logs/npu_result.json
exit_code : 0
SUCCESSThe reconstruction matches the official reference (
MAE = 0.00443,RMSE = 0.00914, frame-0 sample values listed above) while the codec's own fidelity isRMSE(recon, input) = 0.02168andPRD = 2.27%, consistent with the model card quality scorecard. The small residual vs. the reference is the expected TFLite-float32 vs. pure-Keras float32 difference in the reference generation path.
compressionkit-ecg-2x-npu/
├── inference.py # faithful PyTorch/torch_npu codec (runs on npu:2)
├── requirements.txt # matched torch/torch_npu + numpy/h5py pins
├── README.md # this document (identical to readme.md)
├── readme.md # AtomGit-oriented mirror (byte-identical)
├── SHA256SUMS # sha256 of every delivered file
├── logs/
│ ├── npu_inference.log # final sanitized raw run log (real output, PID 1300556)
│ └── npu_result.json # machine-readable result / evidence
└── assets/
├── agent_workflow.png # rendered from the real ModelAgent runner log
├── modelagent_live_session.png
├── npu_device_call.png # npu-smi device/PID evidence
└── model_result.png # real result/metricsNo credentials are stored in any artifact.