Files changed (3) hide show
  1. README.md +6 -138
  2. config.json +33 -0
  3. model.safetensors +3 -0
README.md CHANGED
@@ -1,141 +1,9 @@
1
  ---
2
- license: cc-by-nc-4.0
 
 
3
  ---
4
 
5
- # Moirai-1.0-R-Small
6
-
7
- Moirai, the Masked Encoder-based Universal Time Series Forecasting Transformer is a Large Time Series Model pre-trained on [LOTSA data](https://huggingface.co/datasets/Salesforce/lotsa_data).
8
- For more details on the Moirai architecture, training, and results, please refer to the [paper](https://arxiv.org/abs/2402.02592).
9
-
10
- <p align="center">
11
- <img src="figures/architecture.png" width="100%">
12
- <br />
13
- <span>
14
- 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.
15
- </span>
16
- </p>
17
-
18
- ## Usage
19
-
20
- To perform inference with Moirai, install the uni2ts library from our [GitHub repo](https://github.com/SalesforceAIResearch/uni2ts).
21
-
22
- 1. Clone repository:
23
- ```shell
24
- git clone https://github.com/SalesforceAIResearch/uni2ts.git
25
- cd uni2ts
26
- ```
27
-
28
- 2) Create virtual environment:
29
- ```shell
30
- virtualenv venv
31
- . venv/bin/activate
32
- ```
33
-
34
- 3) Build from source:
35
- ```shell
36
- pip install -e '.[notebook]'
37
- ```
38
-
39
- 4) Create a `.env` file:
40
- ```shell
41
- touch .env
42
- ```
43
-
44
- A simple example to get started:
45
-
46
- ```python
47
- import torch
48
- import pandas as pd
49
- from gluonts.dataset.pandas import PandasDataset
50
- from gluonts.dataset.split import split
51
- from huggingface_hub import hf_hub_download
52
-
53
- from uni2ts.eval_util.plot import plot_single
54
- from uni2ts.model.moirai import MoiraiForecast
55
-
56
-
57
- SIZE = "small" # model size: choose from {'small', 'base', 'large'}
58
- PDT = 20 # prediction length: any positive integer
59
- CTX = 200 # context length: any positive integer
60
- PSZ = "auto" # patch size: choose from {"auto", 8, 16, 32, 64, 128}
61
- BSZ = 32 # batch size: any positive integer
62
- TEST = 100 # test set length: any positive integer
63
-
64
- # Read data into pandas DataFrame
65
- url = (
66
- "https://gist.githubusercontent.com/rsnirwan/c8c8654a98350fadd229b00167174ec4"
67
- "/raw/a42101c7786d4bc7695228a0f2c8cea41340e18f/ts_wide.csv"
68
- )
69
- df = pd.read_csv(url, index_col=0, parse_dates=True)
70
-
71
- # Convert into GluonTS dataset
72
- ds = PandasDataset(dict(df))
73
-
74
- # Split into train/test set
75
- train, test_template = split(
76
- ds, offset=-TEST
77
- ) # assign last TEST time steps as test set
78
-
79
- # Construct rolling window evaluation
80
- test_data = test_template.generate_instances(
81
- prediction_length=PDT, # number of time steps for each prediction
82
- windows=TEST // PDT, # number of windows in rolling window evaluation
83
- distance=PDT, # number of time steps between each window - distance=PDT for non-overlapping windows
84
- )
85
-
86
- # Prepare pre-trained model by downloading model weights from huggingface hub
87
- model = MoiraiForecast.load_from_checkpoint(
88
- checkpoint_path=hf_hub_download(
89
- repo_id=f"Salesforce/moirai-R-{SIZE}", filename="model.ckpt"
90
- ),
91
- prediction_length=PDT,
92
- context_length=CTX,
93
- patch_size=PSZ,
94
- num_samples=100,
95
- target_dim=1,
96
- feat_dynamic_real_dim=ds.num_feat_dynamic_real,
97
- past_feat_dynamic_real_dim=ds.num_past_feat_dynamic_real,
98
- map_location="cuda:0" if torch.cuda.is_available() else "cpu",
99
- )
100
-
101
- predictor = model.create_predictor(batch_size=BSZ)
102
- forecasts = predictor.predict(test_data.input)
103
-
104
- input_it = iter(test_data.input)
105
- label_it = iter(test_data.label)
106
- forecast_it = iter(forecasts)
107
-
108
- inp = next(input_it)
109
- label = next(label_it)
110
- forecast = next(forecast_it)
111
-
112
- plot_single(
113
- inp,
114
- label,
115
- forecast,
116
- context_length=200,
117
- name="pred",
118
- show_label=True,
119
- )
120
- ```
121
-
122
- ## The Moirai Family
123
-
124
- | # Model | # Parameters |
125
- | :---: | :---: |
126
- | [Moirai-1.0-R-Small](https://huggingface.co/Salesforce/moirai-1.0-R-small) | 14m |
127
- | [Moirai-1.0-R-Base](https://huggingface.co/Salesforce/moirai-1.0-R-base) | 91m |
128
- | [Moirai-1.0-R-Large](https://huggingface.co/Salesforce/moirai-1.0-R-large) | 311m |
129
-
130
- ## Citation
131
-
132
- If you're using Uni2TS in your research or applications, please cite it using this BibTeX:
133
-
134
- ```markdown
135
- @article{woo2024unified,
136
- title={Unified Training of Universal Time Series Forecasting Transformers},
137
- author={Woo, Gerald and Liu, Chenghao and Kumar, Akshat and Xiong, Caiming and Savarese, Silvio and Sahoo, Doyen},
138
- journal={arXiv preprint arXiv:2402.02592},
139
- year={2024}
140
- }
141
- ```
 
1
  ---
2
+ tags:
3
+ - pytorch_model_hub_mixin
4
+ - model_hub_mixin
5
  ---
6
 
7
+ This model has been pushed to the Hub using the [PytorchModelHubMixin](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.PyTorchModelHubMixin) integration:
8
+ - Library: [More Information Needed]
9
+ - Docs: [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "attn_dropout_p": 0.0,
3
+ "d_model": 384,
4
+ "distr_output": {
5
+ "_target_": "uni2ts.distribution.mixture.MixtureOutput",
6
+ "components": [
7
+ {
8
+ "_target_": "uni2ts.distribution.student_t.StudentTOutput"
9
+ },
10
+ {
11
+ "_target_": "uni2ts.distribution.normal.NormalFixedScaleOutput",
12
+ "scale": 0.001
13
+ },
14
+ {
15
+ "_target_": "uni2ts.distribution.negative_binomial.NegativeBinomialOutput"
16
+ },
17
+ {
18
+ "_target_": "uni2ts.distribution.log_normal.LogNormalOutput"
19
+ }
20
+ ]
21
+ },
22
+ "dropout_p": 0.0,
23
+ "max_seq_len": 512,
24
+ "num_layers": 6,
25
+ "patch_sizes": [
26
+ 8,
27
+ 16,
28
+ 32,
29
+ 64,
30
+ 128
31
+ ],
32
+ "scaling": true
33
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:84317fe1a53632f2b72574b072f200811f6a98fecefe30244d5e34492c9d7a7c
3
+ size 55320200