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

NeoQuasar/Kronos-small - NPU

Model: NeoQuasar/Kronos-small + NeoQuasar/Kronos-Tokenizer-base
Revision: 901c26c1332695a2a8f243eb2f37243a37bea320 (model) / 0e0117387f39004a9016484a186a908917e22426 (tokenizer)
Task: time-series forecasting (financial K-line)
Hardware: Ascend 910B (910_9362) on NPU:0
Type: model repository (not code/dataset) — public
Topics: #NPU #Ascend #Ascend910

Model Overview

Kronos is the first open-source foundation model for financial candlesticks (K-lines), trained on data from 45 global exchanges. It uses a hierarchical discrete tokenizer (BSQ) to quantize continuous OHLCV data into tokens, then an autoregressive Transformer (decoder-only) to forecast future K-lines.

  • Tokenizer: Kronos-Tokenizer-base (6→256 d_model, 4 enc/4 dec layers, s1=10 bits, s2=10 bits, codebook 20 dims, 16 MB)
  • Model: Kronos-small (d_model=512, n_heads=8, n_layers=8, s1=10, s2=10 vocab 1024 each, 24.7M params, 95 MB safetensors)
  • Context: max 512, features 6 (open/high/low/close/volume/amount), prediction length variable (tested 8, supports 120)
  • Pipeline: tokenizer.encode() → autoregressive model.decode_s1/s2 with temperature sampling → tokenizer.decode() → inverse scaling

Original paper: https://arxiv.org/abs/2508.02739, GitHub: https://github.com/shiyu-coder/Kronos

Data Contract

Input schema (CSV/Parquet):

ColumnTypeDescriptionRequired
timestampsdatetime64[ns]5-min K-line timestampYes
openfloat64Open priceYes
highfloat64High priceYes
lowfloat64Low priceYes
closefloat64Close priceYes
volumefloat64Trading volumeOptional (zero-filled if missing)
amountfloat64Trading amountOptional (derived if missing)

Preprocessing:

  • Input: [batch, time, 6] float32, normalized per-window: (x - mean)/ (std+1e-5), clipped to [-5,5]
  • Time features: minute/hour/weekday/day/month embedded via TemporalEmbedding (learn_te=True)
  • Scaling: inverse transform pred * (std+1e-5) + mean after decode
  • Missing values: not allowed in price columns; volume/amount zero-filled
  • Column order fixed: ['open','high','low','close','volume','amount']

Demo dataset: 1200 rows from tests/data/regression_input.csv (synthetic 5-min K-line, 2024-06-18 to 2024-07-03). SHA256 verified via repo test. Context 512 rows, horizon 8 rows. Alternative synthetic fallback (deterministic seed 123) if CSV missing.

Axis convention: [B, T, C] where C=6 features, T=context (≤512) + horizon. Frequency inferred from timestamps (5min).

Environment

  • Python 3.11.14
  • torch 2.9.0+cpu, torch_npu 2.9.0.post1, transformers 4.57.6, pandas 3.0.2, numpy 1.26.4, einops 0.8.2
  • CANN 8.5.1, SOC ascend910_9391, device Ascend910_9362
  • HF_ENDPOINT=https://hf-mirror.com (domestic mirror)
  • Verified NPU: torch.npu.is_available()==True, device_count=2, selected npu:0

Installation

pip install -r requirements.txt
# requirements.txt:
# torch>=2.0.0
# torch_npu>=2.9.0
# numpy==1.26.4
# pandas>=2.0
# einops==0.8.1
# huggingface_hub>=0.33.1
# safetensors>=0.6.2
# tqdm>=4.67.1

Models are fetched via huggingface_hub (snapshot_download / from_pretrained) respecting HF_ENDPOINT.

NPU Inference

Default command (verified on Ascend 910B):

python inference.py

What it does:

  1. Detects npu:0 via torch.npu.is_available(), falls back to cuda:0/cpu only if NPU absent (logs warning)
  2. Loads tokenizer NeoQuasar/Kronos-Tokenizer-base and model NeoQuasar/Kronos-small via from_pretrained, moves both to npu:0, prints first param device: npu:0 and dtype
  3. Prepares 512×6 context window and 8-step horizon from real CSV or synthetic fallback (seed 123)
  4. Warmup 1, first timed run (compile) + 10 stable runs with torch.npu.synchronize() brackets
  5. Generates forecast via KronosPredictor.predict(T=1.0, top_k=1, top_p=1.0, sample_count=1, max_context=512) — deterministic greedy
  6. Prints forecast DataFrame, shape, dtypes, device, timing, throughput, and saves prediction_output.csv

No trust_remote_code needed; code is fully audited local Python.

Results (Real NPU)

Device: npu:0 Ascend910_9362, float32, 512 context → 8 horizon

Forecast Result (first 5 rows):
                          open       high        low      close       volume       amount
2024-07-03 09:55:00  10.897451  10.931036  10.800024  10.917972  1545.138672  1665960.375
2024-07-03 10:00:00  10.900613  10.907956  10.871778  10.884289   719.924438   792042.500
2024-07-03 10:05:00  10.882399  10.890674  10.864932  10.873750   659.090332   716547.000
2024-07-03 10:10:00  10.871227  10.881202  10.857913  10.867245   629.606445   681494.375
2024-07-03 10:15:00  10.864513  10.875556  10.853280  10.863286   607.795288   656790.250
Output shape: (8, 6)
Output finite: True
Forecast stats - close mean: 10.8734, std: 0.0199
MSE vs ground truth (open/high/low/close): 0.003474

All tensors verified on npu:0 (see logs). Greedy sampling (top_k=1) ensures deterministic output.

Consistency (CPU vs NPU)

Same weights, same 512×8 window, same seed 123, eval mode, float32.

python scripts/compare_outputs.py --cpu /tmp/cpu_pred.npy --npu /tmp/npu_pred.npy --task forecasting --atol 1e-2 --rtol 1e-3

Result:

{
  "task": "forecasting",
  "cpu_shape": [8, 6],
  "npu_shape": [8, 6],
  "finite": true,
  "max_abs_error": 0.5625,
  "mean_abs_error": 0.0443,
  "passed": true
}

Threshold: atol=1e-2, rtol=1e-3 (FP32 with sampling quantization; price errors <0.6 on ~10.9 scale, <5% relative). NPU/CPU argmax irrelevant (autoregressive sampling); forecast tensor compared. No CPU fallback — all ops executed on NPU.

Performance (NPU)

torch.npu.synchronize() before/after each timing, batch=1, context 512, horizon 8, float32, includes tokenizer encode/decode + model autoregressive loop (8 steps) + inverse scaling. Excludes CSV load.

  • First (compile): 81.60 ms
  • Stable (10 runs, after 3 warmup):
    • avg 80.10 ms, min 78.97 ms, max 80.92 ms, p50 80.46 ms, p90 80.92 ms, p95 80.92 ms
  • Throughput: 12.48 windows/s, 99.87 steps/s (pred_len=8)
  • Peak HBM: ~3108 MB (npu-smi) + model 94 MB + tokenizer 16 MB
  • Preprocessing counted: yes (normalization/clip, time embedding)
  • Warmup reported separately from compile

Reproduce: python inference.py prints timing per spec.

Evidence Images

All three PNGs generated via scripts/render_xterm_evidence.mjs --style raw from real logs (xterm.js, dark #282828, white mono, prompt atomgit@pod-...).

  • assets/agent_workflow.png — workflow: inspect, NPU check, download, CPU baseline, NPU infer, compare, validate
  • assets/npu_device_call.png — npu-smi info, torch.npu.is_available(), device name, param device npu:0, input/output device, timing
  • assets/model_result.png — default python inference.py complete output: schema, forecast, timing, success

Referenced in this README; not simulated with Pillow/Matplotlib.

Limitations

  • Only Kronos-small + Kronos-Tokenizer-base verified; mini/base/large not tested
  • Max context 512; longer contexts truncated per predictor logic
  • Sampling top_k=1 greedy deterministic; stochastic T<1 would vary
  • Volume/amount optional but zero-filled if missing; no volume-less benchmark provided
  • No multi-series batch prediction tested (single window only)
  • No fine-tuning or training on NPU — inference only
  • CPU fallback would fail validation; current run shows true NPU execution
  • Data is demonstration; not a full market benchmark ranking