Skip to content

Commit 006103e

Browse files
Merge branch 'main' into add-nbeats-v2
2 parents 372f20e + 7bcf66c commit 006103e

14 files changed

Lines changed: 375 additions & 66 deletions

File tree

.github/workflows/pypi_release.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v7
1414

15-
- uses: actions/setup-python@v6
15+
- uses: actions/setup-python@v7
1616
with:
1717
python-version: '3.11'
1818

@@ -34,11 +34,12 @@ jobs:
3434
build_wheels:
3535
name: Build wheels
3636
runs-on: ubuntu-latest
37+
needs: [check_tag]
3738

3839
steps:
3940
- uses: actions/checkout@v7
4041

41-
- uses: actions/setup-python@v6
42+
- uses: actions/setup-python@v7
4243
with:
4344
python-version: '3.11'
4445

@@ -67,7 +68,7 @@ jobs:
6768
- uses: actions/checkout@v7
6869

6970
- name: Set up Python ${{ matrix.python-version }}
70-
uses: actions/setup-python@v6
71+
uses: actions/setup-python@v7
7172
with:
7273
python-version: ${{ matrix.python-version }}
7374

.github/workflows/test.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
uses: actions/checkout@v7
2323

2424
- name: python environment step
25-
uses: actions/setup-python@v6
25+
uses: actions/setup-python@v7
2626
with:
2727
python-version: "3.11"
2828

@@ -59,7 +59,7 @@ jobs:
5959
steps:
6060
- uses: actions/checkout@v7
6161
- name: Set up Python
62-
uses: actions/setup-python@v6
62+
uses: actions/setup-python@v7
6363
with:
6464
python-version: "3.11"
6565
- name: Install dependencies
@@ -88,7 +88,7 @@ jobs:
8888
- uses: actions/checkout@v7
8989

9090
- name: Set up Python ${{ matrix.python-version }}
91-
uses: actions/setup-python@v6
91+
uses: actions/setup-python@v7
9292
with:
9393
python-version: ${{ matrix.python-version }}
9494

@@ -132,7 +132,7 @@ jobs:
132132
enable-cache: true
133133

134134
- name: Set up Python ${{ matrix.python-version }}
135-
uses: actions/setup-python@v6
135+
uses: actions/setup-python@v7
136136
with:
137137
python-version: ${{ matrix.python-version }}
138138

@@ -172,7 +172,7 @@ jobs:
172172
- uses: actions/checkout@v7
173173

174174
- name: Set up Python ${{ matrix.python-version }}
175-
uses: actions/setup-python@v6
175+
uses: actions/setup-python@v7
176176
with:
177177
python-version: ${{ matrix.python-version }}
178178

docs/source/m_layer_v2.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ See the detailed API documentation for the V2 base classes and specific model im
4747
models.samformer._samformer_v2.Samformer
4848
models.tide._tide_dsipts._tide_v2.TIDE
4949
models.timexer._timexer_v2.TimeXer
50+
models.mlp._decodermlp_v2.DecoderMLP_v2

docs/source/pkg_v2.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,4 @@ See the detailed API documentation for the available V2 Package classes below:
9999
models.samformer._samformer_v2_pkg.Samformer_pkg_v2
100100
models.tide._tide_dsipts._tide_v2_pkg.TIDE_pkg_v2
101101
models.timexer._timexer_pkg_v2.TimeXer_pkg_v2
102+
models.mlp._decodermlp_pkg_v2.DecoderMLP_pkg_v2

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ dependencies = [
3333
"scipy >=1.8,<2.0",
3434
"pandas >=1.3.0,<3.1.0",
3535
"scikit-learn >=1.2,<2.0",
36-
"scikit-base <1.1.0",
36+
"scikit-base <1.2.0",
3737
]
3838

3939
[project.optional-dependencies]

pytorch_forecasting/layers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
Encoder,
2020
EncoderLayer,
2121
)
22+
from pytorch_forecasting.layers._mlp import FullyConnectedModule
2223
from pytorch_forecasting.layers._normalization import RevIN
2324
from pytorch_forecasting.layers._output._flatten_head import (
2425
FlattenHead,
@@ -54,4 +55,5 @@
5455
"RevIN",
5556
"ResidualBlock",
5657
"embedding_cat_variables",
58+
"FullyConnectedModule",
5759
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""
2+
Fully connected (MLP) layers.
3+
"""
4+
5+
from pytorch_forecasting.layers._mlp._fully_connected import FullyConnectedModule
6+
7+
__all__ = ["FullyConnectedModule"]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
Fully connected (MLP) module.
3+
"""
4+
5+
import torch
6+
from torch import nn
7+
8+
9+
class FullyConnectedModule(nn.Module):
10+
def __init__(
11+
self,
12+
input_size: int,
13+
output_size: int,
14+
hidden_size: int,
15+
n_hidden_layers: int,
16+
activation_class: nn.ReLU,
17+
dropout: float = None,
18+
norm: bool = True,
19+
):
20+
super().__init__()
21+
self.input_size = input_size
22+
self.output_size = output_size
23+
self.hidden_size = hidden_size
24+
self.n_hidden_layers = n_hidden_layers
25+
self.activation_class = activation_class
26+
self.dropout = dropout
27+
self.norm = norm
28+
29+
# input layer
30+
module_list = [nn.Linear(input_size, hidden_size), activation_class()]
31+
if dropout is not None:
32+
module_list.append(nn.Dropout(dropout))
33+
if norm:
34+
module_list.append(nn.LayerNorm(hidden_size))
35+
# hidden layers
36+
for _ in range(n_hidden_layers):
37+
module_list.extend(
38+
[nn.Linear(hidden_size, hidden_size), activation_class()]
39+
)
40+
if dropout is not None:
41+
module_list.append(nn.Dropout(dropout))
42+
if norm:
43+
module_list.append(nn.LayerNorm(hidden_size))
44+
# output layer
45+
module_list.append(nn.Linear(hidden_size, output_size))
46+
47+
self.sequential = nn.Sequential(*module_list)
48+
49+
def forward(self, x: torch.Tensor) -> torch.Tensor:
50+
# x of shape: batch_size x n_timesteps_in
51+
# output of shape batch_size x n_timesteps_out
52+
return self.sequential(x)

pytorch_forecasting/metrics/base_metrics/_base_metrics.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -689,18 +689,22 @@ def to_quantiles(self, y_pred: torch.Tensor, **kwargs) -> torch.Tensor:
689689
return self._metrics[0].to_quantiles(y_pred, **kwargs)
690690

691691
def __add__(self, metric: LightningMetric):
692+
new_metrics = list(self._metrics)
693+
new_weights = list(self._weights)
692694
if isinstance(metric, self.__class__):
693-
self._metrics.extend(metric._metrics)
694-
self._weights.extend(metric._weights)
695+
new_metrics.extend(metric._metrics)
696+
new_weights.extend(metric._weights)
695697
else:
696-
self._metrics.append(metric)
697-
self._weights.append(1.0)
698+
new_metrics.append(metric)
699+
new_weights.append(1.0)
698700

699-
return self
701+
result = CompositeMetric(metrics=new_metrics, weights=new_weights)
702+
return result
700703

701704
def __mul__(self, multiplier: float):
702-
self._weights = [w * multiplier for w in self._weights]
703-
return self
705+
new_weights = [w * multiplier for w in self._weights]
706+
result = CompositeMetric(metrics=list(self._metrics), weights=new_weights)
707+
return result
704708

705709
__rmul__ = __mul__
706710

pytorch_forecasting/models/mlp/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
from pytorch_forecasting.models.mlp._decodermlp import DecoderMLP
44
from pytorch_forecasting.models.mlp._decodermlp_pkg import DecoderMLP_pkg
5+
from pytorch_forecasting.models.mlp._decodermlp_pkg_v2 import DecoderMLP_pkg_v2
6+
from pytorch_forecasting.models.mlp._decodermlp_v2 import DecoderMLP_v2
57
from pytorch_forecasting.models.mlp.submodules import FullyConnectedModule
68

7-
__all__ = ["DecoderMLP", "DecoderMLP_pkg", "FullyConnectedModule"]
9+
__all__ = [
10+
"DecoderMLP",
11+
"DecoderMLP_pkg",
12+
"DecoderMLP_v2",
13+
"DecoderMLP_pkg_v2",
14+
"FullyConnectedModule",
15+
]

0 commit comments

Comments
 (0)