赛事: 昇腾 Model Agent 模型适配大赛(第二季) 引擎: torch_npu + transformers 4.40.1 (trust_remote_code) 硬件: Ascend 910B 系列(实测 Ascend910B4) 标签:
npuascendpytorchtransformers
| 属性 | 值 |
|---|---|
| 原始模型 | thuml/timer-base-84m |
| 架构 | Causal Transformer(Decoder-only),TIMER 大规模时序基础模型 |
| 参数量 | 84.14M(预训练 260B 时间点) |
| 任务类型 | 时序预测(Time Series Forecasting,zero-shot) |
| 输入格式 | 长度 ≤ 2880 的过去值序列 |
| 输出格式 | 未来 96 步预测 |
⚠️ TIMER 使用自定义 transformers 代码(trust_remote_code),需与
transformers==4.40.1配套。
python3 -m venv --system-site-packages venv
source venv/bin/activate
pip install -r requirements.txt -i https://repo.huaweicloud.com/repository/pypi/simple/⚠️ 本仓库不包含模型权重(交付件仅
inference.py/readme.md/requirements.txt/assets/), 推理前必须先从原始模型仓单独下载权重。
# 1. 下载模型权重(仓库不含权重,必须单独下载)
git clone https://gitcode.com/hf_mirrors/thuml/timer-base-84m.git .
git lfs pull
# 2. 运行 NPU 推理(缺省 2880 点示例数据,预测 96 步)
python3 inference.py --model_path . --device npu:0
# 自定义输入
python3 inference.py --model_path . --input "50,50.5,51,..." --prediction_length 96 --device npu:0python3 inference.py --model_path . --device npu:0预期输出:
[Model Agent] ✅ NPU 设备就绪: Ascend910B4
[Model Agent] ✅ 模型加载完成 → npu:0
[Model Agent] 📊 输入过去值: 2880 个, 预测 96 步
[Model Agent] ✅ 推理完成 → 预测 96 步, 耗时 296.91 ms
[Model Agent] 📈 预测前5: [108.05, 107.97, 107.95, 108.29, 107.69]
[Model Agent] ✅ 结果已保存 → inference_result.json.
├── inference.py # NPU 推理脚本
├── readme.md # 本文件
├── requirements.txt # 依赖清单
└── assets/ # 截图素材本模型由 昇腾 Model Agent 自动完成 NPU 适配。
TimerForPrediction(自定义 Causal Transformer)迁移至昇腾 NPU:
transformers==4.40.1(TIMER 官方指定版本,自定义代码与 5.x 不兼容);trust_remote_code=True 加载自定义 modeling_timer.py;torch_npu 完成设备初始化,model.generate() 自回归生成预测。