๐ Moirai-1.0-R-Large
Moirai, the Masked Encoder-based Universal Time Series Forecasting Transformer, is a large time series model pre-trained on LOTSA data. It offers advanced capabilities for time series forecasting. For more details on the Moirai architecture, training, and results, please refer to the paper.
Fig. 1: Overall architecture of Moirai. Visualized is a 3-variate time series, where variates 0 and 1 are target variables (i.e. to be forecasted, and variate 2 is a dynamic covariate (values in forecast horizon known). Based on a patch size of 64, each variate is patchified into 3 tokens. The patch embeddings along with sequence and variate id are fed into the Transformer. The shaded patches represent the forecast horizon to be forecasted, whose corresponding output representations are mapped into the mixture distribution parameters.
๐ Quick Start
๐ฆ Installation
To perform inference with Moirai, you need to install the uni2ts library from our GitHub repo. Follow these steps:
- Clone the repository:
git clone https://github.com/SalesforceAIResearch/uni2ts.git
cd uni2ts
- Create a virtual environment:
virtualenv venv
. venv/bin/activate
- Build from source:
pip install -e '.[notebook]'
- Create a
.env
file:
touch .env
๐ป Usage Examples
๐ Basic Usage
Here is a simple example to get you started with Moirai:
import torch
import matplotlib.pyplot as plt
import pandas as pd
from gluonts.dataset.pandas import PandasDataset
from gluonts.dataset.split import split
from uni2ts.eval_util.plot import plot_single
from uni2ts.model.moirai import MoiraiForecast, MoiraiModule
SIZE = "small"
PDT = 20
CTX = 200
PSZ = "auto"
BSZ = 32
TEST = 100
url = (
"https://gist.githubusercontent.com/rsnirwan/c8c8654a98350fadd229b00167174ec4"
"/raw/a42101c7786d4bc7695228a0f2c8cea41340e18f/ts_wide.csv"
)
df = pd.read_csv(url, index_col=0, parse_dates=True)
ds = PandasDataset(dict(df))
train, test_template = split(
ds, offset=-TEST
)
test_data = test_template.generate_instances(
prediction_length=PDT,
windows=TEST // PDT,
distance=PDT,
)
model = MoiraiForecast(
module=MoiraiModule.from_pretrained(f"Salesforce/moirai-1.0-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,
)
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()
๐ Documentation
๐จโ๐ฉโ๐งโ๐ฆ The Moirai Family
The Moirai family consists of models with different parameter sizes. Here is an overview:
๐ Citation
If you're using Uni2TS in your research or applications, please cite it using this BibTeX:
@article{woo2024unified,
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},
journal={arXiv preprint arXiv:2402.02592},
year={2024}
}
โ๏ธ Ethical Considerations
โ ๏ธ Important Note
This release is for research purposes only in support of an academic paper. Our models, datasets, and code are not specifically designed or evaluated for all downstream purposes. We strongly recommend users evaluate and address potential concerns related to accuracy, safety, and fairness before deploying this model. We encourage users to consider the common limitations of AI, comply with applicable laws, and leverage best practices when selecting use cases, particularly for high-risk scenarios where errors or misuse could significantly impact peopleโs lives, rights, or safety. For further guidance on use cases, refer to our AUP and AI AUP.
๐ License
This project is licensed under the CC BY-NC 4.0 license.