Skip to content

Commit

Permalink
Initial version of Seasonal Naive
Browse files Browse the repository at this point in the history
  • Loading branch information
zqiao11 committed Oct 4, 2024
1 parent 68351a9 commit 5f6b3a4
Show file tree
Hide file tree
Showing 30 changed files with 2,543 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cli/conf/seasonal_naive_eval/data/etth1_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
_target_: uni2ts.eval_util.data.get_custom_eval_dataset
dataset_name: ETTh1_eval
offset: 14400
windows: 2785
distance: 1
prediction_length: 96
mode: null
7 changes: 7 additions & 0 deletions cli/conf/seasonal_naive_eval/data/etth1_val.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
_target_: uni2ts.eval_util.data.get_custom_eval_dataset
dataset_name: ETTh1_eval
offset: 11520
windows: 2785
distance: 1
prediction_length: 96
mode: null
4 changes: 4 additions & 0 deletions cli/conf/seasonal_naive_eval/data/gluonts_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_target_: uni2ts.eval_util.data.get_gluonts_test_dataset
dataset_name: ???
prediction_length: null
mode: S
4 changes: 4 additions & 0 deletions cli/conf/seasonal_naive_eval/data/gluonts_val.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_target_: uni2ts.eval_util.data.get_gluonts_val_dataset
dataset_name: ???
prediction_length: null
mode: S
4 changes: 4 additions & 0 deletions cli/conf/seasonal_naive_eval/data/lsf_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_target_: uni2ts.eval_util.data.get_lsf_test_dataset
dataset_name: ???
prediction_length: ???
mode: S
4 changes: 4 additions & 0 deletions cli/conf/seasonal_naive_eval/data/lsf_val.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_target_: uni2ts.eval_util.data.get_lsf_val_dataset
dataset_name: ???
prediction_length: ???
mode: S
4 changes: 4 additions & 0 deletions cli/conf/seasonal_naive_eval/data/monash.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_target_: uni2ts.eval_util.data.get_gluonts_test_dataset
dataset_name: ???
prediction_length: null
mode: S
24 changes: 24 additions & 0 deletions cli/conf/seasonal_naive_eval/default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
hydra:
run:
dir: outputs/eval/${hydra:runtime.choices.model}/${exp_name}/${data.dataset_name}/${data.mode}/cl${model.context_length}_pl${data.prediction_length}
defaults:
- model: ???
- data: ???
- _self_
exp_name: ???
metrics:
- _target_: gluonts.ev.metrics.MSE
- _target_: uni2ts.eval_util.metrics.MedianMSE
- _target_: gluonts.ev.metrics.MAE
- _target_: gluonts.ev.metrics.MASE
- _target_: gluonts.ev.metrics.MAPE
- _target_: gluonts.ev.metrics.SMAPE
- _target_: gluonts.ev.metrics.MSIS
- _target_: gluonts.ev.metrics.RMSE
- _target_: gluonts.ev.metrics.NRMSE
- _target_: gluonts.ev.metrics.ND
- _target_: gluonts.ev.metrics.MeanWeightedSumQuantileLoss
quantile_levels: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
batch_size: 512
min_batch_size: 16
device: auto
6 changes: 6 additions & 0 deletions cli/conf/seasonal_naive_eval/model/moirai_lightning_ckpt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
_target_: uni2ts.model.seasonal_naive_moirai.MoiraiForecast.load_from_checkpoint
checkpoint_path: ...
pretrained_checkpoint_path: null
num_samples: 100
patch_size: ???
context_length: ???
2 changes: 2 additions & 0 deletions cli/conf/seasonal_naive_finetune/data/electricity.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_target_: uni2ts.data.builder.simple.SimpleDatasetBuilder
dataset: electricity
3 changes: 3 additions & 0 deletions cli/conf/seasonal_naive_finetune/data/etth1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_target_: uni2ts.data.builder.simple.SimpleDatasetBuilder
dataset: ETTh1
weight: 1000
2 changes: 2 additions & 0 deletions cli/conf/seasonal_naive_finetune/data/etth2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_target_: uni2ts.data.builder.simple.SimpleDatasetBuilder
dataset: ETTh2
2 changes: 2 additions & 0 deletions cli/conf/seasonal_naive_finetune/data/ettm1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_target_: uni2ts.data.builder.simple.SimpleDatasetBuilder
dataset: ETTm1
2 changes: 2 additions & 0 deletions cli/conf/seasonal_naive_finetune/data/ettm2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_target_: uni2ts.data.builder.simple.SimpleDatasetBuilder
dataset: ETTm2
2 changes: 2 additions & 0 deletions cli/conf/seasonal_naive_finetune/data/weather.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_target_: uni2ts.data.builder.simple.SimpleDatasetBuilder
dataset: weather
85 changes: 85 additions & 0 deletions cli/conf/seasonal_naive_finetune/default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
hydra:
run:
dir: outputs/sn_finetune/${hydra:runtime.choices.model}/${exp_name}/${model.finetune_pattern}/${hydra:runtime.choices.data}/${run_name}
defaults:
- model: ???
- data: ???
- val_data: null
- _self_
exp_name: ???
run_name: ???
seed: 0
tf32: true
compile: false # set to mode: default, reduce-overhead, max-autotune
ckpt_path: null
trainer:
_target_: lightning.Trainer
accelerator: auto
strategy: auto
devices: auto
num_nodes: 1
precision: 32
logger:
_target_: lightning.pytorch.loggers.TensorBoardLogger
save_dir: ${hydra:runtime.output_dir}
name: logs
callbacks:
- _target_: lightning.pytorch.callbacks.LearningRateMonitor
logging_interval: epoch
- _target_: lightning.pytorch.callbacks.ModelCheckpoint
dirpath: ${hydra:runtime.output_dir}/checkpoints
monitor: val/PackedNLLLoss
save_weights_only: true
mode: min
save_top_k: 1
every_n_epochs: 1
- _target_: lightning.pytorch.callbacks.EarlyStopping
monitor: val/PackedNLLLoss
min_delta: 0.0
patience: 30
mode: min
strict: false
verbose: true
max_epochs: 1000
enable_progress_bar: true
accumulate_grad_batches: 1
gradient_clip_val: 1.0
gradient_clip_algorithm: norm
train_dataloader:
_target_: uni2ts.data.loader.DataLoader
batch_size: 32
batch_size_factor: 2.0
cycle: true
num_batches_per_epoch: 10
shuffle: true
num_workers: 11
collate_fn:
_target_: uni2ts.data.loader.PackCollate
max_length: ${model.module_kwargs.max_seq_len}
seq_fields: ${cls_getattr:${model._target_},seq_fields}
pad_func_map: ${cls_getattr:${model._target_},pad_func_map}
pin_memory: true
drop_last: false
fill_last: false
worker_init_fn: null
prefetch_factor: 2
persistent_workers: true
val_dataloader:
_target_: uni2ts.data.loader.DataLoader
batch_size: 32
batch_size_factor: 2.0
cycle: false
num_batches_per_epoch: null
shuffle: false
num_workers: 11
collate_fn:
_target_: uni2ts.data.loader.PackCollate
max_length: ${model.module_kwargs.max_seq_len}
seq_fields: ${cls_getattr:${model._target_},seq_fields}
pad_func_map: ${cls_getattr:${model._target_},pad_func_map}
pin_memory: false
drop_last: false
fill_last: true
worker_init_fn: null
prefetch_factor: 2
persistent_workers: true
43 changes: 43 additions & 0 deletions cli/conf/seasonal_naive_finetune/model/moirai_1.1_R_small.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# load a pretrained checkpoint from huggingface hub
_target_: uni2ts.model.seasonal_naive_moirai.MoiraiFinetune
module:
_target_: uni2ts.model.seasonal_naive_moirai.MoiraiModule.from_pretrained
pretrained_model_name_or_path: Salesforce/moirai-1.1-R-small
module_kwargs:
_target_: builtins.dict
distr_output:
_target_: uni2ts.distribution.MixtureOutput
components:
- _target_: uni2ts.distribution.StudentTOutput
- _target_: uni2ts.distribution.NormalFixedScaleOutput
- _target_: uni2ts.distribution.NegativeBinomialOutput
- _target_: uni2ts.distribution.LogNormalOutput
d_model: 384
num_layers: 6
patch_sizes: ${as_tuple:[8, 16, 32, 64, 128]}
max_seq_len: 512
attn_dropout_p: 0.0
dropout_p: 0.0
scaling: true
min_patches: 2
min_mask_ratio: 0.15
max_mask_ratio: 0.5
max_dim: 128
loss_func:
_target_: uni2ts.loss.packed.PackedNLLLoss
val_metric:
- _target_: uni2ts.loss.packed.PackedMSELoss
- _target_: uni2ts.loss.packed.PackedNRMSELoss
normalize: absolute_target_squared
lr: 1e-5
weight_decay: 1e-1
beta1: 0.9
beta2: 0.98
num_training_steps: ${mul:${trainer.max_epochs},${train_dataloader.num_batches_per_epoch}}
num_warmup_steps: 0
patch_size: null
context_length: null
prediction_length: null
finetune_pattern: full
replace_distr_output: False
apply_seasonal_naive: True
13 changes: 13 additions & 0 deletions cli/conf/seasonal_naive_finetune/val_data/electricity.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
_target_: uni2ts.data.builder.ConcatDatasetBuilder
_args_:
_target_: uni2ts.data.builder.simple.generate_eval_builders
dataset: electricity_eval
offset: 18412 # Same as _lsf_dataset.py
eval_length: 2630 # Same as _lsf_dataset.py, test_length=5260
prediction_lengths: ???
context_lengths: ???
patch_sizes: ???

# prediction_lengths: [96, 192, 336, 720]
# context_lengths: [3000]
# patch_sizes: [32, 64] # freq='h'
9 changes: 9 additions & 0 deletions cli/conf/seasonal_naive_finetune/val_data/etth1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_target_: uni2ts.data.builder.ConcatDatasetBuilder
_args_:
_target_: uni2ts.data.builder.simple.generate_eval_builders
dataset: ETTh1_eval
offset: 11520
eval_length: 2880
prediction_lengths: [96, 192, 336, 720]
context_lengths: [1000, 2000, 3000, 4000, 5000]
patch_sizes: [32, 64]
16 changes: 16 additions & 0 deletions cli/conf/seasonal_naive_finetune/val_data/etth1_multi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- _target_: uni2ts.data.builder.simple.SimpleEvalDatasetBuilder
dataset: ETTh1_eval
offset: 11520
windows: 10
distance: 96
prediction_length: 96
context_length: 1000
patch_size: 32
- _target_: uni2ts.data.builder.simple.SimpleEvalDatasetBuilder
dataset: ETTh1_eval
offset: 11520
windows: 10
distance: 192
prediction_length: 192
context_length: 1000
patch_size: 32
13 changes: 13 additions & 0 deletions cli/conf/seasonal_naive_finetune/val_data/etth2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
_target_: uni2ts.data.builder.ConcatDatasetBuilder
_args_:
_target_: uni2ts.data.builder.simple.generate_eval_builders
dataset: ETTh2_eval
offset: 8640 # Same as _lsf_dataset.py
eval_length: 2880 # Same as _lsf_dataset.py
prediction_lengths: ???
context_lengths: ???
patch_sizes: ???

# prediction_lengths: [ 96, 192, 336, 720 ]
# context_lengths: [ 3000 ]
# patch_sizes: [ 32, 64 ]
14 changes: 14 additions & 0 deletions cli/conf/seasonal_naive_finetune/val_data/ettm1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
_target_: uni2ts.data.builder.ConcatDatasetBuilder
_args_:
_target_: uni2ts.data.builder.simple.generate_eval_builders
dataset: ETTm1_eval
offset: 34560 # Same as _lsf_dataset.py
eval_length: 11520 # Same as _lsf_dataset.py
prediction_lengths: ???
context_lengths: ???
patch_sizes: ???


# prediction_lengths: [96, 192, 336, 720]
# context_lengths: [ 3000 ]
# patch_sizes: [ 32, 64, 128 ] # freq="15T"
14 changes: 14 additions & 0 deletions cli/conf/seasonal_naive_finetune/val_data/ettm2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
_target_: uni2ts.data.builder.ConcatDatasetBuilder
_args_:
_target_: uni2ts.data.builder.simple.generate_eval_builders
dataset: ETTm2_eval
offset: 34560 # Same as _lsf_dataset.py
eval_length: 11520 # Same as _lsf_dataset.py
prediction_lengths: ???
context_lengths: ???
patch_sizes: ???


# prediction_lengths: [96, 192, 336, 720]
# context_lengths: [3000]
# patch_sizes: [32, 64, 128] # "freq=15T"
9 changes: 9 additions & 0 deletions cli/conf/seasonal_naive_finetune/val_data/weather.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_target_: uni2ts.data.builder.ConcatDatasetBuilder
_args_:
_target_: uni2ts.data.builder.simple.generate_eval_builders
dataset: weather_eval
offset: 36887 # Same as _lsf_dataset.py
eval_length: 5269 # Same as _lsf_dataset.py; test_length=10539
prediction_lengths: ???
context_lengths: ???
patch_sizes: ???
25 changes: 25 additions & 0 deletions src/uni2ts/model/seasonal_naive_moirai/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2024, Salesforce, Inc.
# SPDX-License-Identifier: Apache-2
#
# 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.

from .finetune import MoiraiFinetune
from .forecast import MoiraiForecast
from .module import MoiraiModule


__all__ = [
"MoiraiFinetune",
"MoiraiForecast",
"MoiraiModule",
]
Loading

0 comments on commit 5f6b3a4

Please sign in to comment.