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

Enables extra parameters to be passed to the model load function. #734

Merged
merged 3 commits into from
Aug 29, 2023
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
33 changes: 28 additions & 5 deletions nbs/core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@
" pickle.dump(config_dict, f)\n",
"\n",
" @staticmethod\n",
" def load(path, verbose=False):\n",
" def load(path, verbose=False, **kwargs):\n",
" \"\"\"Load NeuralForecast\n",
"\n",
" `core.NeuralForecast`'s method to load checkpoint from path.\n",
Expand All @@ -733,7 +733,10 @@
" -----------\n",
" path : str\n",
" Directory to save current status.\n",
" \n",
" kwargs\n",
" Additional keyword arguments to be passed to the function\n",
" `load_from_checkpoint`.\n",
"\n",
" Returns\n",
" -------\n",
" result : NeuralForecast\n",
Expand All @@ -750,7 +753,7 @@
" models = []\n",
" for model in models_ckpt:\n",
" model_name = model.split('_')[0]\n",
" models.append(MODEL_FILENAME_DICT[model_name].load_from_checkpoint(f\"{path}/{model}\"))\n",
" models.append(MODEL_FILENAME_DICT[model_name].load_from_checkpoint(f\"{path}/{model}\", **kwargs))\n",
" if verbose: print(f\"Model {model_name} loaded.\")\n",
"\n",
" if verbose: print(10*'-' + ' Loading dataset ' + 10*'-')\n",
Expand Down Expand Up @@ -843,6 +846,26 @@
"show_doc(NeuralForecast.predict_insample, title_level=3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "93155738-b40f-43d3-ba76-d345bf2583d5",
"metadata": {},
"outputs": [],
"source": [
"show_doc(NeuralForecast.save, title_level=3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0e915796-173c-4400-812f-c6351d5df3be",
"metadata": {},
"outputs": [],
"source": [
"show_doc(NeuralForecast.load, title_level=3)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -921,8 +944,8 @@
"metadata": {},
"outputs": [],
"source": [
"#| hide\\n\",\n",
"# test fit+cross_validation behaviour\\n\",\n",
"#| hide\n",
"# test fit+cross_validation behaviour\n",
"models = [NHITS(h=12, input_size=24, max_steps=10)]\n",
"nf = NeuralForecast(models=models, freq='M')\n",
"nf.fit(AirPassengersPanel_train)\n",
Expand Down
9 changes: 7 additions & 2 deletions neuralforecast/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ def save(
pickle.dump(config_dict, f)

@staticmethod
def load(path, verbose=False):
def load(path, verbose=False, **kwargs):
"""Load NeuralForecast

`core.NeuralForecast`'s method to load checkpoint from path.
Expand All @@ -682,6 +682,9 @@ def load(path, verbose=False):
-----------
path : str
Directory to save current status.
**kwargs
Additional keyword arguments to be passed to the function
`load_from_checkpoint`.

Returns
-------
Expand All @@ -701,7 +704,9 @@ def load(path, verbose=False):
for model in models_ckpt:
model_name = model.split("_")[0]
models.append(
MODEL_FILENAME_DICT[model_name].load_from_checkpoint(f"{path}/{model}")
MODEL_FILENAME_DICT[model_name].load_from_checkpoint(
f"{path}/{model}", **kwargs
)
)
if verbose:
print(f"Model {model_name} loaded.")
Expand Down
Loading