{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Forecasting with Chronos\n", "\n", "[](https://colab.research.google.com/github/autogluon/autogluon/blob/master/docs/tutorials/timeseries/forecasting-chronos.ipynb)\n", "[](https://studiolab.sagemaker.aws/import/github/autogluon/autogluon/blob/master/docs/tutorials/timeseries/forecasting-chronos.ipynb)\n", "\n", "AutoGluon-TimeSeries (AG-TS) now features [Chronos](https://github.com/amazon-science/chronos-forecasting), a family of pretrained time series forecasting models. Chronos models are based on language model architectures, and work by quantizing time series into buckets which are treated as tokens. Language models are then trained on these token sequences using cross-entropy loss. \n", "\n", "The current iteration of Chronos models, [available](https://huggingface.co/amazon/chronos-t5-large) on Hugging Face 🤗, is based on the T5 architecture and was trained on a large corpus of open-source time series data augmented with synthetic data generation techniques. The Chronos [paper](https://arxiv.org/abs/2403.07815) provides greater detail about the models and how they were trained. \n", "\n", "AG-TS provides a robust and easy way to use Chronos through the familiar `TimeSeriesPredictor` API.\n", "- Chronos can be combined with other forecasting models to build accurate ensembles using the `\"high_quality\"` and `\"best_quality\"` presets.\n", "- Alternatively, Chronos can be used as a standalone zero-shot model with presets such as `\"chronos_small\"` or `\"chronos_base\"`." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [ "remove-cell", "skip-execution" ] }, "outputs": [], "source": [ "# We use uv for faster installation\n", "!pip install uv\n", "!uv pip install -q autogluon.timeseries --system\n", "!uv pip uninstall -q torchaudio torchvision torchtext --system # fix incompatible package versions on Colab" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from autogluon.timeseries import TimeSeriesDataFrame, TimeSeriesPredictor" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Getting Started with Chronos\n", "\n", "Chronos is available in 5 model sizes with different numbers of parameters: `tiny` (8M), `mini` (20M), `small` (46M), `base` (200M), and `large` (710M). Being a pretrained model for zero-shot forecasting, Chronos is different from other models available in AG-TS. \n", "Specifically, Chronos models do not really `fit` time series data. However, when `predict` is called, they carry out a relatively more expensive computation that scales linearly with the number of time series in the dataset. In this aspect, they behave like local statistical models such as ETS or ARIMA, where expensive computation happens during inference. Differently from statistical models, however, computation in the larger Chronos models requires an accelerator chip to run in a reasonable amount of time.\n", "\n", "The easiest way to get started with Chronos is through model-specific presets available in the `TimeSeriesPredictor`. As of v1.1, the `TimeSeriesPredictor.fit` method has a separate Chronos preset for each model size, such as `\"chronos_small\"` or `\"chronos_base\"`.\n", "\n", "Alternatively, Chronos can be combined with other time series models using presets `\"chronos_ensemble\"`, `\"chronos_large_ensemble\"`, `\"high_quality\"` and `\"best_quality\"`. More details about these presets are available in the documentation for [`TimeSeriesPredictor.fit`](https://auto.gluon.ai/stable/api/autogluon.timeseries.TimeSeriesPredictor.fit.html).\n", "\n", "Note that the model sizes `small` and higher require a GPU to run. However, models `tiny` and `mini` can be run on the CPU as well. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "Let's work with a subset of the M4 competition data set to see Chronos-tiny in action." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | \n", " | target | \n", "
---|---|---|
item_id | \n", "timestamp | \n", "\n", " |
H1 | \n", "1750-01-01 00:00:00 | \n", "605.0 | \n", "
1750-01-01 01:00:00 | \n", "586.0 | \n", "|
1750-01-01 02:00:00 | \n", "586.0 | \n", "|
1750-01-01 03:00:00 | \n", "559.0 | \n", "|
1750-01-01 04:00:00 | \n", "511.0 | \n", "