From a5b862f6e6d37120feec3c6b4f92f6df31f8ce99 Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Sun, 20 Oct 2024 08:22:10 -0500 Subject: [PATCH 1/2] Fix cache_dir issue with loading CLIPModel --- sentence_transformers/SentenceTransformer.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sentence_transformers/SentenceTransformer.py b/sentence_transformers/SentenceTransformer.py index 1a8cb2efb..4fd069f7d 100644 --- a/sentence_transformers/SentenceTransformer.py +++ b/sentence_transformers/SentenceTransformer.py @@ -1718,10 +1718,10 @@ def _load_sbert_model( # Try to initialize the module with a lot of kwargs, but only if the module supports them # Otherwise we fall back to the load method - # try: - module = module_class(model_name_or_path, cache_dir=cache_folder, backend=self.backend, **kwargs) - # except TypeError: - # module = module_class.load(model_name_or_path) + try: + module = module_class(model_name_or_path, cache_dir=cache_folder, backend=self.backend, **kwargs) + except TypeError: + module = module_class.load(model_name_or_path) else: # Normalize does not require any files to be loaded if module_class == Normalize: From 4f8255538fa347779200c1dcfe4c16e166a91a38 Mon Sep 17 00:00:00 2001 From: Tom Aarsen Date: Mon, 21 Oct 2024 11:19:58 +0200 Subject: [PATCH 2/2] Clarify that you must use Transformer-based models in ONNX export --- sentence_transformers/backend.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sentence_transformers/backend.py b/sentence_transformers/backend.py index eef76352e..355f40d83 100644 --- a/sentence_transformers/backend.py +++ b/sentence_transformers/backend.py @@ -78,7 +78,9 @@ def export_optimized_onnx_model( or not isinstance(model[0], Transformer) or not isinstance(model[0].auto_model, ORTModelForFeatureExtraction) ): - raise ValueError('The model must be a SentenceTransformer model loaded with `backend="onnx"`.') + raise ValueError( + 'The model must be a Transformer-based SentenceTransformer model loaded with `backend="onnx"`.' + ) ort_model: ORTModelForFeatureExtraction = model[0].auto_model optimizer = ORTOptimizer.from_pretrained(ort_model) @@ -158,7 +160,9 @@ def export_dynamic_quantized_onnx_model( or not isinstance(model[0], Transformer) or not isinstance(model[0].auto_model, ORTModelForFeatureExtraction) ): - raise ValueError('The model must be a SentenceTransformer model loaded with `backend="onnx"`.') + raise ValueError( + 'The model must be a Transformer-based SentenceTransformer model loaded with `backend="onnx"`.' + ) ort_model: ORTModelForFeatureExtraction = model[0].auto_model quantizer = ORTQuantizer.from_pretrained(ort_model)