#NPU
[batch, seq_len, 6] (open, high, low, close, volume, amount) 连续 K 线,序列长度任意(推荐 ≤512)[batch, seq_len] (vocab 2^20) 或 half=True 时 [s1(2^10), s2(2^10)],以及通过 decode() 重建的 [batch, seq_len, 6]该 Tokenizer 是 Kronos 基金模型家族的专用分词器,需与 Kronos-small/base 配合完成自回归预测;单独使用可完成 K 线压缩/重建,零样本重建 MAE (normalized) ≈0.12。
[batch, time, channel],channel 固定为 6,顺序 open, high, low, close, volume, amountx_norm = clip((x - mean)/ (std+1e-5), -5, 5),与官方 KronosPredictor 预处理一致x_timestamp / y_timestamp 生成 minute/hour/weekday/day/month 嵌入kronos_input_norm.npy 由固定脚本生成,重复运行一致torch.npu.is_available()==True, device_count==2, torch.npu.get_device_name(0)==Ascend910_9362pip install -r requirements.txt
# requirements.txt 已固定版本,见文件默认命令(必须在 NPU 机器上执行,自动同步计时):
python inference.py
# 或自定义 batch/seq: python inference.py --batch 4 --seq_len 64 --device npu:0执行流程:
model_snapshot/ 或 /opt/atomgit/adapt-npu-agent/work_kronos_tokenizer/model_snapshot 加载本地权重;不存在则从 HuggingFace 公开下载 config.json + model.safetensors (NeoQuasar/Kronos-Tokenizer-base)KronosTokenizer 并 to("npu:0"),打印 first_param_device: npu:0forward 与 encode/decode,前后调用 torch.npu.synchronize() 计时单次真实运行(npu:0, batch 4, seq 64, float32):
model_name: NeoQuasar/Kronos-Tokenizer-base
revision: 0e0117387f...
device: npu:0
first_param_device: npu:0
input_shape: (4, 64, 6) input_dtype: torch.float32
input_summary: mean=0.000000 std=0.999159 min=-3.049207 max=2.853351
forward_first_ms: 315.20
encode_decode_ms: 11.36
output_recon_shape: (4, 64, 6) dtype float32
output_recon_summary: mean=0.002841 std=0.987892 min=-2.603998 max=2.854678
encode_indices_shape: (4, 64) unique=174 first5=[ 887106 625747 885031 581368 1016231]
bsq_loss: -0.066174
perf avg_ms=7.57 throughput_windows_per_sec=528.20
[SUCCESS] NPU inference completedCPU 与 NPU 使用同一权重、同一输入、同一预处理、同一 dtype (float32)、同一 seed (42)、eval 模式,对比 forward 重建与 encode/decode 重建:
python .opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu /tmp/cpu_recon_norm.npy --npu /tmp/npu_recon_norm.npy --task regression --atol 1e-4 --rtol 1e-3
python .opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu /tmp/cpu_decoded_norm.npy --npu /tmp/npu_decoded_norm.npy --task regression --atol 1e-4 --rtol 1e-3结果:
cpu_recon vs npu_recon: max_abs_error=2.15e-06 mean_abs_error=3.05e-07 PASSED (阈值 atol=1e-4 rtol=1e-3, FP32)cpu_decoded vs npu_decoded: 同上 PASSEDindices: np.array_equal(cpu_indices, npu_indices)==True,整数精确一致torch.npu.synchronize() 后计时torch.npu.synchronize(),不含数据生成与归一化(归一化在 CPU)三张 PNG 由 xterm.js 根据本次真实日志生成(raw 风格,固定提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$):

NeoQuasar/Kronos-small 或 base 并与本 tokenizer 配合使用 KronosPredictor / auto_regressive_inferencehalf=True 输出为两个 10-bit 索引,half=False 为 20-bit 单索引,读写需匹配