Name | uni2ts JSON |
Version |
1.2.0
JSON |
| download |
home_page | None |
Summary | Unified Training of Universal Time Series Forecasting Transformers |
upload_time | 2024-12-04 02:43:13 |
maintainer | None |
docs_url | None |
author | Akshat Kumar, Caiming Xiong, Silvio Savarese, Doyen Sahoo |
requires_python | >=3.10 |
license | Apache License Version 2.0 Copyright (c) 2023 Salesforce, Inc. All rights reserved. Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. |
keywords |
deep learning
pytorch
time series forecasting
transformer
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<div align="center">
# Unified Training of Universal Time Series Transformers
[![arXiv](https://img.shields.io/badge/Moirai-2402.02592-b31b1b.svg)](https://arxiv.org/abs/2402.02592)
[![arXiv](https://img.shields.io/badge/MoiraiMoE-2410.10469-b31b1b.svg)](https://arxiv.org/abs/2410.10469)
[![huggingface](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Models-FFD21E)](https://huggingface.co/collections/Salesforce/moirai-r-models-65c8d3a94c51428c300e0742)
[![huggingface](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Leaderboard-FFD21E)](https://huggingface.co/spaces/Salesforce/GIFT-Eval)
[![License: MIT](https://img.shields.io/badge/License-Apache--2.0-green.svg)](https://opensource.org/licenses/Apache-2.0)
</div>
Uni2TS is a PyTorch based library for research and applications related to Time Series Forecasting. It provides a unified framework for large-scale pre-training, fine-tuning, inference, and evaluation of Universal Time Series Transformers.
Related reading: [Moirai Paper](https://arxiv.org/abs/2402.02592), [Moirai Salesforce Blog](https://blog.salesforceairesearch.com/moirai/), [Moirai-MoE Paper](https://arxiv.org/abs/2410.10469), [Moirai-MoE Salesforce Blog](https://www.salesforce.com/blog/time-series-morai-moe/), [Moirai-MoE AI Horizon Forecast Blog](https://aihorizonforecast.substack.com/p/moirai-moe-upgrading-moirai-with), [Moirai-MoE Jiqizhixin Blog](https://mp.weixin.qq.com/s/LQvlgxx9vU965Yzy6RuBfQ).
## 🎉 What's New
* Nov 2024: The first general time series forecasting benchmark [GIFT-Eval](https://github.com/SalesforceAIResearch/gift-eval) is released. [Leaderboard](https://huggingface.co/spaces/Salesforce/GIFT-Eval) is available and please try your model on it!
* Oct 2024: A new model Moirai-MoE! The preprint is available on [arXiv](https://arxiv.org/abs/2410.10469), along with the model weights of [Moirai-MoE-Small](https://huggingface.co/Salesforce/moirai-moe-1.0-R-small) and [Moirai-MoE-Base](https://huggingface.co/Salesforce/moirai-moe-1.0-R-base). Getting started with [inference code](https://github.com/SalesforceAIResearch/uni2ts/tree/main/project/moirai-moe-1) and [notebook examples](https://github.com/SalesforceAIResearch/uni2ts/tree/main/example)!
* Sep 2024: Released [Evaluation Code](https://github.com/SalesforceAIResearch/uni2ts/tree/main/project/benchmarks) of [TimesFM](https://arxiv.org/abs/2310.10688), [Chronos](https://arxiv.org/abs/2403.07815) and [VisionTS](https://arxiv.org/abs/2408.17253) on Monash, LSF and PF benchmarks.
* Jun 2024: Released Moirai-1.1-R model weights in [small](https://huggingface.co/Salesforce/moirai-1.1-R-small), [base](https://huggingface.co/Salesforce/moirai-1.1-R-base), and [large](https://huggingface.co/Salesforce/moirai-1.1-R-large).
* May 2024: The [Moirai Paper](https://arxiv.org/abs/2402.02592) has been accepted to ICML 2024 as an Oral presentation!
* Mar 2024: Release of Uni2TS library, along with [Moirai Paper](https://arxiv.org/abs/2402.02592), [Moirai-1.0-R Models](https://huggingface.co/collections/Salesforce/moirai-10-r-models-65c8d3a94c51428c300e0742), and [LOTSA Data](https://huggingface.co/datasets/Salesforce/lotsa_data/).
## ⚙️ Installation
1. Clone repository:
```shell
git clone https://github.com/SalesforceAIResearch/uni2ts.git
cd uni2ts
```
2) Create virtual environment:
```shell
virtualenv venv
. venv/bin/activate
```
3) Build from source:
```shell
pip install -e '.[notebook]'
```
4) Create a `.env` file:
```shell
touch .env
```
We also support installation via PyPI.
```shell
pip install uni2ts
```
## 🏃 Getting Started
Let's see a simple example on how to use Uni2TS to make zero-shot forecasts from a pre-trained model.
We first load our data using pandas, in the form of a wide DataFrame.
Uni2TS relies on GluonTS for inference as it provides many convenience functions for time series forecasting, such as splitting a dataset into a train/test split and performing rolling evaluations, as demonstrated below.
```python
import torch
import matplotlib.pyplot as plt
import pandas as pd
from gluonts.dataset.pandas import PandasDataset
from gluonts.dataset.split import split
from huggingface_hub import hf_hub_download
from uni2ts.eval_util.plot import plot_single
from uni2ts.model.moirai import MoiraiForecast, MoiraiModule
from uni2ts.model.moirai_moe import MoiraiMoEForecast, MoiraiMoEModule
MODEL = "moirai-moe" # model name: choose from {'moirai', 'moirai-moe'}
SIZE = "small" # model size: choose from {'small', 'base', 'large'}
PDT = 20 # prediction length: any positive integer
CTX = 200 # context length: any positive integer
PSZ = "auto" # patch size: choose from {"auto", 8, 16, 32, 64, 128}
BSZ = 32 # batch size: any positive integer
TEST = 100 # test set length: any positive integer
# Read data into pandas DataFrame
url = (
"https://gist.githubusercontent.com/rsnirwan/c8c8654a98350fadd229b00167174ec4"
"/raw/a42101c7786d4bc7695228a0f2c8cea41340e18f/ts_wide.csv"
)
df = pd.read_csv(url, index_col=0, parse_dates=True)
# Convert into GluonTS dataset
ds = PandasDataset(dict(df))
# Split into train/test set
train, test_template = split(
ds, offset=-TEST
) # assign last TEST time steps as test set
# Construct rolling window evaluation
test_data = test_template.generate_instances(
prediction_length=PDT, # number of time steps for each prediction
windows=TEST // PDT, # number of windows in rolling window evaluation
distance=PDT, # number of time steps between each window - distance=PDT for non-overlapping windows
)
# Prepare pre-trained model by downloading model weights from huggingface hub
if MODEL == "moirai":
model = MoiraiForecast(
module=MoiraiModule.from_pretrained(f"Salesforce/moirai-1.1-R-{SIZE}"),
prediction_length=PDT,
context_length=CTX,
patch_size=PSZ,
num_samples=100,
target_dim=1,
feat_dynamic_real_dim=ds.num_feat_dynamic_real,
past_feat_dynamic_real_dim=ds.num_past_feat_dynamic_real,
)
elif MODEL == "moirai-moe":
model = MoiraiMoEForecast(
module=MoiraiMoEModule.from_pretrained(f"Salesforce/moirai-moe-1.0-R-{SIZE}"),
prediction_length=PDT,
context_length=CTX,
patch_size=16,
num_samples=100,
target_dim=1,
feat_dynamic_real_dim=ds.num_feat_dynamic_real,
past_feat_dynamic_real_dim=ds.num_past_feat_dynamic_real,
)
predictor = model.create_predictor(batch_size=BSZ)
forecasts = predictor.predict(test_data.input)
input_it = iter(test_data.input)
label_it = iter(test_data.label)
forecast_it = iter(forecasts)
inp = next(input_it)
label = next(label_it)
forecast = next(forecast_it)
plot_single(
inp,
label,
forecast,
context_length=200,
name="pred",
show_label=True,
)
plt.show()
```
## 📔 Jupyter Notebook Examples
See the [example folder](example) for more examples on common tasks, e.g. visualizing forecasts, predicting from pandas DataFrame, etc.
## 💻 Command Line Interface
We provide several scripts which act as a [command line interface](cli) to easily run fine-tuning, evaluation, and even pre-training jobs.
[Configurations](cli/conf) are managed with the [Hydra](https://hydra.cc/) framework.
### Fine-tuning
Firstly, let's see how to use Uni2TS to fine-tune a pre-trained model on your custom dataset.
Uni2TS uses the [Hugging Face datasets library](https://github.com/huggingface/datasets) to handle data loading, and we first need to convert your dataset into the Uni2TS format.
If your dataset is a simple pandas DataFrame, we can easily process your dataset with the following script.
We'll use the ETTh1 dataset from the popular [Long Sequence Forecasting benchmark](https://github.com/thuml/Time-Series-Library) for this example.
For more complex use cases, see [this notebook](example/prepare_data.ipynb) for more in-depth examples on how to use your custom dataset with Uni2TS.
1. To begin the process, add the path to the directory where you want to save the processed dataset into the ```.env``` file.
```shell
echo "CUSTOM_DATA_PATH=PATH_TO_SAVE" >> .env
```
2. Run the following script to process the dataset into the required format. For the ```dataset_type``` option, we support `wide`, `long` and `wide_multivariate`.
```shell
python -m uni2ts.data.builder.simple ETTh1 dataset/ETT-small/ETTh1.csv --dataset_type wide
```
However, we may want validation set during fine-tuning to perform hyperparameter tuning or early stopping.
To additionally split the dataset into a train and validation split we can use the mutually exclusive ```date_offset``` (datetime string) or ```offset``` (integer) options which determines the last time step of the train set.
The validation set will be saved as DATASET_NAME_eval.
```shell
python -m uni2ts.data.builder.simple ETTh1 dataset/ETT-small/ETTh1.csv --date_offset '2017-10-23 23:00:00'
```
3. Finally, we can simply run the fine-tuning script with the appropriate [training](cli/conf/finetune/data/etth1.yaml) and [validation](cli/conf/finetune/val_data/etth1.yaml) data configuration files.
```shell
python -m cli.train \
-cp conf/finetune \
run_name=example_run \
model=moirai_1.0_R_small \
data=etth1 \
val_data=etth1
```
### Evaluation
The evaluation script can be used to calculate evaluation metrics such as MSE, MASE, CRPS, and so on (see the [configuration file](cli/conf/eval/default.yaml)).
Given a test split (see previous section on processing datasets), we can run the following command to evaluate it:
```shell
python -m cli.eval \
run_name=example_eval_1 \
model=moirai_1.0_R_small \
model.patch_size=32 \
model.context_length=1000 \
data=etth1_test
```
Alternatively, we provide access to popular datasets, and can be toggled via the [data configurations](cli/conf/eval/data).
As an example, say we want to perform evaluation, again on the ETTh1 dataset from the popular [Long Sequence Forecasting benchmark](https://github.com/thuml/Time-Series-Library).
We first need to download the pre-processed datasets and put them in the correct directory, by setting up the TSLib repository and following the instructions.
Then, assign the dataset directory to the `LSF_PATH` environment variable:
```shell
echo "LSF_PATH=PATH_TO_TSLIB/dataset" >> .env
```
Thereafter, simply run the following script with the predefined [Hydra config file](cli/conf/eval/data/lsf_test.yaml):
```shell
python -m cli.eval \
run_name=example_eval_2 \
model=moirai_1.0_R_small \
model.patch_size=32 \
model.context_length=1000 \
data=lsf_test \
data.dataset_name=ETTh1 \
data.prediction_length=96
```
### Pre-training
Now, let's see how you can pre-train your own model.
We'll start with preparing the data for pre-training first, by downloading the [Large-scale Open Time Series Archive (LOTSA data)](https://huggingface.co/datasets/Salesforce/lotsa_data/).
Assuming you've already createed a `.env` file, run the following commands.
```shell
huggingface-cli download Salesforce/lotsa_data --repo-type=dataset --local-dir PATH_TO_SAVE
echo "LOTSA_V1_PATH=PATH_TO_SAVE" >> .env
```
Then, we can simply run the following script to start a pre-training job.
See the [relevant](cli/train.py) [files](cli/conf/pretrain) on how to further customize the settings.
```shell
python -m cli.train \
-cp conf/pretrain \
run_name=first_run \
model=moirai_small \
data=lotsa_v1_unweighted
```
## 👀 Citation
If you're using this repository in your research or applications, please cite using the following BibTeX:
```markdown
@article{liu2024moiraimoe,
title={Moirai-MoE: Empowering Time Series Foundation Models with Sparse Mixture of Experts},
author={Liu, Xu and Liu, Juncheng and Woo, Gerald and Aksu, Taha and Liang, Yuxuan and Zimmermann, Roger and Liu, Chenghao and Savarese, Silvio and Xiong, Caiming and Sahoo, Doyen},
journal={arXiv preprint arXiv:2410.10469},
year={2024}
}
@article{aksu2024gifteval,
title={GIFT-Eval: A Benchmark For General Time Series Forecasting Model Evaluation},
author={Aksu, Taha and Woo, Gerald and Liu, Juncheng and Liu, Xu and Liu, Chenghao and Savarese, Silvio and Xiong, Caiming and Sahoo, Doyen},
journal={arXiv preprint arXiv:2410.10393},
year={2024}
}
@inproceedings{woo2024moirai,
title={Unified Training of Universal Time Series Forecasting Transformers},
author={Woo, Gerald and Liu, Chenghao and Kumar, Akshat and Xiong, Caiming and Savarese, Silvio and Sahoo, Doyen},
booktitle={Forty-first International Conference on Machine Learning},
year={2024}
}
```
Raw data
{
"_id": null,
"home_page": null,
"name": "uni2ts",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": "Gerald Woo <gwoo@salesforce.com>, Juncheng Liu <juncheng.liu@salesforce.com>",
"keywords": "Deep Learning, PyTorch, Time Series Forecasting, Transformer",
"author": "Akshat Kumar, Caiming Xiong, Silvio Savarese, Doyen Sahoo",
"author_email": "Gerald Woo <gwoo@salesforce.com>, Chenghao Liu <chenghao.liu@salesforce.com>, Juncheng Liu <juncheng.liu@salesforce.com>, Taha Aksu <iaksu@salesforce.com>, Xu Liu <xu.liu@salesforce.com>",
"download_url": "https://files.pythonhosted.org/packages/90/16/cceb7667719e3cd47fefdafd6c3e306eeb6436c48bc412d65ccc343f3046/uni2ts-1.2.0.tar.gz",
"platform": null,
"description": "<div align=\"center\">\n\n# Unified Training of Universal Time Series Transformers\n\n[![arXiv](https://img.shields.io/badge/Moirai-2402.02592-b31b1b.svg)](https://arxiv.org/abs/2402.02592)\n[![arXiv](https://img.shields.io/badge/MoiraiMoE-2410.10469-b31b1b.svg)](https://arxiv.org/abs/2410.10469)\n[![huggingface](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Models-FFD21E)](https://huggingface.co/collections/Salesforce/moirai-r-models-65c8d3a94c51428c300e0742)\n[![huggingface](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Leaderboard-FFD21E)](https://huggingface.co/spaces/Salesforce/GIFT-Eval)\n[![License: MIT](https://img.shields.io/badge/License-Apache--2.0-green.svg)](https://opensource.org/licenses/Apache-2.0)\n\n</div>\n\nUni2TS is a PyTorch based library for research and applications related to Time Series Forecasting. It provides a unified framework for large-scale pre-training, fine-tuning, inference, and evaluation of Universal Time Series Transformers.\n\nRelated reading: [Moirai Paper](https://arxiv.org/abs/2402.02592), [Moirai Salesforce Blog](https://blog.salesforceairesearch.com/moirai/), [Moirai-MoE Paper](https://arxiv.org/abs/2410.10469), [Moirai-MoE Salesforce Blog](https://www.salesforce.com/blog/time-series-morai-moe/), [Moirai-MoE AI Horizon Forecast Blog](https://aihorizonforecast.substack.com/p/moirai-moe-upgrading-moirai-with), [Moirai-MoE Jiqizhixin Blog](https://mp.weixin.qq.com/s/LQvlgxx9vU965Yzy6RuBfQ).\n## \ud83c\udf89 What's New\n\n* Nov 2024: The first general time series forecasting benchmark [GIFT-Eval](https://github.com/SalesforceAIResearch/gift-eval) is released. [Leaderboard](https://huggingface.co/spaces/Salesforce/GIFT-Eval) is available and please try your model on it!\n\n* Oct 2024: A new model Moirai-MoE! The preprint is available on [arXiv](https://arxiv.org/abs/2410.10469), along with the model weights of [Moirai-MoE-Small](https://huggingface.co/Salesforce/moirai-moe-1.0-R-small) and [Moirai-MoE-Base](https://huggingface.co/Salesforce/moirai-moe-1.0-R-base). Getting started with [inference code](https://github.com/SalesforceAIResearch/uni2ts/tree/main/project/moirai-moe-1) and [notebook examples](https://github.com/SalesforceAIResearch/uni2ts/tree/main/example)!\n\n* Sep 2024: Released [Evaluation Code](https://github.com/SalesforceAIResearch/uni2ts/tree/main/project/benchmarks) of [TimesFM](https://arxiv.org/abs/2310.10688), [Chronos](https://arxiv.org/abs/2403.07815) and [VisionTS](https://arxiv.org/abs/2408.17253) on Monash, LSF and PF benchmarks.\n\n* Jun 2024: Released Moirai-1.1-R model weights in [small](https://huggingface.co/Salesforce/moirai-1.1-R-small), [base](https://huggingface.co/Salesforce/moirai-1.1-R-base), and [large](https://huggingface.co/Salesforce/moirai-1.1-R-large).\n\n* May 2024: The [Moirai Paper](https://arxiv.org/abs/2402.02592) has been accepted to ICML 2024 as an Oral presentation!\n\n* Mar 2024: Release of Uni2TS library, along with [Moirai Paper](https://arxiv.org/abs/2402.02592), [Moirai-1.0-R Models](https://huggingface.co/collections/Salesforce/moirai-10-r-models-65c8d3a94c51428c300e0742), and [LOTSA Data](https://huggingface.co/datasets/Salesforce/lotsa_data/).\n\n## \u2699\ufe0f Installation\n\n1. Clone repository:\n```shell\ngit clone https://github.com/SalesforceAIResearch/uni2ts.git\ncd uni2ts\n```\n\n2) Create virtual environment:\n```shell\nvirtualenv venv\n. venv/bin/activate\n```\n\n3) Build from source:\n```shell\npip install -e '.[notebook]'\n```\n\n4) Create a `.env` file:\n```shell\ntouch .env\n```\n\nWe also support installation via PyPI.\n```shell\npip install uni2ts\n```\n\n## \ud83c\udfc3 Getting Started\n\nLet's see a simple example on how to use Uni2TS to make zero-shot forecasts from a pre-trained model. \nWe first load our data using pandas, in the form of a wide DataFrame. \nUni2TS relies on GluonTS for inference as it provides many convenience functions for time series forecasting, such as splitting a dataset into a train/test split and performing rolling evaluations, as demonstrated below.\n\n```python\nimport torch\nimport matplotlib.pyplot as plt\nimport pandas as pd\nfrom gluonts.dataset.pandas import PandasDataset\nfrom gluonts.dataset.split import split\nfrom huggingface_hub import hf_hub_download\n\nfrom uni2ts.eval_util.plot import plot_single\nfrom uni2ts.model.moirai import MoiraiForecast, MoiraiModule\nfrom uni2ts.model.moirai_moe import MoiraiMoEForecast, MoiraiMoEModule\n\nMODEL = \"moirai-moe\" # model name: choose from {'moirai', 'moirai-moe'}\nSIZE = \"small\" # model size: choose from {'small', 'base', 'large'}\nPDT = 20 # prediction length: any positive integer\nCTX = 200 # context length: any positive integer\nPSZ = \"auto\" # patch size: choose from {\"auto\", 8, 16, 32, 64, 128}\nBSZ = 32 # batch size: any positive integer\nTEST = 100 # test set length: any positive integer\n\n# Read data into pandas DataFrame\nurl = (\n \"https://gist.githubusercontent.com/rsnirwan/c8c8654a98350fadd229b00167174ec4\"\n \"/raw/a42101c7786d4bc7695228a0f2c8cea41340e18f/ts_wide.csv\"\n)\ndf = pd.read_csv(url, index_col=0, parse_dates=True)\n\n# Convert into GluonTS dataset\nds = PandasDataset(dict(df))\n\n# Split into train/test set\ntrain, test_template = split(\n ds, offset=-TEST\n) # assign last TEST time steps as test set\n\n# Construct rolling window evaluation\ntest_data = test_template.generate_instances(\n prediction_length=PDT, # number of time steps for each prediction\n windows=TEST // PDT, # number of windows in rolling window evaluation\n distance=PDT, # number of time steps between each window - distance=PDT for non-overlapping windows\n)\n\n# Prepare pre-trained model by downloading model weights from huggingface hub\nif MODEL == \"moirai\":\n model = MoiraiForecast(\n module=MoiraiModule.from_pretrained(f\"Salesforce/moirai-1.1-R-{SIZE}\"),\n prediction_length=PDT,\n context_length=CTX,\n patch_size=PSZ,\n num_samples=100,\n target_dim=1,\n feat_dynamic_real_dim=ds.num_feat_dynamic_real,\n past_feat_dynamic_real_dim=ds.num_past_feat_dynamic_real,\n )\nelif MODEL == \"moirai-moe\":\n model = MoiraiMoEForecast(\n module=MoiraiMoEModule.from_pretrained(f\"Salesforce/moirai-moe-1.0-R-{SIZE}\"),\n prediction_length=PDT,\n context_length=CTX,\n patch_size=16,\n num_samples=100,\n target_dim=1,\n feat_dynamic_real_dim=ds.num_feat_dynamic_real,\n past_feat_dynamic_real_dim=ds.num_past_feat_dynamic_real,\n )\n\npredictor = model.create_predictor(batch_size=BSZ)\nforecasts = predictor.predict(test_data.input)\n\ninput_it = iter(test_data.input)\nlabel_it = iter(test_data.label)\nforecast_it = iter(forecasts)\n\ninp = next(input_it)\nlabel = next(label_it)\nforecast = next(forecast_it)\n\nplot_single(\n inp, \n label, \n forecast, \n context_length=200,\n name=\"pred\",\n show_label=True,\n)\nplt.show()\n```\n\n## \ud83d\udcd4 Jupyter Notebook Examples\nSee the [example folder](example) for more examples on common tasks, e.g. visualizing forecasts, predicting from pandas DataFrame, etc.\n\n## \ud83d\udcbb Command Line Interface\nWe provide several scripts which act as a [command line interface](cli) to easily run fine-tuning, evaluation, and even pre-training jobs. \n[Configurations](cli/conf) are managed with the [Hydra](https://hydra.cc/) framework.\n\n### Fine-tuning\nFirstly, let's see how to use Uni2TS to fine-tune a pre-trained model on your custom dataset. \nUni2TS uses the [Hugging Face datasets library](https://github.com/huggingface/datasets) to handle data loading, and we first need to convert your dataset into the Uni2TS format. \nIf your dataset is a simple pandas DataFrame, we can easily process your dataset with the following script.\nWe'll use the ETTh1 dataset from the popular [Long Sequence Forecasting benchmark](https://github.com/thuml/Time-Series-Library) for this example.\nFor more complex use cases, see [this notebook](example/prepare_data.ipynb) for more in-depth examples on how to use your custom dataset with Uni2TS.\n\n1. To begin the process, add the path to the directory where you want to save the processed dataset into the ```.env``` file.\n```shell\necho \"CUSTOM_DATA_PATH=PATH_TO_SAVE\" >> .env\n```\n\n2. Run the following script to process the dataset into the required format. For the ```dataset_type``` option, we support `wide`, `long` and `wide_multivariate`.\n```shell\npython -m uni2ts.data.builder.simple ETTh1 dataset/ETT-small/ETTh1.csv --dataset_type wide\n```\n\nHowever, we may want validation set during fine-tuning to perform hyperparameter tuning or early stopping.\nTo additionally split the dataset into a train and validation split we can use the mutually exclusive ```date_offset``` (datetime string) or ```offset``` (integer) options which determines the last time step of the train set.\nThe validation set will be saved as DATASET_NAME_eval.\n```shell\npython -m uni2ts.data.builder.simple ETTh1 dataset/ETT-small/ETTh1.csv --date_offset '2017-10-23 23:00:00'\n```\n\n3. Finally, we can simply run the fine-tuning script with the appropriate [training](cli/conf/finetune/data/etth1.yaml) and [validation](cli/conf/finetune/val_data/etth1.yaml) data configuration files.\n```shell\npython -m cli.train \\\n -cp conf/finetune \\\n run_name=example_run \\ \n model=moirai_1.0_R_small \\ \n data=etth1 \\ \n val_data=etth1 \n```\n\n### Evaluation\n\nThe evaluation script can be used to calculate evaluation metrics such as MSE, MASE, CRPS, and so on (see the [configuration file](cli/conf/eval/default.yaml)). \n\nGiven a test split (see previous section on processing datasets), we can run the following command to evaluate it:\n```shell\npython -m cli.eval \\ \n run_name=example_eval_1 \\\n model=moirai_1.0_R_small \\\n model.patch_size=32 \\ \n model.context_length=1000 \\\n data=etth1_test\n```\n\nAlternatively, we provide access to popular datasets, and can be toggled via the [data configurations](cli/conf/eval/data).\nAs an example, say we want to perform evaluation, again on the ETTh1 dataset from the popular [Long Sequence Forecasting benchmark](https://github.com/thuml/Time-Series-Library).\nWe first need to download the pre-processed datasets and put them in the correct directory, by setting up the TSLib repository and following the instructions.\nThen, assign the dataset directory to the `LSF_PATH` environment variable:\n```shell\necho \"LSF_PATH=PATH_TO_TSLIB/dataset\" >> .env\n```\n\nThereafter, simply run the following script with the predefined [Hydra config file](cli/conf/eval/data/lsf_test.yaml):\n```shell\npython -m cli.eval \\ \n run_name=example_eval_2 \\\n model=moirai_1.0_R_small \\\n model.patch_size=32 \\ \n model.context_length=1000 \\ \n data=lsf_test \\\n data.dataset_name=ETTh1 \\\n data.prediction_length=96 \n```\n\n### Pre-training\nNow, let's see how you can pre-train your own model. \nWe'll start with preparing the data for pre-training first, by downloading the [Large-scale Open Time Series Archive (LOTSA data)](https://huggingface.co/datasets/Salesforce/lotsa_data/).\nAssuming you've already createed a `.env` file, run the following commands.\n```shell\nhuggingface-cli download Salesforce/lotsa_data --repo-type=dataset --local-dir PATH_TO_SAVE\necho \"LOTSA_V1_PATH=PATH_TO_SAVE\" >> .env\n```\n\nThen, we can simply run the following script to start a pre-training job. \nSee the [relevant](cli/train.py) [files](cli/conf/pretrain) on how to further customize the settings.\n```shell\npython -m cli.train \\\n -cp conf/pretrain \\\n run_name=first_run \\\n model=moirai_small \\\n data=lotsa_v1_unweighted\n```\n\n## \ud83d\udc40 Citation\n\nIf you're using this repository in your research or applications, please cite using the following BibTeX:\n\n```markdown\n@article{liu2024moiraimoe,\n title={Moirai-MoE: Empowering Time Series Foundation Models with Sparse Mixture of Experts},\n author={Liu, Xu and Liu, Juncheng and Woo, Gerald and Aksu, Taha and Liang, Yuxuan and Zimmermann, Roger and Liu, Chenghao and Savarese, Silvio and Xiong, Caiming and Sahoo, Doyen},\n journal={arXiv preprint arXiv:2410.10469},\n year={2024}\n}\n\n@article{aksu2024gifteval,\n title={GIFT-Eval: A Benchmark For General Time Series Forecasting Model Evaluation},\n author={Aksu, Taha and Woo, Gerald and Liu, Juncheng and Liu, Xu and Liu, Chenghao and Savarese, Silvio and Xiong, Caiming and Sahoo, Doyen},\n journal={arXiv preprint arXiv:2410.10393},\n year={2024}\n}\n\n@inproceedings{woo2024moirai,\n title={Unified Training of Universal Time Series Forecasting Transformers},\n author={Woo, Gerald and Liu, Chenghao and Kumar, Akshat and Xiong, Caiming and Savarese, Silvio and Sahoo, Doyen},\n booktitle={Forty-first International Conference on Machine Learning},\n year={2024}\n}\n```\n",
"bugtrack_url": null,
"license": "Apache License Version 2.0 Copyright (c) 2023 Salesforce, Inc. All rights reserved. Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. \"License\" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. \"Licensor\" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. \"Legal Entity\" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, \"control\" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. \"You\" (or \"Your\") shall mean an individual or Legal Entity exercising permissions granted by this License. \"Source\" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. \"Object\" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. \"Work\" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). \"Derivative Works\" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. \"Contribution\" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, \"submitted\" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as \"Not a Contribution.\" \"Contributor\" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a \"NOTICE\" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets \"{}\" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same \"printed page\" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ",
"summary": "Unified Training of Universal Time Series Forecasting Transformers",
"version": "1.2.0",
"project_urls": null,
"split_keywords": [
"deep learning",
" pytorch",
" time series forecasting",
" transformer"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "39141cb6369988fb76e24351013d297248218e3d559643f3bf4157ecbff145a5",
"md5": "ec66884e4da055d9b67e1ea87b51c06f",
"sha256": "058a37ac3c12b95cb0d4fe006b6f1015aa0fe6d1e3cbf169515b75d746f925ee"
},
"downloads": -1,
"filename": "uni2ts-1.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ec66884e4da055d9b67e1ea87b51c06f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 157022,
"upload_time": "2024-12-04T02:43:11",
"upload_time_iso_8601": "2024-12-04T02:43:11.297063Z",
"url": "https://files.pythonhosted.org/packages/39/14/1cb6369988fb76e24351013d297248218e3d559643f3bf4157ecbff145a5/uni2ts-1.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9016cceb7667719e3cd47fefdafd6c3e306eeb6436c48bc412d65ccc343f3046",
"md5": "db43e5dd6ecd7f061f08f17920fa6d01",
"sha256": "ea716a567787262c99aa13d5d7833f5382dbfd85e8e6e1598e1c37b4b84895f3"
},
"downloads": -1,
"filename": "uni2ts-1.2.0.tar.gz",
"has_sig": false,
"md5_digest": "db43e5dd6ecd7f061f08f17920fa6d01",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 87301,
"upload_time": "2024-12-04T02:43:13",
"upload_time_iso_8601": "2024-12-04T02:43:13.068901Z",
"url": "https://files.pythonhosted.org/packages/90/16/cceb7667719e3cd47fefdafd6c3e306eeb6436c48bc412d65ccc343f3046/uni2ts-1.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-04 02:43:13",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "uni2ts"
}