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

model2vec support #106

Merged
merged 3 commits into from
Feb 1, 2025
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
12 changes: 12 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ jobs:
- model_name: Snowflake/snowflake-arctic-embed-s
model_tag_name: snowflake-snowflake-arctic-embed-s
onnx_runtime: false
- model_name: minishlab/potion-base-32M
model_tag_name: minishlab/potion-base-32M
use_sentence_transformers_vectorizer: true
onnx_runtime: false
- model_name: minishlab/potion-base-8M
model_tag_name: minishlab/potion-base-8M
use_sentence_transformers_vectorizer: true
onnx_runtime: false
- model_name: minishlab/potion-base-4M
model_tag_name: minishlab/potion-base-4M
use_sentence_transformers_vectorizer: true
onnx_runtime: false
- model_name: Snowflake/snowflake-arctic-embed-s
model_tag_name: snowflake-snowflake-arctic-embed-s
onnx_runtime: true
Expand Down
5 changes: 5 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ def log_info_about_onnx(onnx_runtime: bool):
use_sentence_transformers_vectorizer,
trust_remote_code,
)

if cuda_support is False and meta_config.get_model_type() == "model2vec":
# in case of CPU we need to run this model explicitly on CPU device, not MPS device
cuda_core = "cpu"

vec = Vectorizer(
model_dir,
cuda_support,
Expand Down
19 changes: 15 additions & 4 deletions download.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,28 @@ def save_model_config(model_config):
print(
f"Downloading model {model_name} from huggingface model hub ({trust_remote_code=})"
)
config = AutoConfig.from_pretrained(model_name, trust_remote_code=trust_remote_code)
model_type = config.to_dict()["model_type"]
try:
config = AutoConfig.from_pretrained(
model_name, trust_remote_code=trust_remote_code
)
config_dict = config.to_dict()
model_type = config.to_dict()["model_type"]
except ValueError as e:
# Check if this is the specific model2vec error
if "model type `model2vec`" in str(e):
config_dict = {"model_type": "model2vec"}
model_type = "model2vec"
else:
raise e

if (
model_type is not None and model_type == "t5"
model_type is not None and (model_type == "t5" or model_type == "model2vec")
) or use_sentence_transformers_vectorizer.lower() == "true":
SentenceTransformer(
model_name, cache_folder=model_dir, trust_remote_code=trust_remote_code
)
save_model_name(model_name)
save_model_config(config.to_dict())
save_model_config(config_dict)
else:
if config.architectures and not force_automodel:
print(f"Using class {config.architectures[0]} to load model weights")
Expand Down
10 changes: 5 additions & 5 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
transformers==4.47.1
fastapi==0.115.6
transformers==4.48.2
fastapi==0.115.8
uvicorn==0.34.0
nltk==3.9.1
torch==2.5.1
torch==2.6.0
sentencepiece==0.2.0
sentence-transformers==3.1.1
optimum==1.23.3
sentence-transformers==3.4.1
optimum==1.24.0
onnxruntime==1.20.1
onnx==1.17.0
numpy==1.26.4
Expand Down
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
transformers==4.47.1
fastapi==0.115.6
transformers==4.48.2
fastapi==0.115.8
uvicorn==0.34.0
nltk==3.9.1
torch==2.5.1
torch==2.6.0
sentencepiece==0.2.0
sentence-transformers==3.1.1
optimum==1.23.3
sentence-transformers==3.4.1
optimum==1.24.0
onnxruntime==1.20.1
onnx==1.17.0
numpy==1.26.4
Expand Down