Skip to content

Commit

Permalink
split import cells and remove env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
jmoralez committed Nov 13, 2023
1 parent 0c8d2ff commit 6a65891
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 72 deletions.
22 changes: 13 additions & 9 deletions nbs/common.base_auto.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,6 @@
"outputs": [],
"source": [
"#| hide\n",
"\n",
"#| hide\n",
"import os\n",
"os.environ[\"PYTORCH_ENABLE_MPS_FALLBACK\"] = \"1\"\n",
"os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"0\"\n",
"\n",
"import optuna\n",
"import pandas as pd\n",
"from neuralforecast.models.mlp import MLP\n",
Expand Down Expand Up @@ -647,7 +641,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "ea77450f",
"id": "463d4dc0-b25a-4ce6-9172-5690dc979f0b",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -657,8 +651,18 @@
"from neuralforecast.models.mlp import MLP\n",
"from neuralforecast.utils import AirPassengersDF as Y_df\n",
"from neuralforecast.tsdataset import TimeSeriesDataset\n",
"from neuralforecast.losses.pytorch import MAE, MSE\n",
"\n",
"from neuralforecast.losses.pytorch import MAE, MSE"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "882c8331-440a-4758-a56c-07a78c0b1603",
"metadata": {},
"outputs": [],
"source": [
"#| hide\n",
"# Unit tests to guarantee that losses are correctly instantiated\n",
"Y_train_df = Y_df[Y_df.ds<='1959-12-31'] # 132 train\n",
"Y_test_df = Y_df[Y_df.ds>'1959-12-31'] # 12 test\n",
"\n",
Expand Down
17 changes: 13 additions & 4 deletions nbs/common.base_windows.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -817,16 +817,25 @@
{
"cell_type": "code",
"execution_count": null,
"id": "b2fd48a7",
"id": "8927f2e5-f376-4c99-bb8f-8cbb73efe01e",
"metadata": {},
"outputs": [],
"source": [
"#| hide\n",
"# add h=0,1 unit test for _parse_windows \n",
"from neuralforecast.losses.pytorch import MAE\n",
"from neuralforecast.utils import AirPassengersDF\n",
"from neuralforecast.tsdataset import TimeSeriesDataset, TimeSeriesDataModule\n",
"\n",
"from neuralforecast.tsdataset import TimeSeriesDataset, TimeSeriesDataModule"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "61490e69-f014-4087-83c5-540d5bd7d458",
"metadata": {},
"outputs": [],
"source": [
"#| hide\n",
"# add h=0,1 unit test for _parse_windows \n",
"# Declare batch\n",
"AirPassengersDF['x'] = np.array(len(AirPassengersDF))\n",
"AirPassengersDF['x2'] = np.array(len(AirPassengersDF)) * 2\n",
Expand Down
13 changes: 0 additions & 13 deletions nbs/common.scalers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,6 @@
"![Figure 1. Illustration of temporal normalization (left), layer normalization (center) and batch normalization (right). The entries in green show the components used to compute the normalizing statistics.](imgs_models/temporal_norm.png)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f5400f41",
"metadata": {},
"outputs": [],
"source": [
"#| hide\n",
"import os\n",
"os.environ[\"PYTORCH_ENABLE_MPS_FALLBACK\"] = \"1\"\n",
"os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"0\""
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
18 changes: 12 additions & 6 deletions nbs/core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@
"outputs": [],
"source": [
"#| hide\n",
"import os\n",
"os.environ[\"PYTORCH_ENABLE_MPS_FALLBACK\"] = \"1\"\n",
"os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"0\"\n",
"\n",
"import shutil\n",
"from fastcore.test import test_eq, test_fail\n",
"from nbdev.showdoc import show_doc\n",
Expand Down Expand Up @@ -907,13 +903,23 @@
{
"cell_type": "code",
"execution_count": null,
"id": "8898e349-8000-4668-a1c5-52c03c69e85a",
"id": "5d6ef366-daec-4ec6-a2ae-199c6ea39a51",
"metadata": {},
"outputs": [],
"source": [
"#| hide\n",
"import logging\n",
"import warnings\n",
"import warnings"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0ac1aa65-40a4-4909-bdfb-1439c30439b8",
"metadata": {},
"outputs": [],
"source": [
"#| hide\n",
"logging.getLogger(\"pytorch_lightning\").setLevel(logging.ERROR)\n",
"warnings.filterwarnings(\"ignore\")"
]
Expand Down
2 changes: 1 addition & 1 deletion nbs/examples/Neuralforecast_Map.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
2 changes: 1 addition & 1 deletion nbs/losses.numpy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"outputs": [],
"source": [
"#| hide\n",
"from IPython.display import Image\n",
"from nbdev.showdoc import show_doc"
]
},
Expand All @@ -59,7 +60,6 @@
"outputs": [],
"source": [
"#| hide\n",
"from IPython.display import Image\n",
"WIDTH = 600\n",
"HEIGHT = 300"
]
Expand Down
4 changes: 0 additions & 4 deletions nbs/models.hint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
"outputs": [],
"source": [
"#| hide\n",
"import os\n",
"os.environ[\"PYTORCH_ENABLE_MPS_FALLBACK\"] = \"1\"\n",
"os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"0\"\n",
"\n",
"from nbdev.showdoc import show_doc\n",
"from neuralforecast.losses.pytorch import GMM\n",
"from neuralforecast import NeuralForecast\n",
Expand Down
43 changes: 24 additions & 19 deletions nbs/models.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,6 @@
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cd088010",
"metadata": {},
"outputs": [],
"source": [
"#| hide\n",
"import os\n",
"os.environ[\"PYTORCH_ENABLE_MPS_FALLBACK\"] = \"1\"\n",
"os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"0\""
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -2222,7 +2209,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "fd3a085a",
"id": "db128f64-b311-479e-bf81-07c3bf9f1a5e",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -2232,8 +2219,17 @@
"import matplotlib.pyplot as plt\n",
"\n",
"from neuralforecast.tsdataset import TimeSeriesDataset\n",
"from neuralforecast.utils import AirPassengersDF as Y_df\n",
"\n",
"from neuralforecast.utils import AirPassengersDF as Y_df"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1691fdcc-99e3-472b-ae26-03fb89847227",
"metadata": {},
"outputs": [],
"source": [
"#| hide\n",
"# Split train/test and declare time series dataset\n",
"Y_train_df = Y_df[Y_df.ds<='1959-12-31'] # 132 train\n",
"Y_test_df = Y_df[Y_df.ds>'1959-12-31'] # 12 test\n",
Expand Down Expand Up @@ -2285,15 +2281,24 @@
{
"cell_type": "code",
"execution_count": null,
"id": "56493784",
"id": "0bd1d011-aafb-4b7c-a0a0-0f190b529fa8",
"metadata": {},
"outputs": [],
"source": [
"#| hide\n",
"from neuralforecast.losses.pytorch import GMM, sCRPS"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b7e471ca-a633-4868-be0b-3f2992b6cdc1",
"metadata": {},
"outputs": [],
"source": [
"#| hide\n",
"## TODO: Add unit tests for interactions between loss/valid_loss types\n",
"## TODO: Unit tests (2 types of networks x 2 types of loss x 2 types of valid loss)\n",
"from neuralforecast.losses.pytorch import GMM, sCRPS\n",
"\n",
"## Checking if base recurrent methods run point valid_loss correctly\n",
"tcn_config = {\n",
" \"learning_rate\": tune.choice([1e-3]), # Initial Learning rate\n",
Expand Down
3 changes: 0 additions & 3 deletions nbs/models.nbeatsx.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@
"outputs": [],
"source": [
"#| hide\n",
"import os\n",
"os.environ[\"PYTORCH_ENABLE_MPS_FALLBACK\"] = \"1\"\n",
"\n",
"from fastcore.test import test_eq, test_fail\n",
"from nbdev.showdoc import show_doc\n",
"from neuralforecast.utils import generate_series"
Expand Down
12 changes: 0 additions & 12 deletions nbs/models.nhits.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,6 @@
"![Figure 1. Neural Hierarchical Interpolation for Time Series (NHITS).](imgs_models/nhits.png)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#| hide\n",
"import os\n",
"os.environ[\"PYTORCH_ENABLE_MPS_FALLBACK\"] = \"1\"\n",
"os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"0\""
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit 6a65891

Please sign in to comment.