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

fix torch.load after torch.jit.load #462

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

scott-vsi
Copy link

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)

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)` while will eventually raise a RuntimeError, which is then caught and handled 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)`
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

Successfully merging this pull request may close these issues.

1 participant