SelfExplainML / PiML-Toolbox

PiML (Python Interpretable Machine Learning) toolbox for model development & diagnostics
https://selfexplainml.github.io/PiML-Toolbox
Apache License 2.0
912 stars 109 forks source link

Saving trained models #21

Closed xloffree closed 1 year ago

xloffree commented 1 year ago

Hi,

I have asked about this in a previous, closed issue (https://github.com/SelfExplainML/PiML-Toolbox/issues/14), but the solution given is not working.

Has this solution worked for you with PiML? When I try this solution, this line: with open('name_model.pkl', 'rb') as file: clf_load = dill.load(file)

results in a recursion error every time. I tried changing the recursion limit but even with a recursion limit pf 10000000 I still run into this error. Increasing the recursion limit indefinitely just causes the kernel to crash.

The error is as follows:

RecursionError Traceback (most recent call last) Cell In [39], line 2 1 with open('name_model.pkl', 'rb') as file: ----> 2 clf_load = dill.load(file)

File /n/holylfs05/LABS/liang_lab_l3/Lab/piml_py39_shared/lib/python3.9/site-packages/dill/_dill.py:272, in load(file, ignore, kwds) 266 def load(file, ignore=None, kwds): 267 """ 268 Unpickle an object from a file. 269 270 See :func:loads for keyword arguments. 271 """ --> 272 return Unpickler(file, ignore=ignore, **kwds).load()

File /n/holylfs05/LABS/liang_lab_l3/Lab/piml_py39_shared/lib/python3.9/site-packages/dill/_dill.py:419, in Unpickler.load(self) 418 def load(self): #NOTE: if settings change, need to update attributes --> 419 obj = StockUnpickler.load(self) 420 if type(obj).module == getattr(_main_module, 'name', 'main'): 421 if not self._ignore: 422 # point obj class to main

File piml/models/glm.py:32, in piml.models.glm.GLMRegressor.getattr()

File piml/models/glm.py:32, in piml.models.glm.GLMRegressor.getattr()

[... skipping similar frames: piml.models.glm.GLMRegressor.getattr at line 32 (9999967 times)] File piml/models/glm.py:32, in piml.models.glm.GLMRegressor.getattr()

RecursionError: maximum recursion depth exceeded while calling a Python object

Any help with this would be very appreciated. When using PiML for research purposes, being able to save a trained model is essential for reproducibility. Thank you!

ZebinYang commented 1 year ago

Hi @xloffree ,

Please see my comments in https://github.com/SelfExplainML/PiML-Toolbox/issues/14.