forked from opensearch-project/opensearch-py-ml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Thanawan Atchariyachanvanit <[email protected]>
- Loading branch information
1 parent
68198c8
commit bc4cc78
Showing
10 changed files
with
217 additions
and
27 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
tests/ml_model_listing/samples/config_folder/intfloat/e5-small-v2/1.0.1/onnx/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name": "intfloat/e5-small-v2", "version": "1.0.1", "description": "This is a sentence-transformers model: It maps sentences & paragraphs to a 384 dimensional dense vector space.", "model_format": "ONNX", "model_task_type": "TEXT_EMBEDDING", "model_config": {"model_type": "bert", "embedding_dimension": 384, "framework_type": "sentence_transformers", "pooling_mode": "MEAN", "normalize_result": true, "all_config": "{\"_name_or_path\": \"/root/.cache/torch/sentence_transformers/intfloat_e5-small-v2/\", \"architectures\": [\"BertModel\"], \"attention_probs_dropout_prob\": 0.1, \"classifier_dropout\": null, \"hidden_act\": \"gelu\", \"hidden_dropout_prob\": 0.1, \"hidden_size\": 384, \"initializer_range\": 0.02, \"intermediate_size\": 1536, \"layer_norm_eps\": 1e-12, \"max_position_embeddings\": 512, \"model_type\": \"bert\", \"num_attention_heads\": 12, \"num_hidden_layers\": 12, \"pad_token_id\": 0, \"position_embedding_type\": \"absolute\", \"torch_dtype\": \"float32\", \"transformers_version\": \"4.31.0\", \"type_vocab_size\": 2, \"use_cache\": true, \"vocab_size\": 30522}"}} |
1 change: 1 addition & 0 deletions
1
..._listing/samples/config_folder/jhgan/ko-sroberta-multitask/1.0.1/torch_script/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name": "jhgan/ko-sroberta-multitask", "version": "1.0.1", "description": "This is a sentence-transformers model: It maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search.", "model_format": "TORCH_SCRIPT", "model_task_type": "TEXT_EMBEDDING", "model_config": {"model_type": "roberta", "embedding_dimension": 768, "framework_type": "sentence_transformers", "pooling_mode": "MEAN", "normalize_result": false, "all_config": "{\"_name_or_path\": \"/root/.cache/torch/sentence_transformers/jhgan_ko-sroberta-multitask/\", \"architectures\": [\"RobertaModel\"], \"attention_probs_dropout_prob\": 0.1, \"bos_token_id\": 0, \"classifier_dropout\": null, \"eos_token_id\": 2, \"gradient_checkpointing\": false, \"hidden_act\": \"gelu\", \"hidden_dropout_prob\": 0.1, \"hidden_size\": 768, \"initializer_range\": 0.02, \"intermediate_size\": 3072, \"layer_norm_eps\": 1e-05, \"max_position_embeddings\": 514, \"model_type\": \"roberta\", \"num_attention_heads\": 12, \"num_hidden_layers\": 12, \"pad_token_id\": 1, \"position_embedding_type\": \"absolute\", \"tokenizer_class\": \"BertTokenizer\", \"torch_dtype\": \"float32\", \"transformers_version\": \"4.31.0\", \"type_vocab_size\": 1, \"use_cache\": true, \"vocab_size\": 32000}"}} |
1 change: 1 addition & 0 deletions
1
...folder/sentence-transformers/clip-ViT-B-32-multilingual-v1/1.0.1/torch_script/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name": "sentence-transformers/clip-ViT-B-32-multilingual-v1", "version": "1.0.1", "description": "This is a multi-lingual version of the OpenAI CLIP-ViT-B32 model. You can map text and images to a common dense vector space such that images and the matching texts are close. This model can be used for image search and for multi-lingual zero-shot image classification .", "model_format": "TORCH_SCRIPT", "model_task_type": "TEXT_EMBEDDING", "model_config": {"model_type": "distilbert", "embedding_dimension": 512, "framework_type": "sentence_transformers", "pooling_mode": "MEAN", "normalize_result": false, "all_config": "{\"_name_or_path\": \"/root/.cache/torch/sentence_transformers/sentence-transformers_clip-ViT-B-32-multilingual-v1/\", \"activation\": \"gelu\", \"architectures\": [\"DistilBertModel\"], \"attention_dropout\": 0.1, \"dim\": 768, \"dropout\": 0.1, \"hidden_dim\": 3072, \"initializer_range\": 0.02, \"max_position_embeddings\": 512, \"model_type\": \"distilbert\", \"n_heads\": 12, \"n_layers\": 6, \"output_past\": true, \"pad_token_id\": 0, \"qa_dropout\": 0.1, \"seq_classif_dropout\": 0.2, \"sinusoidal_pos_embds\": false, \"tie_weights_\": true, \"torch_dtype\": \"float32\", \"transformers_version\": \"4.31.0\", \"vocab_size\": 119547}"}} |
1 change: 1 addition & 0 deletions
1
...les/config_folder/sentence-transformers/multi-qa-mpnet-base-cos-v1/1.0.1/onnx/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name": "sentence-transformers/multi-qa-mpnet-base-cos-v1", "version": "1.0.1", "description": "This is a sentence-transformers model: It maps sentences & paragraphs to a 768 dimensional dense vector space and was designed for semantic search. It has been trained on 215M pairs from diverse sources.", "model_format": "ONNX", "model_task_type": "TEXT_EMBEDDING", "model_config": {"model_type": "mpnet", "embedding_dimension": 768, "framework_type": "sentence_transformers", "pooling_mode": "MEAN", "normalize_result": true, "all_config": "{\"_name_or_path\": \"/root/.cache/torch/sentence_transformers/sentence-transformers_multi-qa-mpnet-base-cos-v1/\", \"architectures\": [\"MPNetModel\"], \"attention_probs_dropout_prob\": 0.1, \"bos_token_id\": 0, \"eos_token_id\": 2, \"hidden_act\": \"gelu\", \"hidden_dropout_prob\": 0.1, \"hidden_size\": 768, \"initializer_range\": 0.02, \"intermediate_size\": 3072, \"layer_norm_eps\": 1e-05, \"max_position_embeddings\": 514, \"model_type\": \"mpnet\", \"num_attention_heads\": 12, \"num_hidden_layers\": 12, \"pad_token_id\": 1, \"relative_attention_num_buckets\": 32, \"torch_dtype\": \"float32\", \"transformers_version\": \"4.31.0\", \"vocab_size\": 30527}"}} |
1 change: 1 addition & 0 deletions
1
...ig_folder/sentence-transformers/multi-qa-mpnet-base-cos-v1/1.0.1/torch_script/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name": "sentence-transformers/multi-qa-mpnet-base-cos-v1", "version": "1.0.1", "description": "This is a sentence-transformers model: It maps sentences & paragraphs to a 768 dimensional dense vector space and was designed for semantic search. It has been trained on 215M pairs from diverse sources.", "model_format": "TORCH_SCRIPT", "model_task_type": "TEXT_EMBEDDING", "model_config": {"model_type": "mpnet", "embedding_dimension": 768, "framework_type": "sentence_transformers", "pooling_mode": "MEAN", "normalize_result": true, "all_config": "{\"_name_or_path\": \"/root/.cache/torch/sentence_transformers/sentence-transformers_multi-qa-mpnet-base-cos-v1/\", \"architectures\": [\"MPNetModel\"], \"attention_probs_dropout_prob\": 0.1, \"bos_token_id\": 0, \"eos_token_id\": 2, \"hidden_act\": \"gelu\", \"hidden_dropout_prob\": 0.1, \"hidden_size\": 768, \"initializer_range\": 0.02, \"intermediate_size\": 3072, \"layer_norm_eps\": 1e-05, \"max_position_embeddings\": 514, \"model_type\": \"mpnet\", \"num_attention_heads\": 12, \"num_hidden_layers\": 12, \"pad_token_id\": 1, \"relative_attention_num_buckets\": 32, \"torch_dtype\": \"float32\", \"transformers_version\": \"4.31.0\", \"vocab_size\": 30527}"}} |
1 change: 1 addition & 0 deletions
1
...ig_folder/sentence-transformers/multi-qa-mpnet-base-cos-v1/2.0.0/torch_script/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name": "sentence-transformers/multi-qa-mpnet-base-cos-v1", "version": "2.0.0", "description": "This is a sentence-transformers model: It maps sentences & paragraphs to a 768 dimensional dense vector space and was designed for semantic search. It has been trained on 215M pairs from diverse sources. (New Version)", "model_format": "TORCH_SCRIPT", "model_task_type": "TEXT_EMBEDDING", "model_config": {"model_type": "mpnet", "embedding_dimension": 768, "framework_type": "sentence_transformers", "pooling_mode": "MEAN", "normalize_result": true, "all_config": "{\"_name_or_path\": \"/root/.cache/torch/sentence_transformers/sentence-transformers_multi-qa-mpnet-base-cos-v1/\", \"architectures\": [\"MPNetModel\"], \"attention_probs_dropout_prob\": 0.1, \"bos_token_id\": 0, \"eos_token_id\": 2, \"hidden_act\": \"gelu\", \"hidden_dropout_prob\": 0.1, \"hidden_size\": 768, \"initializer_range\": 0.02, \"intermediate_size\": 3072, \"layer_norm_eps\": 1e-05, \"max_position_embeddings\": 514, \"model_type\": \"mpnet\", \"num_attention_heads\": 12, \"num_hidden_layers\": 12, \"pad_token_id\": 1, \"relative_attention_num_buckets\": 32, \"torch_dtype\": \"float32\", \"transformers_version\": \"4.31.0\", \"vocab_size\": 30527}"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ml-models/huggingface/intfloat/e5-small-v2/1.0.1/onnx/config.json ml-models/huggingface/jhgan/ko-sroberta-multitask/1.0.1/torch_script/config.json ml-models/huggingface/sentence-transformers/clip-ViT-B-32-multilingual-v1/1.0.1/torch_script/config.json ml-models/huggingface/sentence-transformers/multi-qa-mpnet-base-cos-v1/1.0.1/onnx/config.json ml-models/huggingface/sentence-transformers/multi-qa-mpnet-base-cos-v1/1.0.1/torch_script/config.json ml-models/huggingface/sentence-transformers/multi-qa-mpnet-base-cos-v1/2.0.0/torch_script/config.json |
53 changes: 53 additions & 0 deletions
53
tests/ml_model_listing/samples/pretrained_model_listing.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
[ | ||
{ | ||
"name": "huggingface/intfloat/e5-small-v2", | ||
"versions": { | ||
"1.0.1": { | ||
"format": [ | ||
"onnx" | ||
], | ||
"description": "This is a sentence-transformers model: It maps sentences & paragraphs to a 384 dimensional dense vector space." | ||
} | ||
} | ||
}, | ||
{ | ||
"name": "huggingface/jhgan/ko-sroberta-multitask", | ||
"versions": { | ||
"1.0.1": { | ||
"format": [ | ||
"torch_script" | ||
], | ||
"description": "This is a sentence-transformers model: It maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search." | ||
} | ||
} | ||
}, | ||
{ | ||
"name": "huggingface/sentence-transformers/clip-ViT-B-32-multilingual-v1", | ||
"versions": { | ||
"1.0.1": { | ||
"format": [ | ||
"torch_script" | ||
], | ||
"description": "This is a multi-lingual version of the OpenAI CLIP-ViT-B32 model. You can map text and images to a common dense vector space such that images and the matching texts are close. This model can be used for image search and for multi-lingual zero-shot image classification ." | ||
} | ||
} | ||
}, | ||
{ | ||
"name": "huggingface/sentence-transformers/multi-qa-mpnet-base-cos-v1", | ||
"versions": { | ||
"1.0.1": { | ||
"format": [ | ||
"onnx", | ||
"torch_script" | ||
], | ||
"description": "This is a sentence-transformers model: It maps sentences & paragraphs to a 768 dimensional dense vector space and was designed for semantic search. It has been trained on 215M pairs from diverse sources." | ||
}, | ||
"2.0.0": { | ||
"format": [ | ||
"torch_script" | ||
], | ||
"description": "This is a sentence-transformers model: It maps sentences & paragraphs to a 768 dimensional dense vector space and was designed for semantic search. It has been trained on 215M pairs from diverse sources. (New Version)" | ||
} | ||
} | ||
} | ||
] |
126 changes: 126 additions & 0 deletions
126
tests/ml_model_listing/test_update_pretrained_model_listing.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# The OpenSearch Contributors require contributions made to | ||
# this file be licensed under the Apache-2.0 license or a | ||
# compatible open source license. | ||
# Any modifications Copyright OpenSearch Contributors. See | ||
# GitHub history for details. | ||
|
||
# We need to append UTILS_MODEL_UPLOADER_DIR path so that we can import | ||
# functions from update_pretrained_model_listing.py | ||
# since this python script is not in the root directory. | ||
|
||
import json | ||
import os | ||
import shutil | ||
import sys | ||
|
||
import pytest | ||
|
||
THIS_DIR = os.path.dirname(__file__) | ||
UTILS_MODEL_UPLOADER_DIR = os.path.join(THIS_DIR, "../../utils/model_uploader") | ||
sys.path.append(UTILS_MODEL_UPLOADER_DIR) | ||
|
||
SAMPLE_FOLDER = os.path.join(THIS_DIR, "samples") | ||
CONFIG_PATHS_TXT_FILENAME = "config_paths.txt" | ||
CONFIG_FOLDERNAME = "config_folder" | ||
SAMPLE_PRETRAINED_MODEL_LISTING = os.path.join( | ||
SAMPLE_FOLDER, "pretrained_model_listing.json" | ||
) | ||
SAMPLE_FOLDER_COPY = os.path.join(THIS_DIR, "samples_copy") | ||
SAMPLE_MISSING_CONFIG_SUBFOLDERNAME = "sentence-transformers" | ||
TEST_FILE = os.path.join(THIS_DIR, "test_pretrained_model_listing.json") | ||
|
||
from update_pretrained_model_listing import create_new_pretrained_model_listing | ||
|
||
|
||
def clean_test_file(): | ||
if os.path.isfile(TEST_FILE): | ||
os.remove(TEST_FILE) | ||
|
||
|
||
def copy_samples_folder(): | ||
shutil.copytree(SAMPLE_FOLDER, SAMPLE_FOLDER_COPY) | ||
|
||
|
||
def clean_samples_folder_copy(): | ||
if os.path.exists(SAMPLE_FOLDER_COPY): | ||
for files in os.listdir(SAMPLE_FOLDER_COPY): | ||
sub_path = os.path.join(SAMPLE_FOLDER_COPY, files) | ||
if os.path.isfile(sub_path): | ||
os.remove(sub_path) | ||
else: | ||
try: | ||
shutil.rmtree(sub_path) | ||
except OSError as err: | ||
print( | ||
"Fail to delete files, please delete all files in " | ||
+ str(SAMPLE_FOLDER_COPY) | ||
+ " " | ||
+ str(err) | ||
) | ||
|
||
shutil.rmtree(SAMPLE_FOLDER_COPY) | ||
|
||
|
||
clean_samples_folder_copy() | ||
clean_test_file() | ||
|
||
|
||
def test_create_new_pretrained_model_listing(): | ||
clean_test_file() | ||
try: | ||
create_new_pretrained_model_listing( | ||
os.path.join(SAMPLE_FOLDER, CONFIG_PATHS_TXT_FILENAME), | ||
os.path.join(SAMPLE_FOLDER, CONFIG_FOLDERNAME), | ||
pretrained_model_listing_json_filepath=TEST_FILE, | ||
) | ||
except Exception as e: | ||
assert False, print(f"Failed while creating new pretrained model listing: {e}") | ||
|
||
try: | ||
with open(SAMPLE_PRETRAINED_MODEL_LISTING, "r") as f: | ||
sample_pretrained_model_listing = json.load(f) | ||
except Exception as e: | ||
assert False, print( | ||
f"Cannot open {SAMPLE_PRETRAINED_MODEL_LISTING} to use it for verification: {e}" | ||
) | ||
|
||
try: | ||
with open(TEST_FILE, "r") as f: | ||
test_pretrained_model_listing = json.load(f) | ||
except Exception as e: | ||
assert False, print(f"Cannot open {TEST_FILE} to verify its content: {e}") | ||
|
||
assert test_pretrained_model_listing == sample_pretrained_model_listing, print( | ||
"Incorrect pretrained model listing" | ||
) | ||
|
||
clean_test_file() | ||
|
||
|
||
def test_missing_config_file(): | ||
clean_test_file() | ||
clean_samples_folder_copy() | ||
|
||
copy_samples_folder() | ||
shutil.rmtree( | ||
os.path.join( | ||
SAMPLE_FOLDER_COPY, CONFIG_FOLDERNAME, SAMPLE_MISSING_CONFIG_SUBFOLDERNAME | ||
) | ||
) | ||
|
||
with pytest.raises(Exception) as exc_info: | ||
create_new_pretrained_model_listing( | ||
os.path.join(SAMPLE_FOLDER_COPY, CONFIG_PATHS_TXT_FILENAME), | ||
os.path.join(SAMPLE_FOLDER_COPY, CONFIG_FOLDERNAME), | ||
pretrained_model_listing_json_filepath=TEST_FILE, | ||
) | ||
assert exc_info.type is Exception | ||
assert "Cannot open" in str(exc_info.value) | ||
|
||
clean_test_file() | ||
clean_samples_folder_copy() | ||
|
||
|
||
clean_samples_folder_copy() | ||
clean_test_file() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters