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

NeoQuasar/Kronos-small NPU Adapted

#NPU

Model Information

  • Model Name: NeoQuasar/Kronos-small
  • Model Weight URL: https://huggingface.co/NeoQuasar/Kronos-small
  • Tokenizer: NeoQuasar/Kronos-Tokenizer-base (revision 0e0117387f39004a9016484a186a908917e22426)
  • Model Revision: 901c26c1332695a2a8f243eb2f37243a37bea320
  • Pipeline Tag: time-series-forecasting
  • Architecture Family: Time-Series Tokenized Autoregressive (Kronos + KronosTokenizer)
  • Task Type: forecasting (K-line OHLCV prediction)
  • Parameter Count: Model 24.74M (95MB safetensors), Tokenizer 3.96M (16MB), Total ~28.7M
  • License: MIT
  • Paper: https://arxiv.org/abs/2508.02739
  • Original Repository: https://github.com/shiyu-coder/Kronos

Architecture Details

ComponentConfig
Modeld_model=512, n_layers=8, n_heads=8, ff_dim=1024, s1_bits=10, s2_bits=10, vocab 1024 each
Tokenizerd_in=6, d_model=256, n_enc_layers=4, n_dec_layers=4, n_heads=4, ff_dim=512, s1_bits=10, s2_bits=10
Contextmax_context=512, lookback=400 used
Horizonpred_len=30 (configurable), example uses 30
Devicenpu:0 (Ascend910_9362)

Data Contract

  • Data Source: Kronos official regression test data /tmp/Kronos/tests/data/regression_input.csv (2500 rows, AA share 5min K-line) + synthetic fallback
  • SHA-256: aa5efe0121b7cc098db1a169ed38f9878681ef14a93c85d54a618fd073048899 (sample_data.csv)
  • Format: CSV with columns timestamps, open, high, low, close, volume, amount
  • Rows: 2500 (example subset 430 rows: 400 context + 30 forecast)
  • Columns / Dtypes: timestamps: datetime64[ns], open/high/low/close/volume/amount: float64
  • Missing Values: 0
  • Feature Order: ['open','high','low','close','volume','amount'] (fixed)
  • Time Features: Derived from timestamps via calc_time_stamps -> minute, hour, weekday, day, month (5 dims)
  • Preprocessing:
    • Per-window z-score normalization: (x - mean) / (std + 1e-5) computed on context window (400 rows)
    • Clip to [-5, 5]
    • Tokenizer encode to hierarchical discrete tokens (s1, s2) with BSQuantizer
    • Inverse transform after decode: pred * (std + 1e-5) + mean
  • Target Columns: OHLCV+amount all forecasted (no explicit target_column, multivariate forecast)
  • Axis Order: [Batch, Time, Channel] where Channel=6 for input, [B,T,5] for time features
  • Frequency: 5min (irregular market hours, not continuous)
  • Scaling: Inverse scaling applied before returning DataFrame; consistency compared on inverse-scaled forecast

Data privacy: no private data submitted; logs only show schema statistics and脱敏 forecasts.

Environment

ItemVersion
Python3.11.14
Torch2.9.0+cpu
torch_npu2.9.0.post1+gitee7ba04
Transformers4.57.6
Pandas3.0.2
Numpy1.26.4
Einops0.8.1
Huggingface_hub0.33.1
Safetensors0.6.2
Ascend Toolkit/usr/local/Ascend/cann-8.5.1 (SOC ascend910_9391)
NPUAscend910_9362, 2 devices, visible 4,5

NPU check:

torch.npu.is_available()==True, device_count=2, device_name=Ascend910_9362
npu-smi info OK

Peak memory for Kronos-small + tokenizer on npu:0: ~177 MB (model weights 110MB + activations/buffers)

Installation

pip install -r requirements.txt
# Kronos source will be auto-cloned if missing (https://github.com/shiyu-coder/Kronos)
# Or manually: git clone https://github.com/shiyu-coder/Kronos.git /tmp/Kronos

Requirements:

torch==2.9.0
torch_npu==2.9.0.post1
numpy==1.26.4
pandas==3.0.2
einops==0.8.1
huggingface_hub==0.33.1
safetensors==0.6.2
tqdm==4.67.1

NPU Inference

Default command (verified on Ascend 910B, npu:0):

python inference.py

What it does:

  1. Checks torch.npu.is_available() and npu-smi
  2. Sets torch.npu.set_device(0)
  3. Loads tokenizer and model from local /tmp/kronos-small,tokenizer or downloads from HuggingFace Hub with revision pinned
  4. Moves model+tokenizer to npu:0 via KronosPredictor(device="npu:0")
  5. Loads sample data (seed 42, lookback 400, pred_len 30)
  6. Runs predictor.predict with T=1.0, top_k=1, top_p=1.0, sample_count=1, max_context=512 under torch.no_grad() and torch.npu.synchronize() timing
  7. Prints input/output device, shape, stats, timing, and success status (exit 0 = success)

Expected output excerpt:

[LOAD] predictor.device=npu:0
[LOAD] model first param device: npu:0
[INFER] Completed in 0.65s (sync timed)
[RESULT] Forecast tensor shape (30, 6), finite True
[STATUS] NPU inference SUCCESS on npu:0

Dummy tensor verification:

[VERIFY] Dummy tensor device: npu:0
[VERIFY] Model param device after inference: npu:0

No CPU fallback: explicit device="npu:0" and torch.npu.synchronize(); if NPU unavailable, script exits non-zero.

Results

Real NPU inference on Ascend910_9362 (lookback 400 -> pred 30, batch 1, FP32):

MetricValue
First forecast open10.8214
First forecast close10.8200
Last forecast close10.7239
Forecast mean close10.7677
Forecast std close0.0388
Volume mean851.25
Amount mean902873
Elapsed (first compile)0.65s
Avg after compile0.297s
FiniteTrue

Full forecast head (30 rows):

                 open     high      low    close    volume     amount
2024-06-28 14:05 10.821 10.833 10.810 10.820 525.75 566627
2024-06-28 14:10 10.820 10.831 10.809 10.818 533.29 572885
2024-06-28 14:15 10.817 10.828 10.807 10.816 531.14 570466
...

Ground truth comparison (sample not shown, this is zero-shot forecast). Consistency validated vs CPU.

Consistency

CPU vs NPU on identical weights, data, preprocessing, seed=42, dtype FP32, eval mode:

  • CPU: torch.manual_seed(42) on cpu
  • NPU: torch.npu.set_device(0) + same seed, same predictor.predict args

Outputs saved as .npy (forecast tensor shape [30,6] float32):

  • CPU: /tmp/working/cpu_output.npy
  • NPU: /tmp/working/npu_output.npy

Compare via scripts/compare_outputs.py --task forecasting --atol 1e-4 --rtol 1e-3:

{
  "task": "forecasting",
  "cpu_shape": [30, 6],
  "npu_shape": [30, 6],
  "finite": true,
  "atol": 0.0001,
  "rtol": 0.001,
  "max_abs_error": 1.5625,
  "mean_abs_error": 0.055267,
  "passed": true
}

Note: max_abs 1.56 comes from amount channel (~3.9M scale), relative error < 0.0004%, within rtol 1e-3. Clipping and inverse scaling identical. Smoke consistency only (single window 400->30), not full benchmark.

No CPU fallback observed; model params remain on npu:0 throughout.

Performance

Measured on npu:0, FP32, batch=1, lookback=400, pred_len=30, 6 channels, time features 5:

  • First run (compile): 0.64s
  • Warmup 3: 0.291s, 0.293s, 0.298s
  • Formal 10: avg 0.297s, min 0.294s, max 0.299s, p50 0.297s, p90 0.299s, p95 0.299s
  • Throughput: 3.36 windows/s (or series/s)
  • Tokens: context 400 + generate 30 autoregressive steps (each step decode_s1+decode_s2)
  • Peak NPU memory: 177.11 MB
  • Rows/s: not applicable for time series (windows/s reported)
  • Preprocessing timed included? No, timing wraps only predictor.predict (includes normalization, tokenization, autoregressive generation, detokenization, but not CSV I/O which is outside timed region). torch.npu.synchronize() before and after.

CPU baseline for same window: 13.64s (20x slower), confirming NPU acceleration.

Evidence

Three PNGs generated via scripts/render_xterm_evidence.mjs --style raw from real logs (fixed prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$):

  • assets/agent_workflow.png - full adaptation workflow: inspect, data check, download, load, NPU inference, consistency, benchmark, validation
  • assets/npu_device_call.png - npu-smi and NPU device calls (model param device npu:0, dummy tensor npu:0)
  • assets/model_result.png - default python inference.py output (forecast head, timing, SUCCESS)

Rendered with xterm.js raw style, dark grey background, white monospace. Logs sanitized for tokens.

workflow device result

Limitations

  • Only single window (400->30) smoke consistency, not full dataset evaluation (2500 rows would be 2000 windows)
  • FP32 only; FP16/BF16 not tested (FP32 rtol 1e-3 may need loosening for low precision)
  • Autoregressive sampling with top_k=1 deterministic greedy; stochastic sampling (T>1, top_p<1) will diverge between CPU/NPU due to multinomial randomness unless same seed and deterministic algorithm (verified deterministic with top_k=1)
  • Data is 5min AA market K-line from Jun-Aug 2024; other frequencies/markets not validated
  • 512 max context; longer contexts truncated
  • Volume/Amount forecast scale-sensitive; atol should be scaled per channel if using mixed magnitudes
  • Requires Ascend CANN 8.5.1, torch_npu 2.9.0, and internet for HF download on first run (cached thereafter)
  • Not training adaptation, only inference (fit() not needed for Kronos zero-shot)

References

  • Kronos paper: https://arxiv.org/abs/2508.02739
  • GitHub: https://github.com/shiyu-coder/Kronos
  • HF Model: https://huggingface.co/NeoQuasar/Kronos-small
  • HF Tokenizer: https://huggingface.co/NeoQuasar/Kronos-Tokenizer-base