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

Fix cache_dir issue with loading CLIPModel #3007

Merged
merged 2 commits into from
Oct 21, 2024
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
8 changes: 4 additions & 4 deletions sentence_transformers/SentenceTransformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions sentence_transformers/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down