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

Add model interface support for remote and local custom models #701

Merged
merged 4 commits into from
May 3, 2024

Conversation

joshpalis
Copy link
Member

Description

Adds support for the interface field of model registration. Currently only adding support for the register_remote_model and register_local_custom_model since pretrained/ local sparse encoding models do not currently work with the model interface.

Registering and deploying remote model with model interface :

curl -i -XPOST "localhost:9200/_plugins/_flow_framework/workflow?provision=true" -H "Content-Type:application/json" --data '{"name":"createconnector-registerremotemodel-deploymodel","description":"test case","use_case":"TEST_CASE","version":{"template":"1.0.0","compatibility":["2.12.0","3.0.0"]},"workflows":{"provision":{"nodes":[{"id":"workflow_step_1","type":"create_connector","user_inputs":{"name":"OpenAI Chat Connector","description":"The connector to public OpenAI model service for GPT 3.5","version":"1","protocol":"http","parameters":{"endpoint":"api.openai.com","model":"gpt-3.5-turbo"},"credential":{"openAI_key":"12345"},"actions":[{"action_type":"predict","method":"POST","url":"https://${parameters.endpoint}/v1/chat/completions"}]}},{"id":"workflow_step_2","type":"register_remote_model","previous_node_inputs":{"workflow_step_1":"connector_id"},"user_inputs":{"name":"openAI-gpt-3.5-turbo","description":"test model","interface":{"input":{"properties":{"parameters":{"properties":{"messages":{"type":"string","description":"This is a test description field"}}}}},"output":{"properties":{"inference_results":{"type":"array","items":{"type":"object","properties":{"output":{"type":"array","items":{"properties":{"name":{"type":"string","description":"This is a test description field"},"dataAsMap":{"type":"object","description":"This is a test description field"}}},"description":"This is a test description field"},"status_code":{"type":"integer","description":"This is a test description field"}}},"description":"This is a test description field"}}}},"deploy":true,"node_timeout":"15s"}}]}}}'
HTTP/1.1 201 Created
X-OpenSearch-Version: OpenSearch/3.0.0-SNAPSHOT (opensearch)
content-type: application/json; charset=UTF-8
content-length: 38

{"workflow_id":"gNg7O48BaP6uKfWC1aKh"}

curl -i -XGET "http://localhost:9200/_plugins/_ml/models/hNg7O48BaP6uKfWC2qJv?pretty"
HTTP/1.1 200 OK
X-OpenSearch-Version: OpenSearch/3.0.0-SNAPSHOT (opensearch)
content-type: application/json; charset=UTF-8
content-length: 1318

{
  "name" : "openAI-gpt-3.5-turbo",
  "model_group_id" : "gtg7O48BaP6uKfWC2aJg",
  "algorithm" : "REMOTE",
  "model_version" : "1",
  "description" : "test model",
  "model_state" : "DEPLOYED",
  "created_time" : 1714685729273,
  "last_updated_time" : 1714685729735,
  "last_deployed_time" : 1714685729734,
  "auto_redeploy_retry_times" : 0,
  "planning_worker_node_count" : 1,
  "current_worker_node_count" : 1,
  "planning_worker_nodes" : [
    "TpCVBoolSOCJOR4dkq66ng"
  ],
  "deploy_to_all_nodes" : true,
  "is_hidden" : false,
  "connector_id" : "gdg7O48BaP6uKfWC2KIR",
  "interface" : {
    "output" : "{\"properties\":{\"inference_results\":{\"description\":\"This is a test description field\",\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"output\":{\"description\":\"This is a test description field\",\"type\":\"array\",\"items\":{\"properties\":{\"name\":{\"description\":\"This is a test description field\",\"type\":\"string\"},\"dataAsMap\":{\"description\":\"This is a test description field\",\"type\":\"object\"}}}},\"status_code\":{\"description\":\"This is a test description field\",\"type\":\"integer\"}}}}}}",
    "input" : "{\"properties\":{\"parameters\":{\"properties\":{\"messages\":{\"description\":\"This is a test description field\",\"type\":\"string\"}}}}}"
  }
}

For registering and deploying local custom model :

curl -i -XPOST "localhost:9200/_plugins/_flow_framework/workflow?provision=true" -H "Content-Type:application/json" --data '{"name":"registermodelgroup-registerlocalmodel-deploymodel","description":"test case","use_case":"TEST_CASE","version":{"template":"1.0.0","compatibility":["2.12.0","3.0.0"]},"workflows":{"provision":{"nodes":[{"id":"workflow_step_1","type":"register_local_custom_model","user_inputs":{"node_timeout":"60s","name":"all-MiniLM-L6-v2","version":"1.0.0","description":"test model","model_format":"TORCH_SCRIPT","function_name":"SPARSE_TOKENIZE","model_content_hash_value":"c15f0d2e62d872be5b5bc6c84d2e0f4921541e29fefbef51d59cc10a8ae30e0f","model_type":"bert","embedding_dimension":"384","framework_type":"sentence_transformers","all_config":"{\"_name_or_path\":\"nreimers/MiniLM-L6-H384-uncased\",\"architectures\":[\"BertModel\"],\"attention_probs_dropout_prob\":0.1,\"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\":6,\"pad_token_id\":0,\"position_embedding_type\":\"absolute\",\"transformers_version\":\"4.8.2\",\"type_vocab_size\":2,\"use_cache\":true,\"vocab_size\":30522}","url":"https://artifacts.opensearch.org/models/ml-models/huggingface/sentence-transformers/all-MiniLM-L6-v2/1.0.1/torch_script/sentence-transformers_all-MiniLM-L6-v2-1.0.1-torch_script.zip","interface":{"input":{"properties":{"text_docs":{"type":"array"},"return_number":{"type":"boolean"},"target_response":{"type":"array"}}}}}},{"id":"workflow_step_2","type":"deploy_model","previous_node_inputs":{"workflow_step_1":"model_id"}}],"edges":[{"source":"workflow_step_1","dest":"workflow_step_2"}]}}}'
HTTP/1.1 201 Created
X-OpenSearch-Version: OpenSearch/3.0.0-SNAPSHOT (opensearch)
content-type: application/json; charset=UTF-8
content-length: 38

{"workflow_id":"lch-O48BUXkJrbtALpC3"}

curl -i -XGET "http://localhost:9200/_plugins/_ml/models/mMh-O48BUXkJrbtAMZCk?pretty"
HTTP/1.1 200 OK
X-OpenSearch-Version: OpenSearch/3.0.0-SNAPSHOT (opensearch)
content-type: application/json; charset=UTF-8
content-length: 1687

{
  "name" : "all-MiniLM-L6-v2",
  "model_group_id" : "lsh-O48BUXkJrbtAMJCA",
  "algorithm" : "SPARSE_TOKENIZE",
  "model_version" : "1",
  "description" : "test model",
  "model_format" : "TORCH_SCRIPT",
  "model_state" : "DEPLOYED",
  "model_content_size_in_bytes" : 91790008,
  "model_content_hash_value" : "c15f0d2e62d872be5b5bc6c84d2e0f4921541e29fefbef51d59cc10a8ae30e0f",
  "model_config" : {
    "model_type" : "bert",
    "embedding_dimension" : 384,
    "framework_type" : "SENTENCE_TRANSFORMERS",
    "all_config" : "{\"_name_or_path\":\"nreimers/MiniLM-L6-H384-uncased\",\"architectures\":[\"BertModel\"],\"attention_probs_dropout_prob\":0.1,\"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\":6,\"pad_token_id\":0,\"position_embedding_type\":\"absolute\",\"transformers_version\":\"4.8.2\",\"type_vocab_size\":2,\"use_cache\":true,\"vocab_size\":30522}"
  },
  "created_time" : 1714690076965,
  "last_updated_time" : 1714690083895,
  "last_registered_time" : 1714690081144,
  "last_deployed_time" : 1714690083894,
  "auto_redeploy_retry_times" : 0,
  "total_chunks" : 10,
  "planning_worker_node_count" : 1,
  "current_worker_node_count" : 1,
  "planning_worker_nodes" : [
    "zTtalEMSTRGrYfx29Gh4sQ"
  ],
  "deploy_to_all_nodes" : true,
  "is_hidden" : false,
  "interface" : {
    "input" : "{\"properties\":{\"target_response\":{\"type\":\"array\"},\"return_number\":{\"type\":\"boolean\"},\"text_docs\":{\"type\":\"array\"}}}"
  }
}

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@github-actions github-actions bot added the backport 2.x backport PRs to 2.x branch label May 2, 2024
Signed-off-by: Joshua Palis <[email protected]>
Copy link

codecov bot commented May 2, 2024

Codecov Report

Attention: Patch coverage is 61.11111% with 14 lines in your changes are missing coverage. Please review.

Project coverage is 74.44%. Comparing base (40d9efc) to head (ef3db97).

Files Patch % Lines
...ework/workflow/AbstractRegisterLocalModelStep.java 8.33% 10 Missing and 1 partial ⚠️
.../org/opensearch/flowframework/util/ParseUtils.java 77.77% 1 Missing and 1 partial ⚠️
...g/opensearch/flowframework/model/WorkflowNode.java 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #701      +/-   ##
============================================
- Coverage     74.56%   74.44%   -0.13%     
- Complexity      735      738       +3     
============================================
  Files            83       83              
  Lines          3708     3741      +33     
  Branches        318      322       +4     
============================================
+ Hits           2765     2785      +20     
- Misses          800      811      +11     
- Partials        143      145       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

…INTERFACE to INTERFACE_FIELD, adding parse util test

Signed-off-by: Joshua Palis <[email protected]>
@amitgalitz
Copy link
Member

Instead of relaying on customer to escape strings and having to figure out how to give that user input we can use ParseUtils.parseArbitraryStringToObjectMapToString(configurationsMap); like we do for create index and pipelines so we do it for them.

@amitgalitz
Copy link
Member

Instead of relaying on customer to escape strings and having to figure out how to give that user input we can use ParseUtils.parseArbitraryStringToObjectMapToString(configurationsMap); like we do for create index and pipelines so we do it for them.

ignore this comment :)

@dbwiddis dbwiddis merged commit 3318d31 into opensearch-project:main May 3, 2024
31 of 32 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request May 3, 2024
* Add model interface support for remote and local custom models

Signed-off-by: Joshua Palis <[email protected]>

* Adding changelog and javadocs

Signed-off-by: Joshua Palis <[email protected]>

* Addressing PR comments, adding to 2.14 release notes, updating MODEL_INTERFACE to INTERFACE_FIELD, adding parse util test

Signed-off-by: Joshua Palis <[email protected]>

* updating RegisterRemoteModelStepTests

Signed-off-by: Joshua Palis <[email protected]>

---------

Signed-off-by: Joshua Palis <[email protected]>
(cherry picked from commit 3318d31)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
opensearch-trigger-bot bot pushed a commit that referenced this pull request May 3, 2024
* Add model interface support for remote and local custom models

Signed-off-by: Joshua Palis <[email protected]>

* Adding changelog and javadocs

Signed-off-by: Joshua Palis <[email protected]>

* Addressing PR comments, adding to 2.14 release notes, updating MODEL_INTERFACE to INTERFACE_FIELD, adding parse util test

Signed-off-by: Joshua Palis <[email protected]>

* updating RegisterRemoteModelStepTests

Signed-off-by: Joshua Palis <[email protected]>

---------

Signed-off-by: Joshua Palis <[email protected]>
(cherry picked from commit 3318d31)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
joshpalis pushed a commit that referenced this pull request May 3, 2024
…m models (#703)

Add model interface support for remote and local custom models (#701)

* Add model interface support for remote and local custom models



* Adding changelog and javadocs



* Addressing PR comments, adding to 2.14 release notes, updating MODEL_INTERFACE to INTERFACE_FIELD, adding parse util test



* updating RegisterRemoteModelStepTests



---------


(cherry picked from commit 3318d31)

Signed-off-by: Joshua Palis <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
joshpalis pushed a commit that referenced this pull request May 3, 2024
…om models (#704)

Add model interface support for remote and local custom models (#701)

* Add model interface support for remote and local custom models



* Adding changelog and javadocs



* Addressing PR comments, adding to 2.14 release notes, updating MODEL_INTERFACE to INTERFACE_FIELD, adding parse util test



* updating RegisterRemoteModelStepTests



---------


(cherry picked from commit 3318d31)

Signed-off-by: Joshua Palis <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x backport PRs to 2.x branch backport 2.14
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants