liucu/NeoQuasar-Kronos-Tokenizer-2k-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

NeoQuasar/Kronos-Tokenizer-2k NPU

#NPU

模型简介

Kronos-Tokenizer-2k 是 Kronos 金融时序基础模型的专用量化分词器,由 NeoQuasar 发布,论文 Kronos: A Foundation Model for the Language of Financial Markets。将 6 维 K 线(open/high/low/close/volume/amount)通过 BSQuantizer (20 bits = s1 10 + s2 10, group_size 5) 量化并重构。

  • 模型类型:表格/时间序列 Tokenization 重构
  • 架构:Encoder 3×TransformerBlock + BSQuantizer + Decoder 3×TransformerBlock,d_model 256 n_heads 4 ff_dim 512 4M 参数
  • 权重:model.safetensors 15.8 MiB FP32
  • 仓库:https://huggingface.co/NeoQuasar/Kronos-Tokenizer-2k
  • revision:26966d0035065a0cae0ebad7af8ece35bc1fb51c

Tokenizer-only checkpoint 不是完整预测模型,本仓完成同权重同输入同预处理同 dtype 的真实 NPU 重构验证。

数据契约

  • 输入:[batch, seq_len, 6] float32,6 列固定 ["open","high","low","close","volume","amount"] 顺序不可变
  • 预处理:按序列 z-score 并 clip [-5,5],与 KronosPredictor 一致
  • 输出:[batch, seq_len, 6] 重构张量 indices [batch, seq_len]
  • 数据来源:合成模拟 K 线(seed 42 batch 4 seq_len 64 随机游走围绕 100 volume ~5e6)
  • 缺失值:不得含 NaN

环境

  • NPU:Ascend910_9362 npu:0 device_count 2
  • CANN 8.5.1 /usr/local/Ascend/cann-8.5.1
  • Python 3.11.14 torch 2.9.0 torch_npu 2.9.0.post1 transformers 4.57.6 numpy 1.26.4 pandas 3.0.2 einops
  • HF_ENDPOINT=https://hf-mirror.com

安装

pip install -r requirements.txt

NPU 推理

python inference.py

绑定 npu:0,本地或 HF 镜像加载权重,生成合成 batch [4,64,6],encode->decode,torch.npu.synchronize 计时。

真实结果

Input [4,64,6] mean -0.00 std 1.00 min -5.00 max 5.00
encoded [4,64] sample [102699 275204 37135 37807 275328]
decoded [4,64,6] sample [1.0927 1.1143 1.1096 1.1130 1.2807 1.4784]
forward z [4,64,6] loss -0.068232
NPU avg 6.10 ms (10 runs, warmup 3) min 5.59 max 6.31 p50 6.21 p90 6.27 p95 6.29 throughput 655 windows/s
forward 53 ms, first param npu:0

无 CPU fallback。

一致性

  • 对象:reconstruction
  • 阈值:atol=1e-4 rtol=1e-3 FP32
  • 结果:max_abs 2.6e-06 mean_abs 3.1e-07 passed True
  • 命令:python scripts/compare_outputs.py --cpu cpu_recon.npy --npu npu_recon.npy --task regression --atol 1e-4 --rtol 1e-3
  • smoke consistency 非全量 benchmark

性能

阶段耗时
first-run6.24 ms
avg 106.10 ms min 5.59 max 6.31 p50 6.21 p90 6.27 p95 6.29
throughput655 windows/s batch 4
forward53 ms
峰值显存<2 GiB

不含 CSV 读取,仅模型 encode+decode。

证据图

agent_workflow npu_device_call model_result

三张 PNG 由 xterm.js 基于本次真实日志生成(raw 风格,提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$)。

限制

  • 仅 tokenizer 重构,需 paired Kronos-mini/small/base 才能预测
  • 输入须 6 维且 per-series 归一化
  • 超长 context >2048 未测

许可证

MIT