importing matlab.engine breaks pytorch-lightning model loading.

Open
#16 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
matlab, python, pytorch

Research direction

Start with the minimal reproduction using matlab.engine before the LITModel import and inspect pytorch_lightning/core/saving.py, utilities/cloud_io.py, and torch/serialization.py at the traceback locations. Compare behavior with the imports reversed and verify the reported Python, PyTorch, PyTorch Lightning, MATLAB Engine, and Ubuntu versions. Done means the checkpoint loads successfully regardless of import order, or the compatibility limitation is clearly documented.

Written by the indexing model from the issue text.

Description

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
Dominant language
Python
Stars
97
Forks
13
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mathworks/matlab-engine-for-python

All issues in mathworks/matlab-engine-for-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.