Skip to content

Commit 372f20e

Browse files
feat: Add v2 interface support for N-BEATS model
1 parent a4068ff commit 372f20e

4 files changed

Lines changed: 528 additions & 0 deletions

File tree

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM public.ecr.aws/d3j8x8q7/olympus-base-python:latest
2+
3+
WORKDIR /app
4+
5+
COPY . .
6+
7+
RUN pip install --no-cache-dir .[dev,all_extras]
8+
9+
CMD ["/bin/bash"]

pytorch_forecasting/models/nbeats/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
from pytorch_forecasting.models.nbeats._nbeats import NBeats
1515
from pytorch_forecasting.models.nbeats._nbeats_adapter import NBeatsAdapter
1616
from pytorch_forecasting.models.nbeats._nbeats_pkg import NBeats_pkg
17+
from pytorch_forecasting.models.nbeats._nbeats_pkg_v2 import NBeats_pkg_v2
1718
from pytorch_forecasting.models.nbeats._nbeatskan import NBeatsKAN
1819
from pytorch_forecasting.models.nbeats._nbeatskan_pkg import NBeatsKAN_pkg
1920

2021
__all__ = [
2122
"NBeats",
2223
"NBeatsKAN",
2324
"NBeats_pkg",
25+
"NBeats_pkg_v2",
2426
"NBeatsKAN_pkg",
2527
"NBEATSGenericBlock",
2628
"NBEATSSeasonalBlock",
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
"""NBeats package container."""
2+
3+
from pytorch_forecasting.base._base_pkg import Base_pkg
4+
5+
6+
class NBeats_pkg_v2(Base_pkg):
7+
"""NBeats package container."""
8+
9+
_tags = {
10+
"info:name": "NBeats",
11+
"authors": ["jdb78"],
12+
"capability:exogenous": False,
13+
"capability:multivariate": False,
14+
"capability:pred_int": True,
15+
"capability:flexible_history_length": False,
16+
}
17+
18+
@classmethod
19+
def get_cls(cls):
20+
"""Get model class."""
21+
from pytorch_forecasting.models.nbeats._nbeats_v2 import NBeats
22+
23+
return NBeats
24+
25+
@classmethod
26+
def get_datamodule_cls(cls):
27+
"""Get the underlying DataModule class."""
28+
from pytorch_forecasting.data.data_module import (
29+
EncoderDecoderTimeSeriesDataModule,
30+
)
31+
32+
return EncoderDecoderTimeSeriesDataModule
33+
34+
@classmethod
35+
def get_test_train_params(cls):
36+
"""Return testing parameter settings for the trainer.
37+
38+
Returns
39+
-------
40+
params : dict or list of dict, default = {}
41+
Parameters to create testing instances of the class
42+
Each dict are parameters to construct an "interesting" test instance, i.e.,
43+
`MyClass(**params)` or `MyClass(**params[i])` creates a valid test instance.
44+
`create_test_instance` uses the first (or only) dictionary in `params`
45+
"""
46+
from pytorch_forecasting.metrics import QuantileLoss
47+
48+
params = [
49+
{},
50+
dict(
51+
stack_types=["generic"],
52+
num_blocks=[1],
53+
num_block_layers=[4],
54+
widths=[16],
55+
backcast_loss_ratio=1.0,
56+
),
57+
dict(
58+
stack_types=["trend", "seasonality"],
59+
num_blocks=[2, 2],
60+
widths=[16, 32],
61+
backcast_loss_ratio=0.5,
62+
),
63+
dict(
64+
loss=QuantileLoss(quantiles=[0.1, 0.5, 0.9]),
65+
stack_types=["generic"],
66+
num_blocks=[1],
67+
widths=[16],
68+
),
69+
]
70+
71+
default_dm_cfg = {"max_encoder_length": 8, "max_prediction_length": 2}
72+
73+
for param in params:
74+
current_dm_cfg = param.get("datamodule_cfg", {})
75+
default_dm_cfg.update(current_dm_cfg)
76+
77+
param["datamodule_cfg"] = default_dm_cfg
78+
79+
return params

0 commit comments

Comments
 (0)