模型概述
模型特點
模型能力
使用案例
🚀 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}
}




