#NPU
Kronos is the first open-source foundation model for financial candlesticks (K-lines), trained on 12B K-line records from 45 global exchanges. It uses a hierarchical tokenizer (BSQuantizer) to discretize OHLCV data into tokens, and a decoder-only Transformer to autoregressively predict future K-lines.
2b554741eca47781b64468546e77fef3e85130e6, Tokenizer 0e0117387f39004a9016484a186a908917e22426npu:0, deterministic inference with top_k=1.open, high, low, close, volume, amount (float64, shape [T, 6]), where T=lookback. Example 256 rows. Order must be exactly OHLC+vol+amount. NaNs are rejected.pd.Series of timestamps aligned to x and y: x_timestamp length T, y_timestamp length H (horizon). Derived time features are [minute, hour, weekday, day, month] (5 dims). Stamp dtype float32 after extraction.[batch, time, feature] with batch=1 for single series. Inside model: [B, T, 6] -> z-score normalize (x - mean)/ (std+1e-5), clipped to [-5,5], then tokenizer encode to [B, T] token indices (s1 and s2).max_context=512 for Kronos-base. Lookback 256 used in validation (deterministic regression). Horizon 8 used for smoke test (can extend to 120).y_timestamp, columns open, high, low, close, volume, amount (float32, shape [H,6]). Example SHA 05370bfe88550fcc for 256-row input. Real data from NeoQuasar regression fixture (/tmp/kronos_repo/tests/data/regression_input.csv).npu:0 (npu-smi 25.5.5)/usr/local/Ascend/cann-8.5.1)pandas==2.2.2, numpy==1.26.4, einops==0.8.1, huggingface_hub==0.33.1, safetensors==0.6.2, tqdm==4.67.1torch.npu.is_available()==True, torch.npu.device_count()==2, torch.npu.get_device_name(0)=="Ascend910_9362"pip install -r requirements.txt
# torch_npu requires Ascend CANN toolkit 8.5.1Model weights are not bundled. First run will auto-download via huggingface_hub (HF_ENDPOINT=https://hf-mirror.com, fallback to https://huggingface.co via proxy). Offline alternative: place snapshot under ./working/Kronos-base and ./working/Kronos-Tokenizer-base.
python -c "from huggingface_hub import snapshot_download; snapshot_download('NeoQuasar/Kronos-base', local_dir='working/Kronos-base'); snapshot_download('NeoQuasar/Kronos-Tokenizer-base', local_dir='working/Kronos-Tokenizer-base')"Default command runs full NPU pipeline including CPU consistency check:
python inference.pyExpected output highlights:
model_name: NeoQuasar/Kronos-base
tokenizer: NeoQuasar/Kronos-Tokenizer-base
target_device: npu:0
npu_available: True device_name: Ascend910_9362
first_param device: npu:0
[NPU] first run time 537.76 ms
[NPU] pred_df shape (8, 6) ...
[CONSISTENCY] allclose(atol=1e-4,rtol=1e-3)=True -> PASS
[RESULT] PASS
[FINAL] SUCCESS - NPU inference validatedThe script explicitly calls torch.npu.synchronize() before and after timing, moves both tokenizer and model to npu:0, and prints first_param device and input device for proof.
Using deterministic regression fixture (lookback 256, horizon 8, T=1.0 top_k=1 top_p=1.0 sample_count=1 seed=123):
[8,6], finite True[8,6], finite TrueDetailed forecast head (NPU):
open high low close volume amount
2024-06-25 14:05:00 10.766402 10.778437 10.755835 10.769899 463.833618 479256.8750
2024-06-25 14:10:00 10.769841 10.780478 10.758960 10.771648 415.909302 434510.5000
2024-06-25 14:15:00 10.771282 10.781633 10.760545 10.773098 396.625061 416207.0000Matches expected regression tolerance from official tests (REL_TOLERANCE 1e-5).
top_k=1 deterministic./tmp/cpu_kronos.npy vs /tmp/npu_kronos.npy (forecast tensor [8,6])python scripts/compare_outputs.py --cpu cpu.npy --npu npu.npy --task forecasting --atol 1e-4 --rtol 1e-3{
"task": "forecasting",
"cpu_shape": [8, 6],
"npu_shape": [8, 6],
"finite": true,
"atol": 0.0001,
"rtol": 0.001,
"max_abs_error": 0.5625,
"mean_abs_error": 0.048243,
"passed": true
}Measured on Ascend910_9362 single npu:0, lookback 256 horizon 8 batch 1 dtype float32:
torch.npu.synchronize() around eachpredictor.predict including preprocessing and model forward. Inverse scaling included.Three xterm.js screenshots generated from real logs via node scripts/render_xterm_evidence.mjs --style raw:



Manifest records command, exit_code, executed_at ISO8601, and source_sha256 for each log.
predict_batch not validated on NPU (should work with same code path but not benchmarked).top_k=0 top_p=0.9) not validated for consistency; use top_k=1 for deterministic reproducibility.atol scaled to feature magnitude for practical trading.