siriuz42 commited on
Commit
b59dab6
1 Parent(s): 5cf004e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +92 -11
README.md CHANGED
@@ -16,11 +16,27 @@ TimesFM (Time Series Foundation Model) is a pretrained time-series foundation mo
16
 
17
  This is not an officially supported Google product.
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  ## Installation
20
 
21
  This Hugging Face repo hosts TimesFm checkpoints. Please visit our [GitHub repo](https://github.com/google-research/timesfm) to install the `timesfm` library for model inference.
22
 
23
- We have two environment files. For GPU installation (assuming CUDA 12 has been setup), you can create a conda environment `tfm_env` from the base folder through:
 
 
24
 
25
  ```
26
  conda env create --file=environment.yml
@@ -43,6 +59,7 @@ to install the package.
43
 
44
  ## Usage
45
 
 
46
  Then the base class can be loaded as,
47
 
48
  ```python
@@ -56,21 +73,85 @@ tfm = timesfm.TimesFm(
56
  num_layers=20,
57
  model_dims=1280,
58
  backend=<backend>,
59
- per_core_batch_size=<batch_size>,
60
- quantiles=<quantiles>,
61
- )
62
- tfm.load_from_checkpoint(
63
- <checkpoint_path>,
64
- checkpoint_type=checkpoints.CheckpointType.FLAX,
65
  )
 
66
  ```
67
 
68
- 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.
 
 
 
 
 
 
 
 
 
69
 
70
  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.
71
 
72
- 3. We also provide an API to forecast from `pandas` dataframe. Please look at the documentation of the function `tfm.forecast_on_df()`.
73
 
74
- ## Benchmarks
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
- Please look into the README files in the respective benchmark directories within `experiments/` for instructions for running TimesFM on the respective benchmarks.
 
16
 
17
  This is not an officially supported Google product.
18
 
19
+ ## Checkpoint timesfm-1.0-200m
20
+
21
+ timesfm-1.0-200m is the first open model checkpoint:
22
+
23
+ - It performs univariate time series forecasting for context lengths up tp 512 timepoints and any horizon lengths, with an optional frequency indicator.
24
+ - It focuses on point forecasts, and does not support probabilistic forecasts. We experimentally offer quantile heads but they have not been calibrated after pretraining.
25
+ - It requires the context to be contiguous (i.e. no "holes"), and the context and the horizon to be of the same frequency.
26
+
27
+ ## Benchmarks
28
+
29
+ Please refer to our result tables on the [extended benchmarks](./experiments/extended_benchmarks/tfm_results.png) and the [long horizon benchmarks](./experiments/long_horizon_benchmarks/tfm_long_horizon.png).
30
+
31
+ Please look into the README files in the respective benchmark directories within `experiments/` for instructions for running TimesFM on the respective benchmarks.
32
+
33
  ## Installation
34
 
35
  This Hugging Face repo hosts TimesFm checkpoints. Please visit our [GitHub repo](https://github.com/google-research/timesfm) to install the `timesfm` library for model inference.
36
 
37
+ We have two environment files. For GPU installation (assuming CUDA 12 has been
38
+ setup), you can create a conda environment `tfm_env` from the base folder
39
+ through:
40
 
41
  ```
42
  conda env create --file=environment.yml
 
59
 
60
  ## Usage
61
 
62
+ ### Initialize the model and load a checkpoint.
63
  Then the base class can be loaded as,
64
 
65
  ```python
 
73
  num_layers=20,
74
  model_dims=1280,
75
  backend=<backend>,
 
 
 
 
 
 
76
  )
77
+ tfm.load_from_checkpoint(<checkpoint_path>)
78
  ```
79
 
80
+ Note that the four parameters are fixed to load the 200m model
81
+
82
+ ```python
83
+ input_patch_len=32,
84
+ output_patch_len=128,
85
+ num_layers=20,
86
+ model_dims=1280,
87
+ ```
88
+
89
+ 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. The input time series can have **any context length**. Padding / truncation will be handled by the inference code if needed.
90
 
91
  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.
92
 
93
+ ### Perform inference
94
 
95
+ We provide APIs to forecast from either array inputs or `pandas` dataframe. Both forecast methods expect (1) the input time series contexts, (2) along with their frequencies. Please look at the documentation of the functions `tfm.forecast()` and `tfm.forecast_on_df()` for detailed instructions.
96
+
97
+ In particular regarding the frequency, TimesFM expects a categorical indicator valued in {0, 1, 2}:
98
+
99
+ - **0** (default): high frequency, long horizon time series. We recommend to use this for time series up to daily granularity.
100
+ - **1**: medium frequency time series. We recommend to use this for weekly and monthly data.
101
+ - **2**: low frequency, short horizon time series. We recommend to use this for anything beyond monthly, e.g. quarterly or yearly.
102
+
103
+ This categorical value should be directly provided with the array inputs. For dataframe inputs, we convert the conventional letter coding of frequencies to our expected categories, that
104
+
105
+ - **0**: T, MIN, H, D, B, U
106
+ - **1**: W, M
107
+ - **2**: Q, Y
108
+
109
+ Notice you do **NOT** have to strictly follow our recommendation here. Although this is our setup during model training and we expect it to offer the best forecast result, you can also view the frequency input as a free parameter and modify it per your specific use case.
110
+
111
+
112
+ Examples:
113
+
114
+ Array inputs, with the frequencies set to low, medium and high respectively.
115
+
116
+ ```python
117
+ import numpy as np
118
+ forecast_input = [
119
+ np.sin(np.linspace(0, 20, 100))
120
+ np.sin(np.linspace(0, 20, 200)),
121
+ np.sin(np.linspace(0, 20, 400)),
122
+ ]
123
+ frequency_input = [0, 1, 2]
124
+
125
+ point_forecast, experimental_quantile_forecast = tfm.forecast(
126
+ forecast_input,
127
+ freq=frequency_input,
128
+ )
129
+ ```
130
+
131
+ `pandas` dataframe, with the frequency set to "M" monthly.
132
+
133
+ ```python
134
+ import pandas as pd
135
+
136
+ # e.g. input_df is
137
+ # unique_id ds y
138
+ # 0 T1 1975-12-31 697458.0
139
+ # 1 T1 1976-01-31 1187650.0
140
+ # 2 T1 1976-02-29 1069690.0
141
+ # 3 T1 1976-03-31 1078430.0
142
+ # 4 T1 1976-04-30 1059910.0
143
+ # ... ... ... ...
144
+ # 8175 T99 1986-01-31 602.0
145
+ # 8176 T99 1986-02-28 684.0
146
+ # 8177 T99 1986-03-31 818.0
147
+ # 8178 T99 1986-04-30 836.0
148
+ # 8179 T99 1986-05-31 878.0
149
+
150
+ forecast_df = tfm.forecast_on_df(
151
+ inputs=input_df,
152
+ freq="M", # monthly
153
+ value_name="y",
154
+ num_jobs=-1,
155
+ )
156
+ ```
157