timesfm 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
timesfm-1.0.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
timesfm-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.1
2
+ Name: timesfm
3
+ Version: 1.0.0
4
+ Summary: Open weights time-series foundation model from Google Research.
5
+ Author-email: Rajat Sen <senrajat@google.com>, Yichen Zhou <yichenzhou@google.com>, Abhimanyu Das <abhidas@google.com>, Petros Mol <pmol@google.com>
6
+ License-File: LICENSE
7
+ Requires-Dist: jax==0.4.26
8
+ Requires-Dist: paxml==1.4.0
9
+ Requires-Dist: praxis==1.4.0
10
+ Requires-Dist: jaxlib==0.4.26
11
+ Requires-Dist: numpy==1.26.4
12
+ Requires-Dist: pandas==2.1.4
13
+ Requires-Dist: einshape==1.0.0
14
+ Requires-Dist: utilsforecast==0.1.10
15
+ Requires-Dist: huggingface_hub[cli]==0.23.0
16
+ Requires-Dist: scikit-learn==1.5.1
@@ -0,0 +1,182 @@
1
+ # TimesFM
2
+
3
+ TimesFM (Time Series Foundation Model) is a pretrained time-series foundation model developed by Google
4
+ Research for time-series forecasting.
5
+
6
+ * Paper: [A decoder-only foundation model for time-series forecasting](https://arxiv.org/abs/2310.10688), to appear in ICML 2024.
7
+ * [Google Research blog](https://research.google/blog/a-decoder-only-foundation-model-for-time-series-forecasting/)
8
+ * [Hugging Face checkpoint repo](https://huggingface.co/google/timesfm-1.0-200m)
9
+
10
+ This repo contains the code to load public TimesFM checkpoints and run model
11
+ inference. Please visit our
12
+ [Hugging Face checkpoint repo](https://huggingface.co/google/timesfm-1.0-200m)
13
+ to download model checkpoints.
14
+
15
+ This is not an officially supported Google product.
16
+
17
+ ## Checkpoint timesfm-1.0-200m
18
+
19
+ timesfm-1.0-200m is the first open model checkpoint:
20
+
21
+ - It performs univariate time series forecasting for context lengths up to 512 timepoints and any horizon lengths, with an optional frequency indicator.
22
+ - It focuses on point forecasts, and does not support probabilistic forecasts. We experimentally offer quantile heads but they have not been calibrated after pretraining.
23
+ - It requires the context to be contiguous (i.e. no "holes"), and the context and the horizon to be of the same frequency.
24
+
25
+ ## Benchmarks
26
+
27
+ Please refer to our result tables on the [extended benchmarks](https://github.com/google-research/timesfm/tree/master/experiments/extended_benchmarks) and the [long horizon benchmarks](https://github.com/google-research/timesfm/tree/master/experiments/long_horizon_benchmarks).
28
+
29
+ Please look into the README files in the respective benchmark directories within `experiments/` for instructions for running TimesFM on the respective benchmarks.
30
+
31
+ ## Installation
32
+
33
+ We recommend at least 16GB RAM to load TimesFM dependencies.
34
+
35
+ For calling TimesFM, We have two environment files. Inside `timesfm`, for
36
+ GPU installation (assuming CUDA 12 has been setup), you can create a conda
37
+ environment `tfm_env` from the base folder through:
38
+
39
+ ```
40
+ conda env create --file=environment.yml
41
+ ```
42
+
43
+ For a CPU setup please use,
44
+
45
+ ```
46
+ conda env create --file=environment_cpu.yml
47
+ ```
48
+ to create the environment instead.
49
+
50
+ Follow by
51
+
52
+ ```
53
+ conda activate tfm_env
54
+ pip install -e .
55
+ ```
56
+ to install the package.
57
+
58
+ **Note**:
59
+
60
+ 1. Running the provided benchmarks would require additional dependencies.
61
+ Please use the environment files under `experiments` instead.
62
+
63
+ 2. The dependency `lingvo` does not support ARM architectures, and the code is not working for machines with Apple silicon. We are aware of this issue and are working on a solution. Stay tuned.
64
+
65
+ ## Usage
66
+
67
+ ### Initialize the model and load a checkpoint.
68
+ Then the base class can be loaded as,
69
+
70
+ ```python
71
+ import timesfm
72
+
73
+ tfm = timesfm.TimesFm(
74
+ context_len=<context>,
75
+ horizon_len=<horizon>,
76
+ input_patch_len=32,
77
+ output_patch_len=128,
78
+ num_layers=20,
79
+ model_dims=1280,
80
+ backend=<backend>,
81
+ )
82
+ tfm.load_from_checkpoint(repo_id="google/timesfm-1.0-200m")
83
+ ```
84
+
85
+ Note that the four parameters are fixed to load the 200m model
86
+
87
+ ```python
88
+ input_patch_len=32,
89
+ output_patch_len=128,
90
+ num_layers=20,
91
+ model_dims=1280,
92
+ ```
93
+
94
+ 1. The `context_len` here can be set as the max context length **of the model**. **It needs to be a multiplier of `input_patch_len`, i.e. a multiplier of 32.** You can provide a 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.
95
+
96
+ 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.
97
+
98
+ 3. `backend` is one of "cpu", "gpu" or "tpu", case sensitive.
99
+
100
+ ### Perform inference
101
+
102
+ 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.
103
+
104
+ In particular regarding the frequency, TimesFM expects a categorical indicator valued in {0, 1, 2}:
105
+
106
+ - **0** (default): high frequency, long horizon time series. We recommend using this for time series up to daily granularity.
107
+ - **1**: medium frequency time series. We recommend using this for weekly and monthly data.
108
+ - **2**: low frequency, short horizon time series. We recommend using this for anything beyond monthly, e.g. quarterly or yearly.
109
+
110
+ 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
111
+
112
+ - **0**: T, MIN, H, D, B, U
113
+ - **1**: W, M
114
+ - **2**: Q, Y
115
+
116
+ 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.
117
+
118
+
119
+ Examples:
120
+
121
+ Array inputs, with the frequencies set to low, medium and high respectively.
122
+
123
+ ```python
124
+ import numpy as np
125
+ forecast_input = [
126
+ np.sin(np.linspace(0, 20, 100)),
127
+ np.sin(np.linspace(0, 20, 200)),
128
+ np.sin(np.linspace(0, 20, 400)),
129
+ ]
130
+ frequency_input = [0, 1, 2]
131
+
132
+ point_forecast, experimental_quantile_forecast = tfm.forecast(
133
+ forecast_input,
134
+ freq=frequency_input,
135
+ )
136
+ ```
137
+
138
+ `pandas` dataframe, with the frequency set to "M" monthly.
139
+
140
+ ```python
141
+ import pandas as pd
142
+
143
+ # e.g. input_df is
144
+ # unique_id ds y
145
+ # 0 T1 1975-12-31 697458.0
146
+ # 1 T1 1976-01-31 1187650.0
147
+ # 2 T1 1976-02-29 1069690.0
148
+ # 3 T1 1976-03-31 1078430.0
149
+ # 4 T1 1976-04-30 1059910.0
150
+ # ... ... ... ...
151
+ # 8175 T99 1986-01-31 602.0
152
+ # 8176 T99 1986-02-28 684.0
153
+ # 8177 T99 1986-03-31 818.0
154
+ # 8178 T99 1986-04-30 836.0
155
+ # 8179 T99 1986-05-31 878.0
156
+
157
+ forecast_df = tfm.forecast_on_df(
158
+ inputs=input_df,
159
+ freq="M", # monthly
160
+ value_name="y",
161
+ num_jobs=-1,
162
+ )
163
+ ```
164
+
165
+ ## Finetuning
166
+
167
+ We have provided an example of finetuning the model on a new dataset in `notebooks/finetuning.ipynb`.
168
+
169
+ ## Contribution Style guide
170
+
171
+ If you would like to submit a PR please make sure that you use our formatting style. We use [yapf](https://github.com/google/yapf) for formatting with the following options,
172
+
173
+ ```
174
+ [style]
175
+ based_on_style = google
176
+ # Add your custom style rules here
177
+ indent_width = 2
178
+ spaces_before_comment = 2
179
+
180
+ ```
181
+
182
+ Please run `yapf --in-place --recursive <filename>` on all affected files.
@@ -0,0 +1,29 @@
1
+ # This project can be installed with `python3 -m pip install -e .` from the main directory.
2
+
3
+ [project]
4
+ name = "timesfm"
5
+ description = "Open weights time-series foundation model from Google Research."
6
+ version = "1.0.0"
7
+ dependencies = [
8
+ "jax==0.4.26",
9
+ "paxml==1.4.0",
10
+ "praxis==1.4.0",
11
+ "jaxlib==0.4.26",
12
+ "numpy==1.26.4",
13
+ "pandas==2.1.4",
14
+ "einshape==1.0.0",
15
+ "utilsforecast==0.1.10",
16
+ "huggingface_hub[cli]==0.23.0",
17
+ "scikit-learn==1.5.1",
18
+ ]
19
+ authors = [
20
+ {name = "Rajat Sen", email = "senrajat@google.com"},
21
+ {name = "Yichen Zhou", email = "yichenzhou@google.com"},
22
+ {name = "Abhimanyu Das", email = "abhidas@google.com"},
23
+ {name = "Petros Mol", email = "pmol@google.com"},
24
+ ]
25
+
26
+
27
+ [build-system]
28
+ requires = ["setuptools"]
29
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,17 @@
1
+ # Copyright 2024 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """TimesFM init file."""
16
+
17
+ from .timesfm import TimesFm, freq_map