Skip to content

Commit

Permalink
[Releases 2.13] Add support for legacy OpenAI CLIP model (#1107)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanliAlex authored Jan 31, 2025
1 parent 8980c62 commit c05a794
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/marqo/core/inference/embedding_models/open_clip_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ def _load_model_and_image_preprocessor_from_open_clip_repo(self) -> Tuple[torch.

def _load_tokenizer_from_checkpoint(self) -> Callable:
if not self.model_properties.tokenizer:
return open_clip.get_tokenizer(self.model_properties.name)
# Replace '/'with '-' to support old clip model name style
return open_clip.get_tokenizer(self.model_properties.name.replace("/", "-"))
else:
logger.info(f"Custom HFTokenizer is provided. Loading...")
return HFTokenizer(self.model_properties.tokenizer)
Expand Down
13 changes: 12 additions & 1 deletion tests/core/inference/test_open_clip_model_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,15 @@ def test_load_OpenCLIPModel_with_auth_hf(self):
mock_download_model.assert_called_once_with(
repo_location=ModelLocation(**model_properties["model_location"]),
auth=model_auth,
)
)

def test_load_legacy_openai_clip_model(self):
"""A test to ensure old OpenAI CLIP models (e.g., ViT-B/32) are loaded correctly."""
model_properties = {
"name": "ViT-B/32", # Old OpenAI CLIP model name
"type": "open_clip",
"url": "https://github.com/mlfoundations/open_clip/releases/download/v0.2-weights/vit_b_32-quickgelu-laion400m_e32-46683a32.pt",
"dimensions": 512
}
model = OPEN_CLIP(model_properties=model_properties, device="cpu")
model.load()

0 comments on commit c05a794

Please sign in to comment.