darts icon indicating copy to clipboard operation
darts copied to clipboard

Issue with loading model: no attribute '_FaultTolerantMode'

Open chengyineng38 opened this issue 3 years ago • 7 comments

Has something with the model loading API changed? My code worked 1 week before and now it's throwing this error module 'pytorch_lightning.utilities.enums' has no attribute '_FaultTolerantMode'

Screen Shot 2023-03-22 at 3 16 41 PM

Stacktrace:

Traceback (most recent call last):
  File "/xxx/python/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3378, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<command-1139128025771105>", line 3, in <module>
    loaded_model = NBEATSModel.load(loaded_model_path)
  File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/darts/models/forecasting/torch_forecasting_model.py", line 1319, in load
    model: TorchForecastingModel = torch.load(
  File "/xxx/python/lib/python3.9/site-packages/torch/serialization.py", line 789, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
  File "/xxx/python/lib/python3.9/site-packages/torch/serialization.py", line 1131, in _load
    result = unpickler.load()
  File "/usr/lib/python3.9/pickle.py", line 1212, in load
    dispatch[key[0]](self)
  File "/usr/lib/python3.9/pickle.py", line 1528, in load_global
    klass = self.find_class(module, name)
  File "/xxx/python/lib/python3.9/site-packages/torch/serialization.py", line 1124, in find_class
    return super().find_class(mod_name, name)
  File "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/pytorch_lightning/_graveyard/legacy_import_unpickler.py", line 24, in find_class
    return super().find_class(new_module, name)
  File "/usr/lib/python3.9/pickle.py", line 1583, in find_class
    return getattr(sys.modules[module], name)
AttributeError: module 'pytorch_lightning.utilities.enums' has no attribute '_FaultTolerantMode'

chengyineng38 avatar Mar 22 '23 22:03 chengyineng38

Hi @chengyineng38,

Which version of darts are you using? If you're using the master branch, there was indeed some modifications to the save/loading interface but I don't think that they would be the reason of this error...

Did you update your environment recently? The release of PyTorch 2.0 (and subsequently, PyTorch Lightning 2.0) on March 15th might be the culprit, I'll try to run some tests.

madtoinou avatar Mar 23 '23 07:03 madtoinou

I'm using darts==0.23.1. No, I used the same virtual environment. What's odd is that I cannot load the models trained last week. But if I retrain the model, loading these new models works. So, the problem is only with "older" models.

chengyineng38 avatar Mar 23 '23 16:03 chengyineng38

I have no idea of how this feature could break without any updates; I quickly looked at PyTorch Lightning source code and the _FaultTolerantMode class is present in 1.8.3 but not in 2.0.0, could you please check which version of PyTorch Ligtning is installed in your environment?

madtoinou avatar Mar 27 '23 07:03 madtoinou

I am not installing PyTorch lightning directly. I'm using torch. I ran into errors with torch==1.13.0+cu11 (as part of this virtual environment) but loading models works with torch==1.13.1+cu117 virtual environment here.

Double-checked I used darts==0.23.1 both times.

chengyineng38 avatar Mar 27 '23 16:03 chengyineng38

Just to check that I understood correctly: models trained with torch==1.13.0 last week cannot be loaded in this environment anymore and models trained/loaded with torch==1.13.1 work just fine?

Can you please check which version of PyTorch Lightning is installed when you install darts 0.23.1 using pip list | grep pytorch-lightning in each of these environments?

madtoinou avatar Mar 28 '23 09:03 madtoinou

Yes, that's a correct summary.

pip list | grep pytorch-lightning returns 2.0.0 in each of these environments. I just re-ran model loading in these two environments. Using either of these environments now results in the FaultTolerant error. Oddly enough, before I submitted the issue last week, I was able to load using models trained ontorch==1.13.0.

chengyineng38 avatar Mar 28 '23 17:03 chengyineng38

I am reassured, this means that the breaking change is indeed caused by pytorch-lightning 2.0. For some reason, one of the two env was probably not fetching the latest version but now, both of them are.

If you need to load the models trained on the previous version, you'll need to pip install pytorch-lightning with a version <= 2.0 prior to installing darts (since the requirement is >=1.6, it should not reinstall it).

madtoinou avatar Mar 29 '23 08:03 madtoinou