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

importing matlab.engine breaks pytorch-lightning model loading. #16

Open
m-lyon opened this issue Nov 30, 2022 · 1 comment
Open

importing matlab.engine breaks pytorch-lightning model loading. #16

m-lyon opened this issue Nov 30, 2022 · 1 comment

Comments

@m-lyon
Copy link

m-lyon commented Nov 30, 2022

It's difficult to assess what package is causing the issue, but i'm going to raise it here as this issue only happens when matlab.engine is imported.

Bug description

importing matlab.engine breaks pytorch_lightning ability to load a previously saved model.

This only happens when import matlab.engine is included in the script. The checkpoint_path is not empty.

How to reproduce the bug

import matlab.engine
from my_custom_model import LITModel # this is a pytorch_lightning.LightningModule model
chkpoint_path = '/path/to/my/checkpoint.ckpt'
model = LITModel.load_from_checkpoint(checkpoint_path=chkpoint_path)

Important

  • If the import of matlab.engine comes after the LITModel import, then the code does not error.

Error messages and logs

LITModel.load_from_checkpoint(chkpoint_path)
  File "/home/anaconda3/envs/torch/lib/python3.8/site-packages/pytorch_lightning/core/saving.py", line 139, in load_from_checkpoint
    checkpoint = pl_load(checkpoint_path, map_location=lambda storage, loc: storage)
  File "/home/anaconda3/envs/torch/lib/python3.8/site-packages/pytorch_lightning/utilities/cloud_io.py", line 47, in load
    return torch.load(f, map_location=map_location)
  File "/home/anaconda3/envs/torch/lib/python3.8/site-packages/torch/serialization.py", line 705, in load
    with _open_zipfile_reader(opened_file) as opened_zipfile:
  File "/home/anaconda3/envs/torch/lib/python3.8/site-packages/torch/serialization.py", line 243, in __init__
    super(_open_zipfile_reader, self).__init__(torch._C.PyTorchFileReader(name_or_buffer))
RuntimeError: [enforce fail at inline_container.cc:106] . archive does not contain any files

Environment

- Linux: Ubuntu 22.04.1 LTS
- python==3.8.12
- pytorch_lightning==1.6.4
- torch==1.11.0
- matlabengine==9.13.1
- Matlab: R2022b
@m-lyon
Copy link
Author

m-lyon commented Dec 1, 2022

I've narrowed down the issue to the pythonengine.createProcess() function call within matlab.engine.enginesession.EngineSession. Commenting out these will stop the issue.

# matlab/engine/enginesession.py
from matlab.engine import pythonengine

class EngineSession:
    def __init__(self):
        try:
            pythonengine.createProcess() # <-- comment this out
            self._process_created = True
        except:
            raise

    def __del__(self):
        self.release()

    def release(self):
        if self._process_created:
            try:
                pythonengine.closeProcess() # <-- comment this out
                self._process_created = False
            except:
                pass

pythonengine is instantiated from a shared object file (on my system) located at /usr/local/MATLAB/R2022b/extern/engines/python/dist/matlab/engine/glnxa64/matlabengineforpython3_8.so.

As far as I know, the code to build matlabengineforpython3_8.so is proprietary, and so this is as far as I can inspect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant