theforecastingcompany/t0-alpha 是 Nixtla / The Forecasting Company 的开源时间序列预测基础模型 t0 的首个公开迭代 t0-alpha。
tfc-t0 (PyPI) 提供 T0Forecaster / T0Config / Forecasttorch_npu), 全程不使用 CUDA, 模型与输入 Tensor 全部运行在 npu:0。init_npu() 在入口用 try-except 捕获异常:
torch_npu import 失败 → 打印清晰中文错误并优雅退出torch.npu.is_available() == False 或 device_count() < 1 → 同样优雅退出HF_ENDPOINT=https://hf-mirror.com) 自动下载, 本地缓存优先:
./model_weights/theforecastingcompany__t0-alpha (模型全名 / 换成 __)snapshot_downloadtfc-t0 库提供全部模型代码
(基于 PyTorchModelHubMixin), 因此无需 trust_remote_code, 直接
T0Forecaster.from_pretrained(<本地目录>, local_files_only=True)。config.json 若因受限下载不到, 程序会用官方 T0Config.medium() 自动重建
(即已发布 checkpoint 的公开超参数)。权重可得性说明:
theforecastingcompany/t0-alpha在 HuggingFace 上是gated(受限)模型, 匿名访问会被拒绝 (403)。当前镜像hf-mirror.com、 ModelScope、GitCode 均无可用镜像, 需要 HF token 才能下载model.safetensors。 若运行时出现权重文件缺失且无法从镜像下载, 请将权重手动放置到./model_weights/theforecastingcompany__t0-alpha/model.safetensors后重试。
requirements.txt。transformers 要求 huggingface-hub<1.0, 而 tfc-t0 声明 huggingface-hub>=1.0;
请用 --no-deps 安装 tfc-t0, 避免破坏 transformers。pip install "huggingface-hub>=0.34,<1.0" jaxtyping rotary-embedding-torch einops safetensors
pip install --no-deps "tfc-t0==0.3.0"
pip install fastapi uvicornpython3 inference.py --text "[1.0,2.1,3.2,4.0,5.1,6.0,7.2,8.3]" --horizon 8 --quantiles "0.1,0.5,0.9"输出为推理 JSON, 含 median(中位数点预测)、quantile_values(各分位数预测) 与设备信息。
uvicorn inference:app --host 0.0.0.0 --port 8003curl -s -X POST http://127.0.0.1:8003/predict \
-H 'Content-Type: application/json' \
-d '{"text":[1.0,2.1,3.2,4.0,5.1,6.0,7.2,8.3],"horizon":8}'返回推理 JSON; GET / 可查看服务信息与 /docs。
[1.0, 2.1, 3.2, 4.0]; 支持 (T,)、(B, T) 或 (B, V, T)。median 为点预测序列, quantile_values 为各分位数的概率区间预测
(模型原生分位数为 0.1/0.25/0.5/0.75/0.9, 其余分位数由插值得到)。model_weights/theforecastingcompany__t0-alpha/
├── config.json
└── model.safetensorsassets/agent_workflow.png — NPU 环境部署、依赖安装、任务启动日志assets/npu_device_call.png — 命令行 python 推理运行 (真实 stdout)assets/model_result.png — FastAPI curl 上传输入返回推理 JSON (真实 HTTP 响应)