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

Attempt to load from an already-used file pointer in clip/clip.py #396

Open
mrd opened this issue Oct 14, 2023 · 0 comments · May be fixed by #397
Open

Attempt to load from an already-used file pointer in clip/clip.py #396

mrd opened this issue Oct 14, 2023 · 0 comments · May be fixed by #397

Comments

@mrd
Copy link

mrd commented Oct 14, 2023

state_dict = torch.load(opened_file, map_location="cpu")

Went through this code path when attempting to load my own saved checkpoint, and kept getting an EOF error until I inserted a rewind, opened_file.seek(0) before the torch.load (linked above).

This is because the try...except block has a (different) load in the try part, so if it falls back to the exception handler the file-handle is not necessarily at the beginning of the file, and therefore it is not valid to try to load from the file-handle again as-is. It is possible that it would be better to separate the exception handling for file errors from the exception handling for 'jit loading problems', or maybe even better not to try to load with the jit module when the jit option is False, but I'll leave that to you to decide.

Note that I have since switched to loading the ViT-B32 model and then replacing the state_dict, so I don't trigger this bug in my own code anymore.

jongwook added a commit that referenced this issue Oct 16, 2023
@jongwook jongwook linked a pull request Oct 16, 2023 that will close this issue
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 a pull request may close this issue.

1 participant