Issue loading a model from torch.hub
johnsutor opened this issue · 3 comments
I'm having trouble importing a model that is in my current directory. Listing the models works without an issue
torch.hub.list("johnsutor/CLIP" ,force_reload=True)
>> ['RN101',
'RN50',
'RN50x16',
'RN50x4',
'RN50x64',
'ViT_B_16',
'ViT_B_32',
'ViT_L_14',
'ViT_L_14_336px',
'tokenize']
But loading a model fails
torch.hub.load("johnsutor/CLIP", "RN101", force_reload=True)
returns the error
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Input In [9], in <cell line: 1>()
----> 1 torch.hub.load("johnsutor/CLIP", "RN101", force_reload=True)
File ~\anaconda3\envs\clip\lib\site-packages\torch\hub.py:404, in load(repo_or_dir, model, source, force_reload, verbose, skip_validation, *args, **kwargs)
401 if source == 'github':
402 repo_or_dir = _get_cache_or_reload(repo_or_dir, force_reload, verbose, skip_validation)
--> 404 model = _load_local(repo_or_dir, model, *args, **kwargs)
405 return model
File ~\anaconda3\envs\clip\lib\site-packages\torch\hub.py:432, in _load_local(hubconf_dir, model, *args, **kwargs)
429 hubconf_path = os.path.join(hubconf_dir, MODULE_HUBCONF)
430 hub_module = _import_module(MODULE_HUBCONF, hubconf_path)
--> 432 entry = _load_entry_from_hubconf(hub_module, model)
433 model = entry(*args, **kwargs)
435 sys.path.remove(hubconf_dir)
File ~\anaconda3\envs\clip\lib\site-packages\torch\hub.py:235, in _load_entry_from_hubconf(m, model)
229 raise ValueError('Invalid input: model should be a string of function name')
231 # Note that if a missing dependency is imported at top level of hubconf, it will
232 # throw before this function. It's a chicken and egg situation where we have to
233 # load hubconf to know what're the dependencies, but to import hubconf it requires
234 # a missing package. This is fine, Python will throw proper error message for users.
--> 235 _check_dependencies(m)
237 func = _load_attr_from_module(m, model)
239 if func is None or not callable(func):
File ~\anaconda3\envs\clip\lib\site-packages\torch\hub.py:224, in _check_dependencies(m)
222 missing_deps = [pkg for pkg in dependencies if not _check_module_exists(pkg)]
223 if len(missing_deps):
--> 224 raise RuntimeError('Missing dependencies: {}'.format(', '.join(missing_deps)))
RuntimeError: Missing dependencies: ftfy
My conda environment is as follows
# Name Version Build Channel
argon2-cffi 21.3.0 pyhd3eb1b0_0
argon2-cffi-bindings 21.2.0 py310h2bbff1b_0
asttokens 2.0.5 pyhd3eb1b0_0
attrs 21.4.0 pyhd3eb1b0_0
backcall 0.2.0 pyhd3eb1b0_0
beautifulsoup4 4.11.1 py310haa95532_0
blas 1.0 mkl
bleach 4.1.0 pyhd3eb1b0_0
brotlipy 0.7.0 py310h2bbff1b_1002
bzip2 1.0.8 he774522_0
ca-certificates 2022.4.26 haa95532_0
certifi 2022.6.15 py310haa95532_0
cffi 1.15.0 py310h2bbff1b_1
charset-normalizer 2.0.4 pyhd3eb1b0_0
colorama 0.4.5 pypi_0 pypi
cryptography 37.0.1 py310h21b164f_0
cudatoolkit 11.3.1 h59b6b97_2
debugpy 1.5.1 py310hd77b12b_0
decorator 5.1.1 pyhd3eb1b0_0
defusedxml 0.7.1 pyhd3eb1b0_0
entrypoints 0.4 py310haa95532_0
executing 0.8.3 pyhd3eb1b0_0
freetype 2.10.4 hd328e21_0
ftfy 6.1.1 pypi_0 pypi
icu 58.2 ha925a31_3
idna 3.3 pyhd3eb1b0_0
intel-openmp 2021.4.0 haa95532_3556
ipykernel 6.9.1 py310haa95532_0
ipython 8.3.0 py310haa95532_0
ipython_genutils 0.2.0 pyhd3eb1b0_1
ipywidgets 7.6.5 pyhd3eb1b0_1
jedi 0.18.1 py310haa95532_1
jinja2 3.0.3 pyhd3eb1b0_0
jpeg 9e h2bbff1b_0
jsonschema 4.4.0 py310haa95532_0
jupyter 1.0.0 py310haa95532_7
jupyter_client 7.2.2 py310haa95532_0
jupyter_console 6.4.3 pyhd3eb1b0_0
jupyter_core 4.10.0 py310haa95532_0
jupyterlab_pygments 0.1.2 py_0
jupyterlab_widgets 1.0.0 pyhd3eb1b0_1
libffi 3.4.2 hd77b12b_4
libpng 1.6.37 h2a8f88b_0
libtiff 4.2.0 he0120a3_1
libuv 1.40.0 he774522_0
libwebp 1.2.2 h2bbff1b_0
lz4-c 1.9.3 h2bbff1b_1
markupsafe 2.1.1 py310h2bbff1b_0
matplotlib-inline 0.1.2 pyhd3eb1b0_2
mistune 0.8.4 py310h2bbff1b_1000
mkl 2021.4.0 haa95532_640
mkl-service 2.4.0 py310h2bbff1b_0
mkl_fft 1.3.1 py310ha0764ea_0
mkl_random 1.2.2 py310h4ed8f06_0
nbclient 0.5.13 py310haa95532_0
nbconvert 6.4.4 py310haa95532_0
nbformat 5.3.0 py310haa95532_0
nest-asyncio 1.5.5 py310haa95532_0
notebook 6.4.11 py310haa95532_0
numpy 1.22.3 py310h6d2d95c_0
numpy-base 1.22.3 py310h206c741_0
openssl 1.1.1o h2bbff1b_0
packaging 21.3 pyhd3eb1b0_0
pandocfilters 1.5.0 pyhd3eb1b0_0
parso 0.8.3 pyhd3eb1b0_0
pickleshare 0.7.5 pyhd3eb1b0_1003
pillow 9.0.1 py310hdc2b20a_0
pip 21.2.4 py310haa95532_0
prometheus_client 0.13.1 pyhd3eb1b0_0
prompt-toolkit 3.0.20 pyhd3eb1b0_0
prompt_toolkit 3.0.20 hd3eb1b0_0
pure_eval 0.2.2 pyhd3eb1b0_0
pycparser 2.21 pyhd3eb1b0_0
pygments 2.11.2 pyhd3eb1b0_0
pyopenssl 22.0.0 pyhd3eb1b0_0
pyparsing 3.0.4 pyhd3eb1b0_0
pyqt 5.9.2 py310hd77b12b_6
pyrsistent 0.18.0 py310h2bbff1b_0
pysocks 1.7.1 py310haa95532_0
python 3.10.4 hbb2ffb3_0
python-dateutil 2.8.2 pyhd3eb1b0_0
python-fastjsonschema 2.15.1 pyhd3eb1b0_0
pytorch 1.11.0 py3.10_cuda11.3_cudnn8_0 pytorch
pytorch-mutex 1.0 cuda pytorch
pywin32 302 py310h2bbff1b_2
pywinpty 2.0.2 py310h5da7b33_0
pyzmq 22.3.0 py310hd77b12b_2
qt 5.9.7 vc14h73c81de_0
qtconsole 5.3.0 pyhd3eb1b0_0
qtpy 2.0.1 pyhd3eb1b0_0
regex 2022.6.2 pypi_0 pypi
requests 2.27.1 pyhd3eb1b0_0
send2trash 1.8.0 pyhd3eb1b0_1
setuptools 61.2.0 py310haa95532_0
sip 4.19.13 py310hd77b12b_0
six 1.16.0 pyhd3eb1b0_1
soupsieve 2.3.1 pyhd3eb1b0_0
sqlite 3.38.5 h2bbff1b_0
stack_data 0.2.0 pyhd3eb1b0_0
terminado 0.13.1 py310haa95532_0
testpath 0.6.0 py310haa95532_0
tk 8.6.12 h2bbff1b_0
torchaudio 0.11.0 py310_cu113 pytorch
torchvision 0.12.0 py310_cu113 pytorch
tornado 6.1 py310h2bbff1b_0
tqdm 4.64.0 pypi_0 pypi
traitlets 5.1.1 pyhd3eb1b0_0
typing-extensions 4.1.1 hd3eb1b0_0
typing_extensions 4.1.1 pyh06a4308_0
tzdata 2022a hda174b7_0
urllib3 1.26.9 py310haa95532_0
vc 14.2 h21ff451_1
vs2015_runtime 14.27.29016 h5e58377_2
wcwidth 0.2.5 pyhd3eb1b0_0
webencodings 0.5.1 py310haa95532_1
wheel 0.37.1 pyhd3eb1b0_0
widgetsnbextension 3.5.2 py310haa95532_0
win_inet_pton 1.1.0 py310haa95532_0
wincertstore 0.2 py310haa95532_2
winpty 0.4.3 4
xz 5.2.5 h8cc25b3_1
zlib 1.2.12 h8cc25b3_2
zstd 1.5.2 h19a0ad4_0
Any help would be greatly appreciated!
Hi @johnsutor ,
I believe this is expected: the repo lists the following as dependencies:
https://github.com/johnsutor/CLIP/blob/e9da8421762c8446ac22cb981506dfb45e55abc1/hubconf.py#L4
These dependencies are required to load a specific model or function, but not to list the entrypoints. This is why you get the dependency error when calling load()
and not when calling list()
.
I think you just have to install ftfy
for it to work properly
Update: in here the dependency starts with a space (`" ftfy"), which makes it unfindable.
I would suggest to remove the trailing space :)
Great catch, it's always the simplest things... thank you much!