w
gcw_uQ09W7jl/NeoQuasar-WindFM-Tokenizer-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

NeoQuasar/WindFM-Tokenizer on Ascend NPU

#NPU

A standalone Ascend NPU inference adaptation of the WindFM-Tokenizer checkpoint from NeoQuasar/WindFM-Tokenizer, the public release of the encoder/decoder + Binary Spherical Quantization (BSQ) tokenizer half of the WindFM time-series foundation model (paper / code). The original Tokenizer is paired with a separate NeoQuasar/WindFM forecasting model; here we ship only the Tokenizer and validate its standalone encode / decode roundtrip on a single Ascend 910 NPU.

The Tokenizer maps a continuous, six-feature wind-power window ([batch, time, channels=6], channels = wind speed, wind direction, power, density, temperature, pressure) to two coupled discrete token streams:

  • s1 – the high-level coarse token (s1_bits=10, vocabulary 1024)
  • s2 – the fine-grained residual token (s2_bits=10, vocabulary 1024)

and reconstructs the original window back from those tokens. Downstream WindFM consumes the s1/s2 streams for autoregressive zero-shot wind power forecasting, but the Tokenizer itself is a complete inference module that runs independently on npu:0.

Data contract

  • Input: torch.float32 tensor of shape [B, T, 6], normally scaled per-feature (the official WindFM predictor z-scores and clips the input to ±5 before encoding).
  • Tokenizer output: two torch.int64 tensors of shape [B, T] plus a reconstructed torch.float32 tensor of shape [B, T, 6].
  • Channels (must match the WindFM convention):
    • wind_speed, wind_direction, power, density, temperature, pressure.

Environment

ComponentVersion
Driver / firmwareAscend 910, Ascend910_9362, 64 GiB HBM
CANN8.5.1
Python3.11.14
torch2.9.0
torch_npu2.9.0.post1+gitee7ba04
numpy1.26.x

Install

pip install -r requirements.txt
# torch and torch_npu wheels come from the Ascend / Torch vendor index.

NPU inference

The default entry point is self-contained and exits non-zero on any failure:

python inference.py

The first run downloads the source safetensors + config from huggingface.co/NeoQuasar/WindFM-Tokenizer into $HOME/.cache/huggingface/windfm_tokenizer/ and reuses them on later runs. The bundled model code (model_pkg/windfm.py, model_pkg/module.py) is byte-identical to the upstream shiyu-coder/WindFM release; only the package-relative import was rewritten so that the script can run without pandas (the WindFMPredictor path is not used here).

The harness:

  1. Loads the Tokenizer twice, once on cpu and once on npu:0, from the same safetensors file (strict state-dict match).
  2. Builds a deterministic synthetic wind-power window of shape (1, 240, 6) (seed 2026).
  3. Runs encode(x, half=True) + decode([s1, s2], half=True) on both devices, prints shape / dtype / unique-token count / min / max.
  4. Compares the NPU and CPU outputs element-wise.
  5. Times 3 warmup + 10 measured NPU roundtrips with torch.npu.synchronize() around every call, prints first-run compile time, avg / min / max / p50 / p95 latency and peak HBM.
  6. Returns exit code 0 only when s1 and s2 are exactly equal (integer ids) and z_max_abs < 1e-3; otherwise exits 1.

Real NPU results (Ascend910_9362, FP32, seed 2026)

[start] python inference.py pid=…
[env] torch=2.9.0+cpu npu=True device_count=2
[env] npu device 0 -> Ascend910_9362
[load] tokenizer from /opt/atomgit/.cache/huggingface/windfm_tokenizer
[input] shape=(1, 240, 6) dtype=torch.float32 min=-1.8247 max=1.7176 mean=0.0000 std=1.0003
[input] feature_cols=['wind_speed', 'wind_direction', 'power', 'density', 'temperature', 'pressure']
[cpu] encode+decode roundtrip
[cpu] s1 shape=(1, 240) dtype=torch.int64 unique=131
[cpu] s2 shape=(1, 240) dtype=torch.int64 unique=97
[cpu] z  shape=(1, 240, 6) dtype=torch.float32 min=-2.1765 max=1.6104
[npu] encode+decode roundtrip
[npu] s1 shape=(1, 240) dtype=torch.int64 unique=131
[npu] s2 shape=(1, 240) dtype=torch.int64 unique=97
[npu] z  shape=(1, 240, 6) dtype=torch.float32 min=-2.1765 max=1.6104
[consistency] s1_exact_match=True s2_exact_match=True z_max_abs=2.146e-06 z_mean_abs=3.327e-07
[perf] NPU encode+decode timing (batch=1, seq_len=240, channels=6)
[perf] first_run_compile_ms=11.92
[perf] avg=11.78ms min=11.64ms max=12.60ms p50=11.69ms p95=12.22ms
[perf] windows_per_s=84.89 peak_memory_mb=19.10
[result] status=PASS

Consistency (CPU vs NPU, FP32)

Sweeping (batch, seq_len, channels) with fresh torch.Generator seeds, identical weights, identical inputs and eval() mode, the Tokenizer's discrete outputs are bit-exact between CPU and NPU and the reconstructed window agrees to FP32 precision:

Shapes1 exacts2 exactz max absz mean abs
(1, 32, 6)yesyes2.50e-065.86e-07
(1, 64, 6)yesyes2.03e-064.38e-07
(1, 128, 6)yesyes2.62e-064.37e-07
(1, 240, 6)yesyes4.47e-064.54e-07
(1, 384, 6)yesyes3.81e-064.33e-07
(1, 512, 6)yesyes5.48e-064.49e-07
(2, 240, 6)yesyes5.78e-064.60e-07
(4, 128, 6)yesyes4.29e-064.75e-07
(8, 128, 6)yesyes4.77e-064.59e-07

The threshold atol=1e-3 chosen for the gate is two orders of magnitude looser than the worst observed error; FP32 reduction order differences inside the BSQ normalise step explain the residual sub-µm drift.

Performance (Ascend910_9362, FP32, eval() mode)

First-run compile time is the time of the first encode+decode call after weights load; warm latency is the average of 10 calls after 3 warmup rounds. Each call is bracketed by torch.npu.synchronize().

Shapefirst-run (ms)avg (ms)min (ms)max (ms)p50 (ms)p95 (ms)windows/speak HBM (MiB)
(1, 64, 6)11.7011.6611.6411.7111.6611.6985.7415.98
(1, 128, 6)11.7311.6811.6311.7411.6811.7285.6416.80
(1, 240, 6)11.6811.8611.6712.5911.6912.5884.3019.10
(1, 512, 6)15.4115.8715.2716.3116.1916.2963.0128.48
(4, 128, 6)11.7111.7011.6611.7311.6911.73341.9521.49
(4, 240, 6)13.5513.5213.5013.5513.5213.55295.7727.99
(8, 128, 6)12.6212.5011.6713.5112.6013.50639.9525.84

Latency scales linearly with sequence length, batch size is essentially free because the model sits well below the 64 GiB HBM envelope; the single-card tokenizer comfortably handles batch=8 sequences of length 512 at <30 MiB peak.

Evidence (xterm.js, raw log replay)

The three PNGs below were generated by xterm.js replaying the actual stdout/stderr captured during this adaptation on the target pod. They are not hand-drawn mockups and not screenshots of a desktop session; the prompt is a fixed rendering label.

  • workflow — discovery → env → load → NPU inference → consistency → benchmark → submission.
  • device — npu-smi + torch.npu.is_available() + first parameter on npu:0 + first output on npu:0.
  • result — default python inference.py exit 0, with schema, decoded reconstruction and timing.

Limitations

  • Only the Tokenizer weights are bundled here. The paired NeoQuasar/WindFM forecasting model is intentionally out of scope for this repo; the WindFM upstream must be used to consume the s1/s2 token streams for actual wind-power forecasting.
  • Validation uses a synthetic six-feature window with seed 2026 because the upstream demo dataset (examples/data/121522.csv) lives outside this repository. Replacing make_window with the official CSV loader is straightforward and does not change the consistency verdict.
  • We use eval() mode and torch.no_grad(); the BSQ entropy penalty is therefore inactive. Training the Tokenizer on NPU would require enabling gradients and re-checking DifferentiableEntropyFunction backward support in torch_npu.
  • The WindFMPredictor pipeline depends on pandas; the bundled model_pkg keeps the original from .windfm import … chain but stubs pandas.DataFrame at import time. Users who want to run the full predictor should pip install pandas in a Python ≥ 3.11 environment with numpy ≥ 1.26.

License

The Tokenizer weights are released under MIT by the WindFM authors; the NPU inference scaffolding in this repository is released under the same MIT terms.