Closed SkyLull closed 2 months ago
Judging by the filename, you have downloaded the state_dict version (and not the full model object).
You can either:
Download the full pickle instead and use that (also search for anything that says jit=
and remove it, if present, if you get another jit error; my model is just a torch.save, not a jit archive).
Load the state_dict you have already downloaded into the ViT-L/14 model:
model, preprocess = clip.load("ViT-L/14")
state_dict = torch.load("path/to/ViT-L-14-TEXT-detail-improved-hiT-GmP-state_dict.pt", map_location="cpu")
model.load_state_dict(state_dict)
model.eval() # or .train(), depending on what you're trying to do
Hope that helps!
THANK YOU VERY MUCH! It worked! I did not realize it work this way. Thank you for your work, your time and your guide!
Description
I'm trying to load CLIP in my code, but it does not work. I bypass the sha256 check in
clip.load()
simply by passing the file name in, in this case, it will just load that model. The code can load original CLIP models successfully using the same method.clip.load("/home/user/.cache/clip/ViT-L-14.pt")
I'm suspecting this might have something to do with a different torch (or python) version, can you provide me with your local environment details?I will list what I have done down below:
Environment
pip install git+https://github.com/openai/CLIP.git
Steps
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "", line 1, in
File "/home/jack/miniconda3/envs/oi/lib/python3.10/site-packages/clip/clip.py", line 136, in load
state_dict = torch.load(opened_file, map_location="cpu")
File "/home/jack/miniconda3/envs/oi/lib/python3.10/site-packages/torch/serialization.py", line 1114, in load
return _legacy_load(
File "/home/jack/miniconda3/envs/oi/lib/python3.10/site-packages/torch/serialization.py", line 1338, in _legacy_load
magic_number = pickle_module.load(f, **pickle_load_args)
EOFError: Ran out of input
Traceback (most recent call last): File "/home/jack/miniconda3/envs/oi/lib/python3.10/site-packages/clip/clip.py", line 129, in load model = torch.jit.load(opened_file, map_location=device if jit else "cpu").eval() File "/home/jack/miniconda3/envs/oi/lib/python3.10/site-packages/torch/jit/_serialization.py", line 165, in load cpp_module = torch._C.import_ir_module_from_buffer( RuntimeError: PytorchStreamReader failed locating file constants.pkl: file not found
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "", line 1, in
File "/home/jack/miniconda3/envs/oi/lib/python3.10/site-packages/clip/clip.py", line 136, in load
state_dict = torch.load(opened_file, map_location="cpu")
File "/home/jack/miniconda3/envs/oi/lib/python3.10/site-packages/torch/serialization.py", line 1114, in load
return _legacy_load(
File "/home/jack/miniconda3/envs/oi/lib/python3.10/site-packages/torch/serialization.py", line 1338, in _legacy_load
magic_number = pickle_module.load(f, **pickle_load_args)
EOFError: Ran out of input