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)
, which will raise a RuntimeError; this is then caught and you re-try loading the model withtorch.load(opened_file)
. However, the file pointer,opened_file
has been advanced bytorch.jit.load
, so this attempt fails with aEOFError: 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)