Ray
Run TimeGPT distributedly on top of Ray
Ray is an open source unified compute framework
to scale Python workloads. In this guide, we will explain how to use
TimeGPT
on top of Ray.
Outline:
1. Installation
Install Ray through Fugue. Fugue provides an easy-to-use interface for distributed computing that lets users execute Python code on top of several distributed computing frameworks, including Ray.
If executing on a distributed Ray
cluster, ensure that the nixtla
library is installed across all the workers.
2. Load Data
You can load your data as a pandas
DataFrame. In this tutorial, we
will use a dataset that contains hourly electricity prices from
different 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 |
3. Initialize Ray
Initialize Ray
and convert the pandas DataFrame to a Ray
DataFrame.
Python version: | 3.10.14 |
Ray version: | 2.6.2 |
4. Use TimeGPT on Ray
Using TimeGPT
on top of Ray
is almost identical to the
non-distributed case. The only difference is that you need to use a
Ray
DataFrame.
First, instantiate the NixtlaClient
class.
Then use any method from the NixtlaClient
class such as
forecast
or
cross_validation
.
To visualize the result, use the to_pandas
method to convert the
output of Ray
to a pandas
DataFrame.
unique_id | ds | TimeGPT | |
---|---|---|---|
55 | NP | 2018-12-24 07:00:00 | 53.784847 |
56 | NP | 2018-12-24 08:00:00 | 54.437321 |
57 | NP | 2018-12-24 09:00:00 | 54.66077 |
58 | NP | 2018-12-24 10:00:00 | 54.744473 |
59 | NP | 2018-12-24 11:00:00 | 54.737762 |
unique_id | ds | cutoff | TimeGPT | |
---|---|---|---|---|
295 | NP | 2018-12-23 19:00:00 | 2018-12-23 11:00:00 | 53.441555 |
296 | NP | 2018-12-23 20:00:00 | 2018-12-23 11:00:00 | 52.649628 |
297 | NP | 2018-12-23 21:00:00 | 2018-12-23 11:00:00 | 51.753975 |
298 | NP | 2018-12-23 22:00:00 | 2018-12-23 11:00:00 | 50.681946 |
299 | NP | 2018-12-23 23:00:00 | 2018-12-23 11:00:00 | 49.716431 |
You can also use exogenous variables with TimeGPT
on top of Ray
. To
do this, please refer to the Exogenous
Variables
tutorial. Just keep in mind that instead of using a pandas DataFrame,
you need to use a Ray
DataFrame instead.
5. Shutdown Ray
When you are done, shutdown the Ray
session.