#NPU
| Component | Config |
|---|---|
| Model | d_model=512, n_layers=8, n_heads=8, ff_dim=1024, s1_bits=10, s2_bits=10, vocab 1024 each |
| Tokenizer | d_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 |
| Context | max_context=512, lookback=400 used |
| Horizon | pred_len=30 (configurable), example uses 30 |
| Device | npu:0 (Ascend910_9362) |
/tmp/Kronos/tests/data/regression_input.csv (2500 rows, AA share 5min K-line) + synthetic fallbacktimestamps, open, high, low, close, volume, amount['open','high','low','close','volume','amount'] (fixed)calc_time_stamps -> minute, hour, weekday, day, month (5 dims)(x - mean) / (std + 1e-5) computed on context window (400 rows)[-5, 5]pred * (std + 1e-5) + mean[Batch, Time, Channel] where Channel=6 for input, [B,T,5] for time featuresData privacy: no private data submitted; logs only show schema statistics and脱敏 forecasts.
| Item | Version |
|---|---|
| Python | 3.11.14 |
| Torch | 2.9.0+cpu |
| torch_npu | 2.9.0.post1+gitee7ba04 |
| Transformers | 4.57.6 |
| Pandas | 3.0.2 |
| Numpy | 1.26.4 |
| Einops | 0.8.1 |
| Huggingface_hub | 0.33.1 |
| Safetensors | 0.6.2 |
| Ascend Toolkit | /usr/local/Ascend/cann-8.5.1 (SOC ascend910_9391) |
| NPU | Ascend910_9362, 2 devices, visible 4,5 |
NPU check:
torch.npu.is_available()==True, device_count=2, device_name=Ascend910_9362
npu-smi info OKPeak memory for Kronos-small + tokenizer on npu:0: ~177 MB (model weights 110MB + activations/buffers)
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/KronosRequirements:
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.1Default command (verified on Ascend 910B, npu:0):
python inference.pyWhat it does:
torch.npu.is_available() and npu-smitorch.npu.set_device(0)/tmp/kronos-small,tokenizer or downloads from HuggingFace Hub with revision pinnednpu:0 via KronosPredictor(device="npu:0")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() timingExpected 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:0Dummy tensor verification:
[VERIFY] Dummy tensor device: npu:0
[VERIFY] Model param device after inference: npu:0No CPU fallback: explicit device="npu:0" and torch.npu.synchronize(); if NPU unavailable, script exits non-zero.
Real NPU inference on Ascend910_9362 (lookback 400 -> pred 30, batch 1, FP32):
| Metric | Value |
|---|---|
| First forecast open | 10.8214 |
| First forecast close | 10.8200 |
| Last forecast close | 10.7239 |
| Forecast mean close | 10.7677 |
| Forecast std close | 0.0388 |
| Volume mean | 851.25 |
| Amount mean | 902873 |
| Elapsed (first compile) | 0.65s |
| Avg after compile | 0.297s |
| Finite | True |
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.
CPU vs NPU on identical weights, data, preprocessing, seed=42, dtype FP32, eval mode:
torch.manual_seed(42) on cputorch.npu.set_device(0) + same seed, same predictor.predict argsOutputs saved as .npy (forecast tensor shape [30,6] float32):
/tmp/working/cpu_output.npy/tmp/working/npu_output.npyCompare 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.
Measured on npu:0, FP32, batch=1, lookback=400, pred_len=30, 6 channels, time features 5:
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.
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, validationassets/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.

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)