pykan icon indicating copy to clipboard operation
pykan copied to clipboard

Cannot reproduce the results of hellokan.ipynb in the latest Python environment.

Open tigran123 opened this issue 9 months ago • 1 comments

I have tried re-running all cells in the provided file hellokan.ipynb and starting from the cell [4] with the comment # train the model I get results, which are different from those shown in the notebook, namely I get train loss: 0.119 instead of 0.115, test loss: 0.125 instead of 0.121, reg: 28.1 instead of 25 and starting from this point everything is different. And, finally, the end result is not the nice $\exp(\sin(\pi x) + y^2)$, but a monstrous huge formula. So, my question is: perhaps some of the cells require running multiple times, e.g. maybe I should keep training the model in the cell [4] until I get the values matching in the notebook? Hmmm, in that case this should have been specified somewhere next to the cell or, better even, done programmatically inside the cell itself.

My environment: Python 3.12.3, matplotlib 3.8.4, numpy 1.26.4, scikit-learn 1.4.2, sympy 1.12 and, most notably, torch 2.3.0, so the versions of the packages are slightly newer and PyTorch is considerably newer, that what is specified in the file requirements.txt. Could this be the cause of the problem? Then we should debug and fix it as sooner or later someone will surely wish to use pykan with the latest Python packages...

I will try to reproduce the problem in a venv generated with the exact versions of the packages as per requirements.txt file.

UPDATE: Those old versions of the packages cannot be installed with Python 3.12.3, so I would have to downgrade Python itself to 3.9.7. I assumed that Python 3.12.3 would work, because the README.md said "3.9.7 or higher".

tigran123 avatar May 14 '24 18:05 tigran123

Just to update: if I rerun cell [4] (the first training), then I get the losses down to the values less than in the original and so after executing all the other cells I eventually get to the expected function in symbolic form. So, looks like with the latest versions of the packages the efficiency of training is somewhat lower and that is why the results were not reproducible if each cell is executed only once. I don't know if this issue should be closed or left for further investigation of which package is causing it. I would bet that it is PyTorch as it is the key package here and the version difference 2.2 vs 2.3 is rather substantial.

tigran123 avatar May 14 '24 20:05 tigran123

Related: https://github.com/KindXiaoming/pykan/issues/258

KindXiaoming avatar Jul 14 '24 04:07 KindXiaoming