Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Fixes 948 multivariate predict/val issues when n_series > 1024 #962

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion nbs/common.base_multivariate.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@
" return self._fit(\n",
" dataset=dataset,\n",
" batch_size=self.n_series,\n",
" valid_batch_size=self.n_series,\n",
" val_size=val_size,\n",
" test_size=test_size,\n",
" random_seed=random_seed,\n",
Expand All @@ -516,7 +517,8 @@
"\n",
" self.predict_step_size = step_size\n",
" self.decompose_forecast = False\n",
" datamodule = TimeSeriesDataModule(dataset=dataset,\n",
" datamodule = TimeSeriesDataModule(dataset=dataset, \n",
" valid_batch_size=self.n_series, \n",
" batch_size=self.n_series,\n",
" **data_module_kwargs)\n",
"\n",
Expand Down
33 changes: 31 additions & 2 deletions nbs/models.tsmixerx.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,10 @@
"#| hide\n",
elephaint marked this conversation as resolved.
Show resolved Hide resolved
"import logging\n",
"import warnings\n",
"import pandas as pd\n",
"\n",
"from neuralforecast import NeuralForecast\n",
"from neuralforecast.utils import AirPassengersPanel, AirPassengersStatic\n",
"from neuralforecast.utils import AirPassengersPanel, AirPassengersStatic, generate_series\n",
"from neuralforecast.losses.pytorch import MAE, MSE, RMSE, MAPE, SMAPE, MASE, relMSE, QuantileLoss, MQLoss, DistributionLoss,PMM, GMM, NBMM, HuberLoss, TukeyLoss, HuberQLoss, HuberMQLoss\n"
]
},
Expand Down Expand Up @@ -589,7 +590,35 @@
" )\n",
"fcst = NeuralForecast(models=[model], freq='M')\n",
"fcst.fit(df=Y_train_df_single, static_df=AirPassengersStatic_single, val_size=12)\n",
"forecasts = fcst.predict(futr_df=Y_test_df_single) "
"forecasts = fcst.predict(futr_df=Y_test_df_single) \n",
"\n",
"# Test n_series > 1024\n",
"# See issue: https://github.com/Nixtla/neuralforecast/issues/948\n",
"n_series = 1111\n",
"Y_df, S_df = generate_series(n_series=n_series, n_temporal_features=2, n_static_features=2)\n",
"\n",
"model = TSMixerx(\n",
" h=12,\n",
" input_size=24,\n",
" n_series=n_series,\n",
" stat_exog_list=['static_0', 'static_1'],\n",
" hist_exog_list=[\"temporal_0\", \"temporal_1\"],\n",
" n_block=4,\n",
" ff_dim=3,\n",
" revin=True,\n",
" scaler_type=\"standard\",\n",
" max_steps=5,\n",
" early_stop_patience_steps=-1,\n",
" val_check_steps=5,\n",
" learning_rate=1e-3,\n",
" loss=MAE(),\n",
" valid_loss=MAE(),\n",
" batch_size=32,\n",
")\n",
"\n",
"fcst = NeuralForecast(models=[model], freq=\"D\")\n",
"fcst.fit(df=Y_df, static_df=S_df, val_size=12)\n",
"forecasts = fcst.predict()"
]
},
{
Expand Down
6 changes: 5 additions & 1 deletion neuralforecast/common/_base_multivariate.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ def fit(
return self._fit(
dataset=dataset,
batch_size=self.n_series,
valid_batch_size=self.n_series,
val_size=val_size,
test_size=test_size,
random_seed=random_seed,
Expand Down Expand Up @@ -556,7 +557,10 @@ def predict(
self.predict_step_size = step_size
self.decompose_forecast = False
datamodule = TimeSeriesDataModule(
dataset=dataset, batch_size=self.n_series, **data_module_kwargs
dataset=dataset,
valid_batch_size=self.n_series,
batch_size=self.n_series,
**data_module_kwargs,
)

# Protect when case of multiple gpu. PL does not support return preds with multiple gpu.
Expand Down
Loading