#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.
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).torch.int64 tensors of shape [B, T] plus a
reconstructed torch.float32 tensor of shape [B, T, 6].wind_speed, wind_direction, power,
density, temperature, pressure.| Component | Version |
|---|---|
| Driver / firmware | Ascend 910, Ascend910_9362, 64 GiB HBM |
| CANN | 8.5.1 |
| Python | 3.11.14 |
| torch | 2.9.0 |
| torch_npu | 2.9.0.post1+gitee7ba04 |
| numpy | 1.26.x |
pip install -r requirements.txt
# torch and torch_npu wheels come from the Ascend / Torch vendor index.The default entry point is self-contained and exits non-zero on any failure:
python inference.pyThe 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:
cpu and once on npu:0, from
the same safetensors file (strict state-dict match).(1, 240, 6) (seed 2026).encode(x, half=True) + decode([s1, s2], half=True) on both
devices, prints shape / dtype / unique-token count / min / max.torch.npu.synchronize() around every call, prints first-run
compile time, avg / min / max / p50 / p95 latency and peak HBM.0 only when s1 and s2 are exactly equal
(integer ids) and z_max_abs < 1e-3; otherwise exits 1.[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=PASSSweeping (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:
| Shape | s1 exact | s2 exact | z max abs | z mean abs |
|---|---|---|---|---|
| (1, 32, 6) | yes | yes | 2.50e-06 | 5.86e-07 |
| (1, 64, 6) | yes | yes | 2.03e-06 | 4.38e-07 |
| (1, 128, 6) | yes | yes | 2.62e-06 | 4.37e-07 |
| (1, 240, 6) | yes | yes | 4.47e-06 | 4.54e-07 |
| (1, 384, 6) | yes | yes | 3.81e-06 | 4.33e-07 |
| (1, 512, 6) | yes | yes | 5.48e-06 | 4.49e-07 |
| (2, 240, 6) | yes | yes | 5.78e-06 | 4.60e-07 |
| (4, 128, 6) | yes | yes | 4.29e-06 | 4.75e-07 |
| (8, 128, 6) | yes | yes | 4.77e-06 | 4.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.
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().
| Shape | first-run (ms) | avg (ms) | min (ms) | max (ms) | p50 (ms) | p95 (ms) | windows/s | peak HBM (MiB) |
|---|---|---|---|---|---|---|---|---|
| (1, 64, 6) | 11.70 | 11.66 | 11.64 | 11.71 | 11.66 | 11.69 | 85.74 | 15.98 |
| (1, 128, 6) | 11.73 | 11.68 | 11.63 | 11.74 | 11.68 | 11.72 | 85.64 | 16.80 |
| (1, 240, 6) | 11.68 | 11.86 | 11.67 | 12.59 | 11.69 | 12.58 | 84.30 | 19.10 |
| (1, 512, 6) | 15.41 | 15.87 | 15.27 | 16.31 | 16.19 | 16.29 | 63.01 | 28.48 |
| (4, 128, 6) | 11.71 | 11.70 | 11.66 | 11.73 | 11.69 | 11.73 | 341.95 | 21.49 |
| (4, 240, 6) | 13.55 | 13.52 | 13.50 | 13.55 | 13.52 | 13.55 | 295.77 | 27.99 |
| (8, 128, 6) | 12.62 | 12.50 | 11.67 | 13.51 | 12.60 | 13.50 | 639.95 | 25.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.
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.
— discovery → env → load → NPU inference → consistency → benchmark → submission.
— npu-smi + torch.npu.is_available() + first parameter on npu:0 + first output on npu:0.
— default python inference.py exit 0, with schema, decoded reconstruction and timing.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.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.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.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.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.