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

chore: move clip models #945

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion client/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
setup_requires=['setuptools>=18.0', 'wheel'],
install_requires=[
'jina>=3.12.0',
'docarray[common]>=0.19.0,<0.30.0',
'docarray[common]==0.21.0',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requirement is too strong. Could we have some flexible version bump here?

'packaging',
],
extras_require={
Expand Down
36 changes: 28 additions & 8 deletions server/clip_server/model/pretrained_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import hashlib
import shutil
import urllib
import requests


_OPENCLIP_S3_BUCKET = 'https://clip-as-service.s3.us-east-2.amazonaws.com/models/torch'
selmiss marked this conversation as resolved.
Show resolved Hide resolved
_OPENCLIP_HUGGINGFACE_BUCKET = 'https://huggingface.co/jinaai/clip-models/'
_OPENCLIP_MODELS = {
'RN50::openai': ('RN50.pt', '9140964eaaf9f68c95aa8df6ca13777c'),
'RN50::yfcc15m': ('RN50-yfcc15m.pt', 'e9c564f91ae7dc754d9043fdcd2a9f22'),
Expand Down Expand Up @@ -132,7 +134,7 @@
def md5file(filename: str):
hash_md5 = hashlib.md5()
with open(filename, 'rb') as f:
for chunk in iter(lambda: f.read(4096), b""):
for chunk in iter(lambda: f.read(4096), b''):
hash_md5.update(chunk)

return hash_md5.hexdigest()
Expand All @@ -143,12 +145,30 @@
if len(model_pretrained) == 0: # not on s3
return None, None
else:
hg_download_url = (
_OPENCLIP_HUGGINGFACE_BUCKET
+ 'resolve/main/'
+ model_pretrained[0]
+ '?download=true'
)
try:
print(f'Test Hg url: {hg_download_url}')
selmiss marked this conversation as resolved.
Show resolved Hide resolved
response = requests.head(hg_download_url)
if response.status_code in [200, 302]:
print('Download from huggingface')
return (hg_download_url, model_pretrained[1])
else:
print(f'Model not found on hugging face, trying to download from s3.')

except requests.exceptions.RequestException as e:
print(str(e))
print(f'Model not found on hugging face, trying to download from s3.')

Check warning on line 165 in server/clip_server/model/pretrained_models.py

View check run for this annotation

Codecov / codecov/patch

server/clip_server/model/pretrained_models.py#L163-L165

Added lines #L163 - L165 were not covered by tests
return (_OPENCLIP_S3_BUCKET + '/' + model_pretrained[0], model_pretrained[1])


def download_model(
url: str,
target_folder: str = os.path.expanduser("~/.cache/clip"),
target_folder: str = os.path.expanduser('~/.cache/clip'),
md5sum: str = None,
with_resume: bool = True,
max_attempts: int = 3,
Expand All @@ -175,14 +195,14 @@
)

progress = Progress(
" \n", # divide this bar from Flow's bar
TextColumn("[bold blue]{task.fields[filename]}", justify="right"),
"[progress.percentage]{task.percentage:>3.1f}%",
"•",
' \n', # divide this bar from Flow's bar
TextColumn('[bold blue]{task.fields[filename]}', justify='right'),
'[progress.percentage]{task.percentage:>3.1f}%',
'•',
DownloadColumn(),
"•",
'•',
TransferSpeedColumn(),
"•",
'•',
TimeRemainingColumn(),
)

Expand Down
Loading