#NPU Ascend 910B Kronos-small financial K-line forecasting on NPU
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.
901c26c1332695a2a8f243eb2f37243a37bea320 (model.safetensors 95 MB)0e0117387f39004a9016484a186a908917e22426 (model.safetensors 16 MB)Tokenizer-only checkpoint is not a standalone forecasting model; this submission uses tokenizer + predictor jointly, as required.
['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.[B, T, C] with T = lookback (default 120, max 512) and C=6; forecast output [B, pred_len, 6](x - mean)/ (std + 1e-5) clipped to [-5,5]; inverse transform pred * (std+1e-5) + mean; no column reordering.max_context 512, default lookback 120, pred_len 8 (configurable via --lookback --pred-len)/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.2024-06-18 11:15:00,11.27,11.28,11.26,11.27,379.0,427161.0npu:0 (validated via torch.npu.is_available()==True, torch.npu.get_device_name(0), and next(model.parameters()).device == npu:0)assets/npu_device_call.pngpip install -r requirements.txt
# requirements.txt pins: torch, torch-npu, numpy, pandas, einops, huggingface_hub, tqdm, safetensorsWeights 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).
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 8Log 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.
Validated on Ascend 910B npu:0 with regression_input.csv (lookback 120 → pred_len 8):
[8,6], e.g. row0 [11.009843,11.015914,10.996269,11.00503,632.9165,643193.0], mean 264343.0[8,6], e.g. row0 [11.009843,11.015914,10.996269,11.00503,632.91687,643193.5], mean 264343.02024-06-18 11:15 -> 2024-06-20 14:40 historical, 2024-06-20 14:45 -> 2024-06-21 09:50 forecastFull terminal output in assets/model_result.png (xterm.js raw render).
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-3max_abs 5.00e-01 mean_abs 4.95e-02 rmse 1.43e-01 passed=True (np.allclose atol 1e-3 rtol 1e-3)amount (~3M scale) is <1e-6 relative.Synchronized with torch.npu.synchronize() before/after each run. Warmup 3, measured 10:
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.
Images are rendered via xterm.js (scripts/render_xterm_evidence.mjs --style raw) from real logs (raw style, prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$), not mocked.
assets/agent_workflow.pngtorch.npu.is_available(), device name, param device/dtype, input/output device: assets/npu_device_call.pngpython inference.py full stdout (schema, forecast head, latency, PASS): assets/model_result.png

top_k=1; stochastic top_p<1 not benchmarked.progress disabled by default (verbose=False) for timing stability; enable with code change.