Time Series Forecasting
TimesFM
File size: 2,212 Bytes
cb20a34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
license: apache-2.0
---

# TimesFM (Time Series Foundation Model)

TimesFM is a pretrained time-series foundation model developed by Google
Research for time-series forecasting.

Paper link: https://arxiv.org/abs/2310.10688 (to appear in ICML 2024)

Blog post: https://research.google/blog/a-decoder-only-foundation-model-for-time-series-forecasting/

This repo contains the code to load public TimesFM checkpoints and run model
inference locally.

This is not an officially supported Google product.

## Installation

We have two environment files. For GPU installation (assuming CUDA 12 has been setup), you can create a conda environment from the base folder through:

```
conda env create --file=environment.yml
```

For a CPU setup please use,

```
conda env create --file=environment_cpu.yml
```
followed by

```
conda activate tfm_env
pip install -e .
```
to install the package.

## Usage 

Then the base class can be loaded as,

```python
import timesfm

tfm = timesfm.TimesFm(
      context_len=<context>,
      horizon_len=<horizon>,
      input_patch_len=32,
      output_patch_len=128,
      num_layers=20,
      model_dims=1280,
      backend=<backend>,
      per_core_batch_size=<batch_size>,
      quantiles=<quantiles>,
  )
  tfm.load_from_checkpoint(
      <checkpoint_path>,
      checkpoint_type=checkpoints.CheckpointType.FLAX,
  )
```

1. The context_len here can be set as the max context length of the model. You can provide shorter series to the `tfm.forecast()` function and the model will handle it. Currently the model handles a max context length of 512, which can be increased in later releases.

2. The horizon length can be set to anything. We recommend setting it to the largest horizon length you would need in the forecasting tasks for your application. We generally recommend horizon length <= context length but it is not a requirement in the function call.

3. We also provide an API to forecast from pandas dataframe. Please look at the documentation of the function `tfm.forecast_on_df()`.

## Benchmarks

Please look into the README files in the respective benchmark directories within `experiments/` for instructions for running TimesFM on the respective benchmarks.