Skip to content

Commit 261b324

Browse files
committed
remove quantile support from Timexer
Signed-off-by: Faakhir30 <zahidfaakhir@gmail.com>
1 parent 72dcf41 commit 261b324

6 files changed

Lines changed: 11 additions & 44 deletions

File tree

pytorch_forecasting/layers/_output/_flatten_head.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,13 @@ class FlattenHead(nn.Module):
1919
nf (int): Number of features in the last layer.
2020
target_window (int): Target window size.
2121
head_dropout (float): Dropout rate for the head. Defaults to 0.
22-
n_quantiles (int, optional): Number of quantiles. Defaults to None."""
22+
"""
2323

24-
def __init__(self, n_vars, nf, target_window, head_dropout=0, n_quantiles=None):
24+
def __init__(self, n_vars, nf, target_window, head_dropout=0):
2525
super().__init__()
2626
self.n_vars = n_vars
2727
self.flatten = nn.Flatten(start_dim=-2)
2828
self.linear = nn.Linear(nf, target_window)
29-
self.n_quantiles = n_quantiles
30-
31-
if self.n_quantiles is not None:
32-
self.linear = nn.Linear(nf, target_window * n_quantiles)
33-
else:
34-
self.linear = nn.Linear(nf, target_window)
3529
self.dropout = nn.Dropout(head_dropout)
3630

3731
def forward(self, x):
@@ -40,7 +34,6 @@ def forward(self, x):
4034
x = self.dropout(x)
4135
x = x.permute(0, 2, 1)
4236

43-
if self.n_quantiles is not None:
44-
batch_size = x.shape[0]
45-
x = x.reshape(batch_size, -1, self.n_quantiles)
37+
batch_size = x.shape[0]
38+
x = x.reshape(batch_size, -1)
4639
return x

pytorch_forecasting/models/timexer/_timexer.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
from pytorch_forecasting.metrics import (
1919
MAE,
2020
MAPE,
21-
MASE,
2221
RMSE,
2322
SMAPE,
2423
MultiHorizonMetric,
25-
QuantileLoss,
2624
)
2725
from pytorch_forecasting.metrics.base_metrics import MultiLoss
2826
from pytorch_forecasting.models.base import BaseModelWithCovariates
@@ -222,16 +220,6 @@ def __init__(
222220
if enc_in is None:
223221
self.enc_in = len(self.reals)
224222

225-
# NOTE: assume point prediction as default here,
226-
# with single median quantile being the point prediction.
227-
# hence self.n_quantiles = 1 for point predictions.
228-
self.n_quantiles = 1
229-
230-
# set n_quantiles to the length of the quantiles list passed
231-
# into the "quantiles" parameter when QuantileLoss is used.
232-
if isinstance(loss, QuantileLoss):
233-
self.n_quantiles = len(loss.quantiles)
234-
235223
if hidden_size % n_heads != 0:
236224
raise ValueError(
237225
f"hidden_size ({hidden_size}) must be divisible by n_heads ({n_heads}) "
@@ -302,7 +290,6 @@ def __init__(
302290
self.head_nf,
303291
self.hparams.prediction_length,
304292
head_dropout=self.hparams.dropout,
305-
n_quantiles=self.n_quantiles,
306293
)
307294

308295
@classmethod
@@ -507,11 +494,7 @@ def forward(self, x: dict[str, torch.Tensor]) -> dict[str, torch.Tensor]:
507494
if prediction.size(2) != len(target_positions):
508495
prediction = prediction[:, :, : len(target_positions)]
509496

510-
# output format is (batch_size, prediction_length, n_quantiles)
511-
# in case of quantile loss, the output n_quantiles = self.n_quantiles
512-
# which is the length of a list of float. In case of MAE, MSE, etc.
513-
# n_quantiles = 1 and it mimics the behavior of a point prediction.
514-
# for multi-target forecasting, the output is a list of tensors.
497+
# output format is (batch_size, prediction_length, n_targets)
515498
if len(target_positions) == 1:
516499
prediction = prediction[..., 0, :]
517500
else:

pytorch_forecasting/models/timexer/_timexer_pkg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ class TimeXer_pkg(_BasePtForecaster):
99
_tags = {
1010
"info:name": "TimeXer",
1111
"info:compute": 3,
12-
"info:pred_type": ["point", "quantile"],
12+
"info:pred_type": ["point"],
1313
"info:y_type": ["numeric"],
1414
"authors": ["PranavBhatP"],
1515
"capability:exogenous": True,
1616
"capability:multivariate": True,
17-
"capability:pred_int": True,
17+
"capability:pred_int": False,
1818
"capability:flexible_history_length": True,
1919
"capability:cold_start": False,
2020
}

pytorch_forecasting/models/timexer/_timexer_pkg_v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TimeXer_pkg_v2(Base_pkg):
1515
"info:y_type": ["numeric"],
1616
"capability:exogenous": True,
1717
"capability:multivariate": True,
18-
"capability:pred_int": True,
18+
"capability:pred_int": False,
1919
"capability:flexible_history_length": False,
2020
"capability:cold_start": False,
2121
}

pytorch_forecasting/models/timexer/_timexer_v2.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,6 @@ def _init_network(self):
195195
# float values.
196196
self.enc_in = self.enc_in or self.cont_dim
197197

198-
self.n_quantiles = None
199-
200-
if hasattr(self.loss, "quantiles") and self.loss.quantiles is not None:
201-
self.n_quantiles = len(self.loss.quantiles)
202-
203198
if self.hidden_size % self.n_heads != 0:
204199
raise ValueError(
205200
f"hidden_size ({self.hidden_size}) must be divisible by n_heads ({self.n_heads}) " # noqa: E501
@@ -259,7 +254,6 @@ def _init_network(self):
259254
self.head_nf,
260255
self.prediction_length,
261256
head_dropout=self.dropout,
262-
n_quantiles=self.n_quantiles,
263257
)
264258

265259
def _forecast(self, x: dict[str, torch.Tensor]) -> dict[str, torch.Tensor]:

pytorch_forecasting/models/timexer/sub_modules.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,14 @@ class FlattenHead(nn.Module):
259259
Target window size.
260260
head_dropout : float, optional
261261
Dropout rate for the head. Defaults to 0.
262-
n_quantiles : int, optional
263-
Number of quantiles. Defaults to 1.
264262
"""
265263

266-
def __init__(self, n_vars, nf, target_window, head_dropout=0, n_quantiles=1):
264+
def __init__(self, n_vars, nf, target_window, head_dropout=0):
267265
super().__init__()
268266
self.n_vars = n_vars
269267
self.flatten = nn.Flatten(start_dim=-2)
270-
self.n_quantiles = n_quantiles
271268

272-
self.linear = nn.Linear(nf, target_window * n_quantiles)
269+
self.linear = nn.Linear(nf, target_window)
273270
self.dropout = nn.Dropout(head_dropout)
274271

275272
def forward(self, x):
@@ -278,7 +275,7 @@ def forward(self, x):
278275
x = self.dropout(x)
279276

280277
batch_size, n_vars = x.shape[0], x.shape[1]
281-
x = x.reshape(batch_size, n_vars, -1, self.n_quantiles)
278+
x = x.reshape(batch_size, n_vars, -1)
282279
return x
283280

284281

0 commit comments

Comments
 (0)