Lightning-AI / Lightning-AI/LitModels
Loading model from .pth is not supported yet
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 40
- Forks
- 9
- PR merge metrics
- No merged PRs in 30d
Description
🐛 Bug
To Reproduce
import torch
from litmodels import save_model, load_model
model = torch.nn.Module()
save_model(model=model, name="skaftenicki/language-model/torch-model")
model_ = load_model(name="skaftenicki/language-model/torch-model")
generates
❯ python main.py
Uploading files...: 100%|█████████████████| 1/1 [00:01<00:00, 1.73s/it]
Model uploaded successfully. Link to the model: 'https://lightning.ai/skaftenicki/language-model/models/torch-model'
Downloading default: 100%|█████████| 1.32k/1.32k [00:00<00:00, 1.71kB/s]
Traceback (most recent call last): | 0.00/1.32k [00:00<?, ?B/s]
File "/home/nsde/Documents/LitModels/main.py", line 6, in <module>
model_ = load_model(name="skaftenicki/language-model/torch-model")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nsde/Documents/LitModels/src/litmodels/io/gateway.py", line 166, in load_model
raise NotImplementedError(f"Loading model from {model_path.suffix} is not supported yet.")
NotImplementedError: Loading model from .pth is not supported yet.
Expected behavior
Code is basically taken from the examples. The problem seems to be that save_model function saves torch models to pth (which are not ScriptModule):
https://github.com/Lightning-AI/LitModels/blob/e9075da71a1cea1ec1d978de3971df937856280f/src/litmodels/io/gateway.py#L94-L96
but not supported in the load_model function.
Environment
- PyTorch Version (e.g., 1.0):
- OS (e.g., Linux):
- How you installed PyTorch (
conda,pip, source): - Build command you used (if compiling from source):
- Python version:
- CUDA/cuDNN version:
- GPU models and configuration:
- Any other relevant information:
Additional context
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/litmodels/io/gateway.py, comparing the save_model handling around lines 94-96 with the load_model failure at line 166. Reproduce the Python example from the issue and trace the .pth path through loading. Done means a model saved by save_model can be loaded without the current NotImplementedError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100