Skip to content

Commit

Permalink
move ST tests to test_modeling.py since it's a single test
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyasMoutawwakil committed Oct 28, 2024
1 parent dcb140d commit 943cb1b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 75 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test_openvino.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
[
"*modeling.py",
"*modeling_diffusion.py",
"*modeling_sentence_transformers.py",
"*quantization*",
"*training*",
"*export*",
Expand Down
34 changes: 34 additions & 0 deletions tests/openvino/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from huggingface_hub import HfApi
from parameterized import parameterized
from PIL import Image
from sentence_transformers import SentenceTransformer
from transformers import (
AutoConfig,
AutoFeatureExtractor,
Expand Down Expand Up @@ -2360,3 +2361,36 @@ def test_functions(self):

del model
gc.collect()


class OVModelForSTFeatureExtractionIntegrationTest(unittest.TestCase):
SUPPORTED_ARCHITECTURES = ("st-bert", "st-mpnet")

@parameterized.expand(SUPPORTED_ARCHITECTURES)
def test_compare_to_transformers(self, model_arch):
model_id = MODEL_NAMES[model_arch]
set_seed(SEED)
ov_model = OVSentenceTransformer.from_pretrained(model_id, export=True, ov_config=F32_CONFIG)
self.assertIsInstance(ov_model.config, PretrainedConfig)
self.assertTrue(hasattr(ov_model, "encode"))
st_model = SentenceTransformer(model_id)
sentences = ["This is an example sentence", "Each sentence is converted"]
st_embeddings = st_model.encode(sentences)
ov_embeddings = ov_model.encode(sentences)
# Compare tensor outputs
self.assertTrue(np.allclose(ov_embeddings, st_embeddings, atol=1e-4))
del st_embeddings
del ov_model
gc.collect()

@parameterized.expand(SUPPORTED_ARCHITECTURES)
def test_sentence_transformers_save_and_infer(self, model_arch):
model_id = MODEL_NAMES[model_arch]
ov_model = OVSentenceTransformer.from_pretrained(model_id, export=True, ov_config=F32_CONFIG)
with TemporaryDirectory() as tmpdirname:
model_save_path = os.path.join(tmpdirname, "sentence_transformers_ov_model")
ov_model.save_pretrained(model_save_path)
model = OVSentenceTransformer.from_pretrained(model_save_path)
sentences = ["This is an example sentence", "Each sentence is converted"]
model.encode(sentences)
gc.collect()
74 changes: 0 additions & 74 deletions tests/openvino/test_modeling_sentence_transformers.py

This file was deleted.

2 changes: 2 additions & 0 deletions tests/openvino/utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@
"glm4": "katuni4ka/tiny-random-glm4",
"open-clip": "hf-internal-testing/tiny-open-clip-model",
"open-clip-ov": "zofinka/tiny-open-clip-model",
"st-bert": "sentence-transformers/all-MiniLM-L6-v2",
"st-mpnet": "sentence-transformers/all-mpnet-base-v2",
}


Expand Down

0 comments on commit 943cb1b

Please sign in to comment.