模型简介
模型特点
模型能力
使用案例
🚀 Chronos - Bolt⚡ (Small)
Chronos - Bolt是一系列预训练的时间序列预测模型,可用于零样本预测。它基于T5编码器 - 解码器架构,在近1000亿个时间序列观测值上进行了训练。该模型将历史时间序列上下文分块为多个观测值的片段,然后输入到编码器中。解码器再利用这些表示直接生成多个未来步骤的分位数预测,这是一种称为直接多步预测的方法。与相同大小的原始Chronos模型相比,Chronos - Bolt模型的速度快达250倍,内存效率提高20倍。
🚀 快速开始
与AutoGluon一起使用
在生产用例中,推荐通过AutoGluon使用Chronos。AutoGluon提供了对Chronos模型轻松的微调功能,可通过协变量回归器将协变量纳入预测中,还能与其他统计和机器学习模型进行集成以实现最高的预测准确性。更多详细信息请查看AutoGluon Chronos 教程。
将Chronos - Bolt端点部署到SageMaker
SageMaker JumpStart可以让你只需几行代码就能轻松部署用于生产的Chronos端点。Chronos - Bolt端点可以部署到CPU和GPU实例上,并且支持使用协变量进行预测。更多详细信息可查看此[示例笔记本](https://github.com/amazon - science/chronos - forecasting/blob/main/notebooks/deploy - chronos - bolt - to - amazon - sagemaker.ipynb)。
使用推理库
或者,你可以在GitHub [配套仓库](https://github.com/amazon - science/chronos - forecasting)中安装该包。这主要用于研究目的,并为Chronos模型提供了一个简洁的接口。
✨ 主要特性
- 高性能:Chronos - Bolt模型不仅速度比原始Chronos模型显著更快,而且预测准确性更高。
- 多尺寸可选:提供了多种不同参数规模的模型,包括
chronos - bolt - tiny
、chronos - bolt - mini
、chronos - bolt - small
和chronos - bolt - base
。 - 多方式使用:支持与AutoGluon集成使用、部署到SageMaker以及使用推理库进行推理。
📦 安装指南
与AutoGluon一起使用
安装所需的依赖项:
pip install autogluon
将Chronos - Bolt端点部署到SageMaker
更新SageMaker SDK以确保所有最新模型可用:
pip install -U sagemaker
使用推理库
安装库:
pip install chronos-forecasting
💻 使用示例
基础用法
与AutoGluon一起使用
以下是一个使用Chronos - Bolt和AutoGluon进行零样本推理的最小示例:
from autogluon.timeseries import TimeSeriesPredictor, TimeSeriesDataFrame
df = TimeSeriesDataFrame("https://autogluon.s3.amazonaws.com/datasets/timeseries/m4_hourly/train.csv")
predictor = TimeSeriesPredictor(prediction_length=48).fit(
df,
hyperparameters={
"Chronos": {"model_path": "amazon/chronos-bolt-small"},
},
)
predictions = predictor.predict(df)
将Chronos - Bolt端点部署到SageMaker
以下是一个将Chronos - Bolt (Base)端点部署到SageMaker的最小示例:
from sagemaker.jumpstart.model import JumpStartModel
model = JumpStartModel(
model_id="autogluon-forecasting-chronos-bolt-base",
instance_type="ml.c5.2xlarge",
)
predictor = model.deploy()
现在你可以将JSON格式的时间序列数据发送到端点:
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/AileenNielsen/TimeSeriesAnalysisWithPython/master/data/AirPassengers.csv")
payload = {
"inputs": [
{"target": df["#Passengers"].tolist()}
],
"parameters": {
"prediction_length": 12,
}
}
forecast = predictor.predict(payload)["predictions"]
使用推理库
以下是一个使用Chronos - Bolt模型进行推理的最小示例:
import pandas as pd # requires: pip install pandas
import torch
from chronos import BaseChronosPipeline
pipeline = BaseChronosPipeline.from_pretrained(
"amazon/chronos-bolt-small",
device_map="cuda", # use "cpu" for CPU inference and "mps" for Apple Silicon
torch_dtype=torch.bfloat16,
)
df = pd.read_csv(
"https://raw.githubusercontent.com/AileenNielsen/TimeSeriesAnalysisWithPython/master/data/AirPassengers.csv"
)
# context must be either a 1D tensor, a list of 1D tensors,
# or a left-padded 2D tensor with batch as the first dimension
# Chronos-Bolt models generate quantile forecasts, so forecast has shape
# [num_series, num_quantiles, prediction_length].
forecast = pipeline.predict(
context=torch.tensor(df["#Passengers"]), prediction_length=12
)
📚 详细文档
性能
以下图表比较了Chronos - Bolt与原始Chronos模型在预测1024个时间序列时的推理时间,上下文长度为512个观测值,预测范围为64步。
Chronos - Bolt模型不仅速度显著更快,而且比原始Chronos模型更准确。以下图表分别报告了Chronos - Bolt在加权分位数损失 (WQL)和平均绝对缩放误差 (MASE)方面的概率和点预测性能,这些性能是在27个数据集上汇总得到的(有关此基准测试的详细信息,请参阅Chronos论文)。值得注意的是,尽管在训练期间没有接触过这些数据集,但零样本的Chronos - Bolt模型的性能优于在这些数据集上训练的常用统计模型和深度学习模型(用*突出显示)。此外,它们的性能也优于其他基础模型(用 + 表示),这表明这些模型在我们基准测试中的某些数据集上进行了预训练,并非完全零样本。值得一提的是,Chronos - Bolt (Base)在预测准确性方面也超过了原始Chronos (Large)模型,同时速度快了600多倍。
Chronos - Bolt模型有以下几种尺寸可供选择:
模型 | 参数数量 | 基于的模型 |
---|---|---|
[chronos - bolt - tiny](https://huggingface.co/amazon/chronos - bolt - tiny) | 9M | [t5 - efficient - tiny](https://huggingface.co/google/t5 - efficient - tiny) |
[chronos - bolt - mini](https://huggingface.co/amazon/chronos - bolt - mini) | 21M | [t5 - efficient - mini](https://huggingface.co/google/t5 - efficient - mini) |
[chronos - bolt - small](https://huggingface.co/amazon/chronos - bolt - small) | 48M | [t5 - efficient - small](https://huggingface.co/google/t5 - efficient - small) |
[chronos - bolt - base](https://huggingface.co/amazon/chronos - bolt - base) | 205M | [t5 - efficient - base](https://huggingface.co/google/t5 - efficient - base) |
🔧 技术细节
Chronos - Bolt基于T5编码器 - 解码器架构,它将历史时间序列上下文分块为多个观测值的片段,然后输入到编码器中。解码器再利用这些表示直接生成多个未来步骤的分位数预测,这是一种称为直接多步预测的方法。
📄 许可证
本项目采用Apache - 2.0许可证。
引用
如果你发现Chronos或Chronos - Bolt模型对你的研究有用,请考虑引用相关论文:
@article{ansari2024chronos,
title={Chronos: Learning the Language of Time Series},
author={Ansari, Abdul Fatir and Stella, Lorenzo and Turkmen, Caner and Zhang, Xiyuan, and Mercado, Pedro and Shen, Huibin and Shchur, Oleksandr and Rangapuram, Syama Syndar and Pineda Arango, Sebastian and Kapoor, Shubham and Zschiegner, Jasper and Maddix, Danielle C. and Mahoney, Michael W. and Torkkola, Kari and Gordon Wilson, Andrew and Bohlke-Schneider, Michael and Wang, Yuyang},
journal={Transactions on Machine Learning Research},
issn={2835-8856},
year={2024},
url={https://openreview.net/forum?id=gerNCVqqtR}
}




