Error uploading local model to OS 3.1.0

Hi all,

I am following the guide here Demo Notebook for Sentence Transformer Model Training, Saving and Uploading to OpenSearch — Opensearch-py-ml 1.3.0 documentation to upload a local model to OS 3.1.0 but got the below error. Note that the model is downloaded from the OS pretrained models and stored locally. And btw, I was able to upload via rest api with no issues. I only get this error in the python APIs.

RequestError: RequestError(400, ‘illegal_argument_exception’, ‘embedding dimension is null’)

Below are the python steps:

import opensearch_py_ml as oml
from opensearch_py_ml.ml_commons import MLCommonClient
import warnings
warnings.filterwarnings('ignore', category=DeprecationWarning)
warnings.filterwarnings("ignore", message="Unverified HTTPS request")
import opensearch_py_ml as oml
from opensearchpy import OpenSearch
def get_os_client(cluster_url = "https://localhost:9200",
                  username='admin',
                  password='Usrch2025!'):
    '''
    Get OpenSearch client
    :param cluster_url: cluster URL like https://ml-te-netwo-1s12ba42br23v-ff1736fa7db98ff2.elb.us-west-2.amazonaws.com:443
    :return: OpenSearch client
    '''
    client = OpenSearch(
        hosts=[cluster_url],
        http_auth=(username, password),
        verify_certs=False
    )
    return client
client = get_os_client()
ml_client = MLCommonClient(client)

model_path = r'D:\my-files\work\opensearch-releases\os31\models\all-MiniLM-L12-v2-1.0.2-onnx.zip'
model_config_path = r'D:\my-files\work\opensearch-releases\os31\models\config.json'
ml_client.upload_model( model_path, model_config_path, isVerbose=True)
1 Like

@asfoorial I’ve tested your script with 2.14, 2.19.1, 3.0.0 and 3.1.0. Only 3.1.0 has failed with the reported error.

I think this is related to how we process model config differently in 3.1 (ref). We might need to update the python script, I’ll look further into this

1 Like

Hi @asfoorial Can you try adding "function_name": "TEXT_EMBEDDING" before model_config in your config.json file. This change fixes the issue on my end.

Due to the changes made in this PR, we check for function_name when registering model meta, and if we don’t specify any, it will go to BaseModelConfig, which doesn’t parse embedding_dimension.

Example config.json file:

{
    "name": "sentence-transformers/all-MiniLM-L12-v2",
    "version": "1.0.2",
    "description": "This is a sentence-transformers model: It maps sentences & paragraphs to a 384 dimensional dense vector space and can be used for tasks like clustering or semantic search.",
    "model_format": "TORCH_SCRIPT",
    "model_task_type": "TEXT_EMBEDDING",
    "function_name": "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\": \"sentence-transformers/all-MiniLM-L12-v2\", \"architectures\": [\"BertModel\"], \"attention_probs_dropout_prob\": 0.1, \"classifier_dropout\": null, \"gradient_checkpointing\": false, \"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.49.0\", \"type_vocab_size\": 2, \"use_cache\": true, \"vocab_size\": 30522}",
        "additional_config": {
            "space_type": "l2"
        }
    },
    "model_content_size_in_bytes": 134567916,
    "model_content_hash_value": "fcec1287bfcb1b3b8c965b07b8960c4ac3af11623e04f08e8b06ca37171eda52"
}
2 Likes

@nathhjo I’ve just tested and it worked. Thank you.

1 Like

It works now. Thanks

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.