atlasleong/compressionkit-ppg-2x-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

compressionkit-ppg-2x — Ascend NPU inference (torch_npu)

Complete RVQ signal-codec inference of the local authorized model Ambiq/compressionkit-ppg-2x-v1.0 on a physical Ascend910B4-1 (npu:0) using torch_npu 2.9.0. The original user alias Ambiq/compressionkit-ppg-2x is recorded and mapped to the official pinned -v1.0 repository revision af00d62fcdd8e8c12a2929bae9d22911ab518966.

The Keras v3 encoder/decoder graph is reimplemented as a faithful PyTorch forward pass. Every neural layer, the 4-stage residual-vector-quantization (RVQ) distance / nearest-codebook step, and every latent / reconstruction tensor executes on npu:0. CPU is used only for file reads, metadata and host metric reduction. There is no CPU fallback, no TensorFlow/TFLite execution, and the run fails non-zero on any missing weight or placement mismatch.

Model introduction

  • Encoder — 1-D convolutional front end (enc_s1_conv kernel (1,7), stride 2, SAME padding), batch-norm + ReLU, and a 1x1 to_vq projection to a 16-channel latent. Input frame (1,1,320,1) → latent (1,1,160,16).
  • Residual vector quantization — 4 codebook stages from codebook.npz, each 256×16; per stage the nearest codebook vector (Euclidean distance r² - 2·r·c + c²) is subtracted from the residual and accumulated.
  • Decoder — nearest ×2 up-sampling, (1,7) convolution + ReLU, separable convolution (dec_s1_aa, depthwise (1,5) + pointwise 1x1), ReLU, channel layer-norm, and a 1x1 output convolution back to (1,1,320,1).

Strict weight accounting loads all 8 encoder tensors, 9 decoder tensors and 4 codebooks (21/21 consumed, 25905 elements) and audits that none are left unused.

Artifacts

FileBytesSHA256
encoder.keras29581863a160cbd8a3d9af61e9a8012150a653cee1137dc56e678e2a6c4a3b1b41204
decoder.keras65070aa9ba2a2a4a36b3c015006379c612a035f88c1fa7044fca14b0d4f3319088ea0
codebook.npz6654278e186916480914b69e7cdb0b4e740af4e3d42902f89c4e157673426e8cc8e66
sample_stimulus.npz39174621663b2c944e2a55444e0e94540b63b2eceeb9b6405bf4b63c1d6f8598eab91

Test input: official sample_stimulus.npz (10 normalized PPG frames of length 320), taken from the local authorized model directory and used directly as-is.

License, attribution and academic use

The upstream model weights, codebooks, and associated deployment artifacts are published by Ambiq Micro, Inc. under the Ambiq Model Weights License (LICENSE-MODEL-WEIGHTS.md in the repository, referenced from the upstream Hugging Face card). That license restricts production deployment of the model artifacts to Ambiq silicon devices, while permitting research, evaluation, and benchmarking on non-Ambiq hardware for the sole purpose of assessing suitability for eventual Ambiq deployment; redistribution is permitted provided the license notice is retained and modified versions are clearly marked.

This repository is a user-authorized academic migration experiment performed on the local authorized model directory. It does not redistribute any of the upstream model weights (.keras, .h5, .npz codebook, TFLite, headers, etc.) — the runtime weights remain outside the public delivery and are supplied at inference time with --model-dir. The four PNG screenshots and logs here are produced from the real NPU run and are not a substitute for upstream permission: no permission beyond the text of the upstream license is claimed or implied, and any downstream use of the weights remains subject to the Ambiq Model Weights License and attribution to Ambiq Micro, Inc.

Environment dependencies

The matched torch 2.9.0+cpu + torch_npu 2.9.0 pair is pre-installed in the container on CANN 8.5.1 and must not be replaced by ordinary PyPI wheels. Only the non-torch packages listed in requirements.txt are installed:

  • numpy==1.26.4
  • h5py>=3.11,<4.0
export PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/
pip install -r requirements.txt

Inference steps (step-by-step)

cd /work/pipeline/jobs/other40/compressionkit-ppg-2x/compressionkit-ppg-2x-npu

export ASCEND_RT_VISIBLE_DEVICES=0
python3 inference.py \
  --model-dir /work/pipeline/models/other40/compressionkit-ppg-2x \
  --delivery-dir /work/pipeline/jobs/other40/compressionkit-ppg-2x/compressionkit-ppg-2x-npu \
  --hold-seconds 4.0

The program writes sanitized logs to logs/npu_inference.log, the npu-smi snapshot to logs/npu_smi.log, and the structured result to logs/npu_result.json. It holds for --hold-seconds after the forward so a host npu-smi snapshot can correlate the process; because this containerized torch_npu does not attribute the Python PID in the npu-smi process table, the correlation evidence is the on-device HBM delta on npu:0 (see npu_smi fields in npu_result.json).

Complete test case and real output

Run at 2026-08-23 06:38:43, PID 448404, exit code 0:

[2026-08-23 06:38:44] device_count=1
[2026-08-23 06:38:44] device_name=Ascend910B4-1
[2026-08-23 06:38:44] input.device=npu:0 input.shape=(10, 1, 320, 1) input.dtype=torch.float32
[2026-08-23 06:38:44] preprocessing: applied=False input mean=1.937151e-07 std=0.990661 -> official already-normalized stimulus (mean~0, std~1)
[2026-08-23 06:38:45] baseline npu-smi rc=0 npu:0 HBM used=3464MB total=65536MB
[2026-08-23 06:38:50] encoder.device=npu:0 latent.shape=(10, 1, 160, 16) ... elapsed=5.0188s
[2026-08-23 06:38:50] quantized.device=npu:0 quantized.shape=(10, 1, 160, 16) ... elapsed=0.0502s
[2026-08-23 06:38:51] output.device=npu:0 output.shape=(10, 1, 320, 1) ... elapsed=0.8845s
[2026-08-23 06:38:56] during-hold npu-smi rc=0 npu:0 HBM used=3535MB delta_from_baseline=71MB
[2026-08-23 06:38:56] OVERALL vs official reference: MAE=4.657089e-03 RMSE=6.335478e-03 PRD=0.6378%
[2026-08-23 06:38:56] CODEC vs input signal: MAE=6.942239e-03 RMSE=9.821287e-03 PRD=0.9914%
[2026-08-23 06:38:56]   frame0 reconstruction[0:8]=[-0.2346852719783783, -0.2929476499557495, ...]
[2026-08-23 06:38:56]   frame0 reference[0:8]     =[-0.23546510934829712, -0.28897935152053833, ...]
[2026-08-23 06:38:56] UNQUANTIZED decoder(encoder(input)) vs official reference: MAE=1.801272e-04 RMSE=2.432851e-04
[2026-08-23 06:38:56] encoder consumed=8/8 decoder consumed=9/9 codebook consumed=4/4
[2026-08-23 06:38:56] TOTAL loaded=21 consumed=21 elements=25905
[2026-08-23 06:38:56] elapsed: encoder=5.0188s rvq=0.0502s decoder=0.8845s total_wall=13.5528s
[2026-08-23 06:38:56] SUCCESS exit_code=0

The RVQ-inclusive reconstruction reproduces the official reference to MAE 4.66e-3 / RMSE 6.34e-3 (0.64% PRD); the reference itself equals the unquantized decoder(encoder(input)) (MAE 1.8e-4), confirming the neural graph is faithful and the residual difference is purely codec quantization.

Screenshots

Rendered from the genuine, sanitized run logs above:

AssetShows
assets/agent_workflow.pngEnd-to-end migration workflow (context → artifact reverse-engineering → CPU validation → NPU run → verification → delivery)
assets/modelagent_live_session.pngLive modelagent session: environment, device init, artifact SHA-256, weight loading
assets/npu_device_call.pngNPU device call: input placement, encoder / RVQ×4 / decoder on npu:0, npu-smi HBM delta
assets/model_result.pngFinal model result: per-frame MAE/RMSE/PRD, weight audit, SUCCESS exit_code=0