From 654b94d36587bf65f1c18d8034375488cae05b61 Mon Sep 17 00:00:00 2001 From: gbilleyPeco <119866794+gbilleyPeco@users.noreply.github.com> Date: Mon, 17 Feb 2025 12:35:09 -0500 Subject: [PATCH] [DOC] fix `gradient_clip` value in tutorials to ensure reproducible outputs similar to the committed cell output (#1750) Update gradient_clip=0.01 to gradient_clip=0.1. ### Description I've been following along with the Interpretable forecasting with N-Beats tutorial found here https://pytorch-forecasting.readthedocs.io/en/latest/tutorials/ar.html, copy-pasting the code exactly, and I am getting different results compared to what is shown on the documentation page. The first discrepancy between my results and the tutorial is when using lightning.pytorch.tuner.Tuner to find the optimal learning rate. The suggested learning rate and resulting plot are different. Perhaps more of a problem, however, is that my model fails to learn (training loss doesn't decrease), even when increasing the epochs. When I run the code from the Evaluate Results section, all of the resulting plots show a flat predicted curve. I believe I've found the problem. Testing on my side confirms. Code cells [6] and [14] have the parameter gradient_clip=0.01, which is the source of the problem. The N-HiTS tutorial uses gradient_clip=0.1, so I tried that out, which fixes the problem. The outputs don't match the tutorial outputs exactly, but they're much closer than what gradient_clip=0.01 yields. --- docs/source/tutorials/ar.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/tutorials/ar.ipynb b/docs/source/tutorials/ar.ipynb index 6689dc0e..7cbf0fbc 100644 --- a/docs/source/tutorials/ar.ipynb +++ b/docs/source/tutorials/ar.ipynb @@ -268,7 +268,7 @@ ], "source": [ "pl.seed_everything(42)\n", - "trainer = pl.Trainer(accelerator=\"auto\", gradient_clip_val=0.01)\n", + "trainer = pl.Trainer(accelerator=\"auto\", gradient_clip_val=0.1)\n", "net = NBeats.from_dataset(training, learning_rate=3e-2, weight_decay=1e-2, widths=[32, 512], backcast_loss_ratio=0.1)" ] }, @@ -448,7 +448,7 @@ " max_epochs=3,\n", " accelerator=\"auto\",\n", " enable_model_summary=True,\n", - " gradient_clip_val=0.01,\n", + " gradient_clip_val=0.1,\n", " callbacks=[early_stop_callback],\n", " limit_train_batches=150,\n", ")\n",