Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Loading model from .pth is not supported yet

未关闭
#120 3 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

@SkafteNicki 已经在做这个了。

开始于 2025年8月7日。

  • #122 来自 @SkafteNicki —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
42/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python, pytorch

调研方向

从 src/litmodels/io/gateway.py 开始,对比第 94-96 行附近的 save_model 处理逻辑与第 166 行的 load_model 失败。复现 issue 中的 Python 示例,并跟踪加载过程中的 .pth 路径。当通过 save_model 保存的模型可以在不触发当前 NotImplementedError 的情况下加载时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

bug help wanted

🐛 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
主要语言
Python
星标
40
派生
9
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。