jsjs1258/qcw2333-YingLong_110m-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

qcw2333/YingLong_110m #NPU

YingLong is a probabilistic time-series foundation model from Alibaba (paper: arxiv 2506.11029) based on a bidirectional GPT backbone with patch embedding + Haar wavelet transform + U-Net skip connections, producing 99 quantiles per forecast step. This repo adapts qcw2333/YingLong_110m to run real zero-shot quantile forecasting on a single Ascend 910 NPU (npu:0).

  • Model: qcw2333/YingLong_110m (revision main, 110M params)
  • Task: zero-shot univariate quantile forecasting (context=512, horizon=96, 99 quantiles)
  • Backend: PyTorch + torch_npu, bfloat16
  • Device: Ascend910_9362 (NPU), dtype torch.bfloat16
  • Weights: model.safetensors (240 MB) loaded locally, never re-downloaded during inference

NPU adaptation notes

The official remote model.py requires CUDA-only libraries (flash_attn, xformers). To run on Ascend NPU the model was re-implemented with equivalent standard PyTorch ops while keeping the exact same module structure and state-dict keys:

Official CUDA opAscend replacement
xformers.ops.SwiGLUnative SwiGLU (w1/w2 gate-up, w3 down)
flash-attn FusedRMSNormnative RMSNorm
flash-attn rotary_embnative GPT-NeoX rotary embedding
flash-attn scaled_dot_product_attentiontorch.nn.functional.scaled_dot_product_attention

All weights are loaded with load_state_dict(..., strict=True). No CPU fallback: every model parameter and input/output tensor is on npu:0.

Data contract

  • Dataset: ETTh1 (public "Electricity Transformer Temperature, hourly"), research dataset.
  • File: ETTh1.csv, date column + 7 value channels [HUFL, HULL, MUFL, MULL, LUFL, LULL, OT], 17420 rows, hourly, time-sorted, no missing values.
  • Task: univariate forecasting of the OT (oil temperature) channel.
  • Context length L=512 (last 512 timesteps), prediction horizon H=96.
  • Input tensor [1, 512] (batch, context) in bfloat16; output [1, 96, 99] (batch, horizon, 99 quantile levels 0.01..0.99).
  • The forecast never crosses the data boundary; the last 512 samples are used as context.
  • The model internally normalizes with mean/std (RevIN-style) and inverts scaling on output.

Environment

  • Python 3.11.14
  • torch 2.9.0+cpu, torch-npu 2.9.0.post1+gitee7ba04, CANN 8.5.1
  • numpy 1.26.4, pandas 2.3.3, transformers 4.33.3, safetensors, einops
  • Device: single Ascend 910B (64 GB HBM), npu:0

Install

pip install -r requirements.txt

NPU inference

python inference.py

The script checks torch.npu.is_available(), downloads the weights once via huggingface_hub (respecting HF_ENDPOINT) into a local cache, loads them from local model.safetensors, moves the model and every tensor to npu:0, runs the 96-step quantile forecast, calls torch.npu.synchronize() for timing, and prints the results (exit 0 = success). It also accepts --context-length, --prediction-length, --data and --cache-dir options.

Real result (NPU)

Run on single npu:0 (Ascend910_9362), ETTh1 OT channel, last-512 context, 96-step quantile forecast:

quantiles shape: (1, 96, 99)  (batch, horizon, 99 quantiles)
quantile levels: 0.01..0.99
median forecast[:8]: [9.375  9.125  9.125  9.     9.1875 9.3125 9.25   9.4375]
sync elapsed: 0.2543 s
STATUS: NPU_OK

CPU-NPU consistency

Same weights, same input, same seed and eval mode. FP32 outputs saved to .npy and compared with compare_outputs.py:

{"task": "forecasting", "atol": 0.25, "rtol": 0.02, "max_abs_error": 0.125, "mean_abs_error": 0.0173, "passed": true}

Threshold rationale: model runs in bfloat16 on NPU (CPU baseline also bfloat16); the output scale is O(10). atol=0.25 is ~2.5% of the median forecast magnitude, consistent with bf16 rounding at this scale.

Performance (NPU)

First run (graph compilation): 269.1 ms; then 3 warmups + 10 timed runs:

{"avg_ms": 14.182, "min_ms": 13.894, "max_ms": 15.239, "p50_ms": 14.098, "p90_ms": 14.323, "p95_ms": 14.781, "throughput_series_per_s": 70.51, "peak_memory_allocated_MB": 487.79}

Timing uses torch.npu.synchronize() around every run. Preprocessing (CSV read + DataFrame slicing) is excluded from latency.

Evidence

The three images in assets/ are rendered by xterm.js from the real logs of this adaptation run (workflow, NPU device calls, and the default python inference.py output):

  • assets/agent_workflow.png — environment check, model download, CPU baseline, NPU inference, consistency and benchmark steps.
  • assets/npu_device_call.png — npu-smi, torch.npu availability and model/input/output tensor device on npu:0.
  • assets/model_result.png — full output of the default python inference.py command.

Limitations

  • Only the OT channel of ETTh1 is demonstrated; the model is univariate and can be applied to any real-valued series.
  • The official remote code is not executed on NPU; the re-implemented module structure is identical and state-dict keys match exactly, but this is a re-implementation rather than the original CUDA build.
  • --data must point to a CSV with an OT column (or the built-in public ETTh1 URL is used).