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

notebook_documentation #66

Merged
merged 2 commits into from
Jan 20, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ venv.bak/
all-MiniLM-L6-v2_torchscript_sentence-transformer.zip
# torch generated files
tests/test_SentenceTransformerModel
tests/ml_commons/test_model_files
docs/source/examples/synthetic_queries
402 changes: 402 additions & 0 deletions demo_ml_commons_integration.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/requirements-docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pandas>=1.5,<2
matplotlib>=3.6.0,<4
nbval
sphinx
sphinx-rtd-theme
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are the two packages with similar names both requires?
sphinx-rtd-theme
sphinx_rtd_theme

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part I'm not exactly sure. You can see two different installation instruction:

  1. https://sphinx-rtd-theme.readthedocs.io/en/stable/installing.html
  2. https://pypi.org/project/sphinx-rtd-theme/

And I'm seeing bit different output than my end. So for which I just wanted to give a try with installing both.

sphinx_rtd_theme
nbsphinx
pandoc
Expand Down
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"sphinx.ext.viewcode",
"nbsphinx",
"sphinx.ext.todo",
"sphinx_rtd_theme",
]


Expand Down
415 changes: 415 additions & 0 deletions docs/source/examples/demo_ml_commons_integration.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/source/examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ Examples
demo_notebook
online_retail_analysis
demo_transformer_model_train_save_upload_to_openSearch
demo_ml_commons_integration
63 changes: 19 additions & 44 deletions opensearch_py_ml/ml_commons/ml_commons_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,44 +32,44 @@ def upload_model(
) -> str:
"""
This method uploads model into opensearch cluster using ml-common plugin's api.

first this method creates a model id to store model metadata and then breaks the model zip file into
multiple chunks and then upload chunks into opensearch cluster.
multiple chunks and then upload chunks into opensearch cluster

Parameters
----------
:param model_path: path of the zip file of the model
:type model_path: string
:param model_config_path: filepath of the model metadata. A json file of model metadata is expected
Model metadata format example:
{
"name": "all-MiniLM-L6-v2",
"version": 1,
"model_format": "TORCH_SCRIPT",
"model_config": {
"model_type": "bert",
"embedding_dimension": 384,
"framework_type": "sentence_transformers",
},
}

refer to:
https://opensearch.org/docs/latest/ml-commons-plugin/model-serving-framework/#upload-model-to-opensearch
:type model_config_path: string
:param isVerbose: if isVerbose is true method will print more messages. default False
:type isVerbose: boolean

Returns
-------
:return: returns the model_id so that we can use this for further operation.
:rtype: string

"""

return self._model_uploader._upload_model(
model_path, model_config_path, isVerbose
)

def load_model(self, model_id: str) -> object:
"""
This method loads model into opensearch cluster using ml-common plugin's load model api.
This method loads model into opensearch cluster using ml-common plugin's load model api

Parameters
----------
:param model_id: unique id of the model
:type model_id: string

Returns
-------
:return: returns a json object, with task_id and status key.
:rtype: object

"""

API_URL = f"{ML_BASE_URI}/models/{model_id}/_load"
Expand All @@ -82,15 +82,10 @@ def load_model(self, model_id: str) -> object:
def get_task_info(self, task_id: str) -> object:
"""
This method return information about a task running into opensearch cluster (using ml commons api)
when we load a model.
when we load a model

Parameters
----------
:param task_id: unique id of the task
:type task_id: string

Returns
-------
:return: returns a json object, with detailed information about the task
:rtype: object
"""
Expand All @@ -104,15 +99,10 @@ def get_task_info(self, task_id: str) -> object:

def get_model_info(self, model_id: str) -> object:
"""
This method return information about a model uploaded into opensearch cluster (using ml commons api).
This method return information about a model uploaded into opensearch cluster (using ml commons api)

Parameters
----------
:param model_id: unique id of the model
:type model_id: string

Returns
-------
:return: returns a json object, with detailed information about the model
:rtype: object
"""
Expand All @@ -128,15 +118,10 @@ def generate_embedding(self, model_id: str, sentences: List[str]) -> object:
"""
This method return embedding for given sentences (using ml commons _predict api)

Parameters
----------
:param model_id: unique id of the nlp model
:type model_id: string
:param sentences: List of sentences
:type sentences: list of string

Returns
-------
:return: returns a json object `inference_results` which is a list of embedding results of given sentences
every item has 4 properties: name, data_type, shape, data (embedding value)
:rtype: object
Expand All @@ -156,15 +141,10 @@ def unload_model(self, model_id: str, node_ids: List[str] = []) -> object:
"""
This method unloads a model from all the nodes or from the given list of nodes (using ml commons _unload api)

Parameters
----------
:param model_id: unique id of the nlp model
:type model_id: string
:param node_ids: List of nodes
:type node_ids: list of string

Returns
-------
:return: returns a json object with defining from which nodes the model has unloaded.
:rtype: object
"""
Expand All @@ -187,15 +167,10 @@ def unload_model(self, model_id: str, node_ids: List[str] = []) -> object:
def delete_model(self, model_id: str) -> object:

"""
This method deletes a model from opensearch cluster (using ml commons api).
This method deletes a model from opensearch cluster (using ml commons api)

Parameters
----------
:param model_id: unique id of the model
:type model_id: string

Returns
-------
:return: returns a json object, with detailed information about the deleted model
:rtype: object
"""
Expand Down
5 changes: 0 additions & 5 deletions opensearch_py_ml/ml_commons/model_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ def _upload_model(
first this method creates a model id to store model metadata and then breaks the model zip file into
multiple chunks and then upload chunks into cluster.

Parameters
----------
:param model_path: path of the zip file of the model
:type model_path: string
:param model_meta_path:
Expand All @@ -72,9 +70,6 @@ def _upload_model(
:type model_meta_path: string
:param isVerbose: if isVerbose is true method will print more messages
:type isVerbose: bool

Returns
-------
:return: returns model id which is created by the model metadata
:rtype: string
"""
Expand Down
Loading