[PR #462] fix torch.load after torch.jit.load #511

Open
opened 2026-10-31 21:15:37 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/openai/CLIP/pull/462
Author: @scott-vsi
Created: 9/18/2024
Status: 🔄 Open

Base: main ← Head: patch-1


📝 Commits (1)

  • 45afa5f fix torch.load after torch.jit.load

📊 Changes

1 file changed (+1 additions, -0 deletions)

View changed files

📝 clip/clip.py (+1 -0)

📄 Description

If we try to load a CLIP model that has not been traced (and is saved as a state_dict), then this first tries to load it with torch.jit.load(opened_file), which will raise a RuntimeError; this is then caught and you re-try loading the model with torch.load(opened_file). However, the file pointer, opened_file has been advanced by torch.jit.load, so this attempt fails with a EOFError: Ran out of input exception. To fix this, we simply need to reset the file pointer to the beginning of the file with .fseek(0)


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/openai/CLIP/pull/462 **Author:** [@scott-vsi](https://github.com/scott-vsi) **Created:** 9/18/2024 **Status:** 🔄 Open **Base:** `main` ← **Head:** `patch-1` --- ### 📝 Commits (1) - [`45afa5f`](https://github.com/openai/CLIP/commit/45afa5f92cc296d299d8850d57a4473224bac8c0) fix torch.load after torch.jit.load ### 📊 Changes **1 file changed** (+1 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `clip/clip.py` (+1 -0) </details> ### 📄 Description If we try to load a CLIP model that has not been traced (and is saved as a state_dict), then this first tries to load it with `torch.jit.load(opened_file)`, which will raise a RuntimeError; this is then caught and you re-try loading the model with `torch.load(opened_file)`. However, the file pointer, `opened_file` has been advanced by `torch.jit.load`, so this attempt fails with a `EOFError: Ran out of input` exception. To fix this, we simply need to reset the file pointer to the beginning of the file with `.fseek(0)` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openai/CLIP#511
No description provided.