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

New E5 Models in Registry #568

Merged
merged 4 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/marqo/s2_inference/model_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,48 @@ def _get_hf_properties() -> Dict:
"type": "hf",
"model_size": 0.134,
"notes": ""},
"hf/multilingual-e5-small":
{"name": 'intfloat/multilingual-e5-small',
"dimensions": 384,
"tokens": 512,
"type": "hf",
"model_size": 0.471,
"notes": ""},
"hf/multilingual-e5-base":
{"name": 'intfloat/multilingual-e5-base',
"dimensions": 768,
"tokens": 512,
"type": "hf",
"model_size": 1.11,
"notes": ""},
"hf/multilingual-e5-large":
{"name": 'intfloat/multilingual-e5-large',
"dimensions": 1024,
"tokens": 512,
"type": "hf",
"model_size": 2.24,
"notes": ""},
"hf/e5-small-v2":
{"name": 'intfloat/e5-small-v2',
"dimensions": 384,
"tokens": 512,
"type": "hf",
"model_size": 0.134,
"notes": ""},
"hf/e5-base-v2":
{"name": 'intfloat/e5-base-v2',
"dimensions": 768,
"tokens": 512,
"type": "hf",
"model_size": 0.438,
"notes": ""},
"hf/e5-large-v2":
{"name": 'intfloat/e5-large-v2',
"dimensions": 1024,
"tokens": 512,
"type": "hf",
"model_size": 1.34,
"notes": ""},
}
return HF_MODEL_PROPERTIES

Expand Down
18 changes: 12 additions & 6 deletions tests/s2_inference/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def test_vectorize(self):
"all-MiniLM-L6-v1", "all_datasets_v4_MiniLM-L6", "hf/all-MiniLM-L6-v1", "hf/all_datasets_v4_MiniLM-L6",
"onnx/all-MiniLM-L6-v1", "onnx/all_datasets_v4_MiniLM-L6"]

names_e5 = ["hf/e5-small", "hf/e5-base", "hf/e5-small-unsupervised", "hf/e5-base-unsupervised"]
names_e5 = ["hf/e5-small", "hf/e5-base", "hf/e5-small-unsupervised", "hf/e5-base-unsupervised", "hf/e5-base-v2",
"hf/multilingual-e5-small"]
names += names_e5

sentences = ['hello', 'this is a test sentence. so is this.', ['hello', 'this is a test sentence. so is this.']]
Expand All @@ -55,7 +56,8 @@ def test_cpu_encode_type(self):
"all-MiniLM-L6-v1", "all_datasets_v4_MiniLM-L6", "hf/all-MiniLM-L6-v1", "hf/all_datasets_v4_MiniLM-L6",
"onnx/all-MiniLM-L6-v1", "onnx/all_datasets_v4_MiniLM-L6"]

names_e5 = ["hf/e5-small", "hf/e5-base", "hf/e5-small-unsupervised", "hf/e5-base-unsupervised"]
names_e5 = ["hf/e5-small", "hf/e5-base", "hf/e5-small-unsupervised", "hf/e5-base-unsupervised",
"hf/e5-base-v2", "hf/multilingual-e5-small"]
names += names_e5

sentences = ['hello', 'this is a test sentence. so is this.', ['hello', 'this is a test sentence. so is this.']]
Expand Down Expand Up @@ -107,7 +109,8 @@ def test_load_sbert_text_model(self):
def test_load_hf_text_model(self):
names = ["hf/all-MiniLM-L6-v1", "hf/all_datasets_v4_MiniLM-L6"]

names_e5 = ["hf/e5-small", "hf/e5-base", "hf/e5-small-unsupervised", "hf/e5-base-unsupervised"]
names_e5 = ["hf/e5-small", "hf/e5-base", "hf/e5-small-unsupervised", "hf/e5-base-unsupervised",
"hf/e5-base-v2", "hf/multilingual-e5-small"]
names += names_e5

device = 'cpu'
Expand Down Expand Up @@ -159,7 +162,8 @@ def test_model_outputs(self):
"all_datasets_v4_MiniLM-L6", "hf/all-MiniLM-L6-v1",
"hf/all_datasets_v4_MiniLM-L6", "onnx/all-MiniLM-L6-v1", "onnx/all_datasets_v4_MiniLM-L6"]

names_e5 = ["hf/e5-small", "hf/e5-base", "hf/e5-small-unsupervised", "hf/e5-base-unsupervised"]
names_e5 = ["hf/e5-small", "hf/e5-base", "hf/e5-small-unsupervised", "hf/e5-base-unsupervised", "hf/e5-base-v2",
"hf/multilingual-e5-small"]
names += names_e5

sentences = ['hello', 'this is a test sentence. so is this.', ['hello', 'this is a test sentence. so is this.']]
Expand All @@ -182,7 +186,8 @@ def test_model_normalization(self):
"all_datasets_v4_MiniLM-L6", "hf/all-MiniLM-L6-v1", "hf/all_datasets_v4_MiniLM-L6",
"onnx/all-MiniLM-L6-v1", "onnx/all_datasets_v4_MiniLM-L6"]

names_e5 = ["hf/e5-small", "hf/e5-base", "hf/e5-small-unsupervised", "hf/e5-base-unsupervised"]
names_e5 = ["hf/e5-small", "hf/e5-base", "hf/e5-small-unsupervised", "hf/e5-base-unsupervised", "hf/e5-base-v2",
"hf/multilingual-e5-small"]
names += names_e5

sentences = ['hello', 'this is a test sentence. so is this.', ['hello', 'this is a test sentence. so is this.']]
Expand Down Expand Up @@ -211,7 +216,8 @@ def test_model_un_normalization(self):
names = [ 'RN50', "ViT-B/16", "hf/all-MiniLM-L6-v1",
"hf/all_datasets_v4_MiniLM-L6", "onnx/all-MiniLM-L6-v1", "onnx/all_datasets_v4_MiniLM-L6"]

names_e5 = ["hf/e5-small", "hf/e5-base", "hf/e5-small-unsupervised", "hf/e5-base-unsupervised"]
names_e5 = ["hf/e5-small", "hf/e5-base", "hf/e5-small-unsupervised", "hf/e5-base-unsupervised", "hf/e5-base-v2",
"hf/multilingual-e5-small"]
names += names_e5

sentences = ['hello', 'this is a test sentence. so is this.', ['hello', 'this is a test sentence. so is this.']]
Expand Down
48 changes: 19 additions & 29 deletions tests/s2_inference/test_large_model_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def setUp(self) -> None:
'open_clip/convnext_large_d_320/laion2b_s29b_b131k_ft_soup',
'open_clip/convnext_large_d/laion2b_s26b_b102k_augreg']

self.multilingual_models = ["multilingual-clip/XLM-Roberta-Large-Vit-L-14"]
self.multilingual_models = ["hf/multilingual-e5-small", "hf/multilingual-e5-base", "hf/multilingual-e5-large"]

self.e5_models = ["hf/e5-large", "hf/e5-large-unsupervised"]

Expand Down Expand Up @@ -149,34 +149,24 @@ def test_model_normalization(self):
del model
clear_loaded_models()

# This block is commented out due to its memory issue.
# The visual part can be loaded into the target device, but the textual part is always loaded into the cpu device.
# def test_multilingual_clip_performance(self):
#
# clear_loaded_models()
#
# names = self.multilingual_models
# device = "cuda"
# texts = [
# "skiing person",
# "滑雪的人",
# "лыжник",
# "persona che scia",
# ]
# image = "https://raw.githubusercontent.com/marqo-ai/marqo-clip-onnx/main/examples/coco.jpg"
# e = 0.1
# with patch.dict(os.environ, {"MARQO_MAX_CUDA_MODEL_MEMORY": "10"}):
# for name in names:
# text_feature = np.array(vectorise(model_name=name, content=texts, normalize_embeddings=True, device=device))
# image_feature = np.array(vectorise(model_name=name, content=image, normalize_embeddings=True, device=device))
#
# clear_loaded_models()
# similarity_score = (text_feature @ image_feature.T).flatten()
#
# assert np.abs(np.max(similarity_score) - np.min(similarity_score)) < e
#
# del similarity_score
# clear_loaded_models()
def test_multilingual_e5_model_performance(self):
clear_loaded_models()
device = "cuda"
english_text = "skiing person"
other_language_texts = [
"滑雪的人",
"лыжник",
"persona che scia",
]
e = 1
with patch.dict(os.environ, {"MARQO_MAX_CUDA_MODEL_MEMORY": "10"}):
for model_name in self.multilingual_models:
english_feature = np.array(
vectorise(model_name=model_name, content=english_text, normalize_embeddings=True, device=device))
for other_language_text in other_language_texts:
other_language_feature = np.array(vectorise(model_name=model_name, content=other_language_text,
normalize_embeddings=True, device=device))
assert np.allclose(english_feature, other_language_feature, atol=e)

def test_cuda_encode_type(self):
names = self.large_clip_models + self.e5_models
Expand Down
Loading