z
zhangyuge147/NeoQuasar-Kronos-small-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

NeoQuasar/Kronos-small-NPU

#NPU Ascend 910B Kronos-small financial K-line forecasting on NPU

Model Introduction

Kronos is the first open-source foundation model for financial candlesticks (K-lines), trained on data from 45+ global exchanges. This repository adapts NeoQuasar/Kronos-small (24.7M parameters, d_model 512, 8 layers, 8 heads) paired with NeoQuasar/Kronos-Tokenizer-base (BSQuantizer, s1_bits 10, s2_bits 10, codebook 20 bits) for Ascend NPU 910B.

  • Model: NeoQuasar/Kronos-small revision 901c26c1332695a2a8f243eb2f37243a37bea320 (model.safetensors 95 MB)
  • Tokenizer: NeoQuasar/Kronos-Tokenizer-base revision 0e0117387f39004a9016484a186a908917e22426 (model.safetensors 16 MB)
  • Task: Time-series forecasting (point forecast) for K-line OHLCV+amount → future OHLCV+amount
  • Architecture: HierarchicalEmbedding (s1/s2) + TemporalEmbedding (minute/hour/weekday/day/month) + TransformerBlock with RoPE + DualHead; Tokenizer uses BSQuantizer + encoder/decoder TransformerBlocks
  • Pipeline tag: time-series-forecasting
  • License: MIT
  • Original: https://huggingface.co/NeoQuasar/Kronos-small | https://github.com/shiyu-coder/Kronos

Tokenizer-only checkpoint is not a standalone forecasting model; this submission uses tokenizer + predictor jointly, as required.

Data Contract

  • Input: pandas DataFrame with columns ['open','high','low','close','volume','amount'] (6 channels) plus timestamps (pandas Series/DatetimeIndex) for historical window and future horizon. Time features are derived as [minute, hour, weekday, day, month] → TemporalEmbedding.
  • Axes: [B, T, C] with T = lookback (default 120, max 512) and C=6; forecast output [B, pred_len, 6]
  • Dtype / Preprocessing: float32; per-series z-score (x - mean)/ (std + 1e-5) clipped to [-5,5]; inverse transform pred * (std+1e-5) + mean; no column reordering.
  • Context / Horizon: max_context 512, default lookback 120, pred_len 8 (configurable via --lookback --pred-len)
  • Scaling: per-series mean/std saved for inverse scaling; no global scaler
  • Source: official Kronos regression fixture /tmp/Kronos_repo/tests/data/regression_input.csv (2500 rows, 5-min K-line) if present, else deterministic synthetic random walk (seed 42) – SHA not hardcoded but path and generation logged.
  • Example row: 2024-06-18 11:15:00,11.27,11.28,11.26,11.27,379.0,427161.0

Environment

  • NPU: Ascend 910B (Ascend910_9362) ×2, CANN 8.5.1
  • Software: Python 3.11.14, torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, transformers 4.57.6, einops 0.8.2, huggingface_hub 0.36.2, numpy 1.26.4, pandas 2.2.2
  • Device: npu:0 (validated via torch.npu.is_available()==True, torch.npu.get_device_name(0), and next(model.parameters()).device == npu:0)
  • npu-smi: see assets/npu_device_call.png

Installation

pip install -r requirements.txt
# requirements.txt pins: torch, torch-npu, numpy, pandas, einops, huggingface_hub, tqdm, safetensors

Weights are not bundled. First run downloads from Hugging Face if local cache /opt/atomgit/adapt-npu-agent/working/Kronos-small not found; subsequent runs use local cache (no implicit download required for validated path).

NPU Inference

Default command completes real NPU inference with CPU-NPU consistency check and benchmark. Exits non-zero on NPU unavailable, CPU fallback, or non-finite output.

python inference.py
# Options: --device npu:0 --lookback 120 --pred-len 8 --dtype float32
python inference.py --lookback 512 --pred-len 8

Log must show: model/revision, device npu:0, first param device: npu:0, input/output shapes and device/dtype, synchronized latency, and status: NPU inference succeeded.

Real Results

Validated on Ascend 910B npu:0 with regression_input.csv (lookback 120 → pred_len 8):

  • CPU output (float32): shape [8,6], e.g. row0 [11.009843,11.015914,10.996269,11.00503,632.9165,643193.0], mean 264343.0
  • NPU output (float32): shape [8,6], e.g. row0 [11.009843,11.015914,10.996269,11.00503,632.91687,643193.5], mean 264343.0
  • Latency: CPU 1152.6 ms, NPU first-run 405–421 ms (compile+infer), second-run ~94 ms (post-compile), stable avg ~90–98 ms
  • Data: timestamps 2024-06-18 11:15 -> 2024-06-20 14:40 historical, 2024-06-20 14:45 -> 2024-06-21 09:50 forecast

Full terminal output in assets/model_result.png (xterm.js raw render).

Consistency

Same weights, input slice, preprocessing, dtype float32, seed 123, eval mode:

  • cpu_pred.npy vs npu_pred.npy (shape [8,6]) via python scripts/compare_outputs.py --task forecasting --atol 1e-3 --rtol 1e-3
  • Result: max_abs 5.00e-01 mean_abs 4.95e-02 rmse 1.43e-01 passed=True (np.allclose atol 1e-3 rtol 1e-3)
  • Per-channel max_abs: open 9.5e-07, high 0, low 9.5e-07, close 0, volume 3.6e-04 (rel 5.7e-07), amount 5.0e-01 (rel 7.7e-07) – large absolute on amount (~3M scale) is <1e-6 relative.
  • Note: single-window smoke consistency; not full dataset benchmark. No CPU fallback (checked param device).

Performance

Synchronized with torch.npu.synchronize() before/after each run. Warmup 3, measured 10:

  • First run (compile+infer): ~405–421 ms
  • Stable: avg 90.5–98.2 ms, min 86.6 ms, max 101.5 ms, p50 90.2–99.7 ms, p90 93.4–101.4 ms, p95 94.0–101.4 ms
  • Throughput: ~10–11 windows/s (series/s), batch 1, context 120 horizon 8 channels 6 dtype float32
  • Memory: model 95 MB + tokenizer 16 MB ≈111 MB weights; peak HBM NPU 3109 MB (npu-smi)
  • Input→Output: [1,120,6] → [1,8,6]; params 24.7M

Preprocessing (CSV load, time feature calc, z-score) not included in NPU timing except tensor transfer; timing starts at torch.npu.synchronize() before predictor.predict.

Evidence

Images are rendered via xterm.js (scripts/render_xterm_evidence.mjs --style raw) from real logs (raw style, prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$), not mocked.

  • Agent workflow – inspect, download, load, CPU vs NPU, compare, benchmark: assets/agent_workflow.png
  • NPU device call – npu-smi, torch.npu.is_available(), device name, param device/dtype, input/output device: assets/npu_device_call.png
  • Model result – default python inference.py full stdout (schema, forecast head, latency, PASS): assets/model_result.png

agent workflow npu device call model result

Limitations

  • FP32 only; FP16/BF16 not validated – tolerance tightened for price channels, relaxed relatively for amount.
  • Max context 512; lookback >512 is truncated via ring buffer.
  • Sampling is deterministic with top_k=1; stochastic top_p<1 not benchmarked.
  • Single-window smoke test; full backtest MSE not re-evaluated on NPU.
  • Requires CANN 8.5.1 and torch_npu; CPU fallback fails explicitly.
  • Verbose progress disabled by default (verbose=False) for timing stability; enable with code change.

References

  • Kronos paper: https://arxiv.org/abs/2508.02739 | GitHub: https://github.com/shiyu-coder/Kronos
  • Hugging Face: https://huggingface.co/NeoQuasar/Kronos-small , https://huggingface.co/NeoQuasar/Kronos-Tokenizer-base