Ray
Distribute TimeGPT forecasting jobs on Ray for scalable Python workloads.
TimeGPT on Ray
Ray is an open-source unified compute framework that helps scale Python workloads for distributed computing. In this tutorial, you will learn how to distribute TimeGPT forecasting jobs on top of Ray.
This guide uses Fugue to easily run code across various distributed computing frameworks, including Ray.
Overview
Key Concepts
Key Concepts
Ray
A framework for scaling Python beyond a single machine.
Fugue
A unified interface to execute Python code on several backends (including Ray).
TimeGPT
A Nixtla service for scalable time-series forecasting.
By combining Ray, Fugue, and TimeGPT, you can quickly scale your time-series forecasting tasks in distributed environments.
Below is an outline of what we’ll cover:
- Installation
- Load Your Data
- Initialize Ray
- Use TimeGPT on Ray
- Shutdown Ray
1. Installation
Install Ray using Fugue. Fugue provides an easy-to-use interface for distributed computation. It lets you run Python code on several distributed computing frameworks, including Ray.
When executing on a distributed Ray cluster, ensure the nixtla
library is installed on all workers.
2. Load Your Data
Load your dataset into a pandas DataFrame. This tutorial uses hourly electricity prices from various markets:
unique_id | ds | y | |
---|---|---|---|
0 | BE | 2016-10-22 00:00:00 | 70.00 |
1 | BE | 2016-10-22 01:00:00 | 37.10 |
2 | BE | 2016-10-22 02:00:00 | 37.10 |
3 | BE | 2016-10-22 03:00:00 | 44.75 |
4 | BE | 2016-10-22 04:00:00 | 37.10 |
Preview of the first few rows of data
3. Initialize Ray
Here, we’re spinning up a Ray cluster locally by creating a head node. You can scale this to multiple machines in a real cluster environment.
Ray Initialization Logs
Ray Initialization Logs
Log Output
Log Output
4. Use TimeGPT on Ray
With Ray, you can run TimeGPT similar to a standard (non-distributed) local environment. Operations such as forecast
still apply directly to Ray Dataset objects.
Instantiating NixtlaClient
Instantiating NixtlaClient
Begin by creating a NixtlaClient
. Replace my_api_key_provided_by_nixtla with your own API key.
If you prefer using an Azure AI endpoint, specify the base_url
and api_key
for Azure.
Making a Forecast
Making a Forecast
Public API models supported include timegpt-1
(default) and timegpt-1-long-horizon
.
Inspect the forecast results by converting to a pandas DataFrame:
Cross-validation with TimeGPT
Cross-validation with TimeGPT
You can also perform cross-validation on Ray. The following sample code performs a cross-validation procedure using rolling windows:
After computation, convert cv_df
to pandas to view the results:
Exogenous Variables
Exogenous Variables
For adding extra predictors or exogenous variables, refer to the Exogenous Variables Tutorial. While running on Ray, simply use your ray_df
in place of a pandas DataFrame.
5. Shutdown Ray
Always shut down Ray after you finish your tasks to free up resources.
Congratulations! You’ve successfully used TimeGPT on Ray for distributed forecasting.