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.
- Installation
- Load Your Data
- Initialize Ray
- Use TimeGPT on Ray
- Shutdown Ray
1
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.
Fugue Ray Installation
When executing on a distributed Ray cluster, ensure the
nixtla
library is installed on all workers.2
2. Load Your Data
Load your dataset into a pandas DataFrame. This tutorial uses hourly electricity prices from various markets:
Load Dataset Example
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
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 Cluster Initialization
Ray Initialization Logs
Ray Initialization Logs
Log Output
Log Output
Ray Initialization Logs
4
4. Use TimeGPT on Ray
With Ray, you can run TimeGPT similar to a standard (non-distributed) local environment. Operations such as
Inspect the forecast results by converting to a pandas DataFrame:
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.NixtlaClient Initialization
If you prefer using an Azure AI endpoint, specify the
base_url
and api_key
for Azure.NixtlaClient Azure Setup
Making a Forecast
Making a Forecast
TimeGPT Forecasting on Ray
Public API models supported include
timegpt-1
(default) and timegpt-1-long-horizon
.Inspect Forecast Results
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
TimeGPT Cross-validation on Ray
cv_df
to pandas to view the results:Inspect Cross-validation 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
5. Shutdown Ray
Always shut down Ray after you finish your tasks to free up resources.
Shutdown Ray Example
Congratulations! You’ve successfully used TimeGPT on Ray for distributed forecasting.