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 Batch Prediction Mode in the Connector Framework for batch inference #2661

Merged
merged 7 commits into from
Jul 22, 2024

Conversation

Zhangxunmt
Copy link
Collaborator

@Zhangxunmt Zhangxunmt commented Jul 16, 2024

Description

Add the batch mode in the connector to support offline batch inference.

POST /_plugins/_ml/connectors/_create
{
 ...
"actions": [
    {
      "action_type": "predict",
      "method": "POST",
      "headers": {
        "content-type": "application/json"
      },
      "url": <your realtime endpoint url>,
      "request_body": "${parameters.input}",
      "pre_process_function": "connector.pre_process.default.embedding",
      "post_process_function": "connector.post_process.default.embedding"
    },
    {
        "action_type": "batch",
        "method": "POST",
        "headers": {
            "content-type": "application/json"
        },
        "url": "https://api.sagemaker.<your region>.amazonaws.com/CreateTransformJob",
        "request_body": "{ \"BatchStrategy\": \"${parameters.BatchStrategy}\", \"ModelName\": \"${parameters.ModelName}\", \"DataProcessing\" : ${parameters.DataProcessing}, \"TransformInput\": ${parameters.TransformInput}, \"TransformJobName\" : \"${parameters.TransformJobName}\", \"TransformOutput\" : ${parameters.TransformOutput}, \"TransformResources\" : ${parameters.TransformResources}}"
    }
  ]
}

Invoke the offline mode batch prediction

POST /_plugins/_ml/models/dBK3t5ABrxVhHgFYhg7Q/_batch_prediction
{
  "parameters": {
    "TransformJobName": "unique name"
  }
}

Invoke the realtime predict

POST /_plugins/_ml/models/dBK3t5ABrxVhHgFYhg7Q/_predict
{
  "parameters": {
    "input" : ["test1", "test2"]
  }
}

Issues Resolved

#2488

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

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.

@Zhangxunmt Zhangxunmt temporarily deployed to ml-commons-cicd-env July 16, 2024 23:40 — with GitHub Actions Inactive
@Zhangxunmt Zhangxunmt temporarily deployed to ml-commons-cicd-env July 16, 2024 23:53 — with GitHub Actions Inactive
@Zhangxunmt Zhangxunmt temporarily deployed to ml-commons-cicd-env July 16, 2024 23:53 — with GitHub Actions Inactive
@Zhangxunmt Zhangxunmt temporarily deployed to ml-commons-cicd-env July 17, 2024 00:50 — with GitHub Actions Inactive
@Zhangxunmt Zhangxunmt temporarily deployed to ml-commons-cicd-env July 20, 2024 00:25 — with GitHub Actions Inactive
@Zhangxunmt Zhangxunmt temporarily deployed to ml-commons-cicd-env July 20, 2024 00:25 — with GitHub Actions Inactive
@Zhangxunmt Zhangxunmt temporarily deployed to ml-commons-cicd-env July 20, 2024 01:23 — with GitHub Actions Inactive
@Zhangxunmt Zhangxunmt temporarily deployed to ml-commons-cicd-env July 22, 2024 20:44 — with GitHub Actions Inactive
@Zhangxunmt Zhangxunmt temporarily deployed to ml-commons-cicd-env July 22, 2024 20:44 — with GitHub Actions Inactive
@Zhangxunmt Zhangxunmt temporarily deployed to ml-commons-cicd-env July 22, 2024 20:45 — with GitHub Actions Inactive
@Zhangxunmt Zhangxunmt temporarily deployed to ml-commons-cicd-env July 22, 2024 20:45 — with GitHub Actions Inactive
@Zhangxunmt Zhangxunmt added backport 2.x v2.16.0 Issues targeting release v2.16.0 labels Jul 22, 2024
@@ -124,11 +127,13 @@ public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client
@VisibleForTesting
MLPredictionTaskRequest getRequest(String modelId, String algorithm, RestRequest request) throws IOException {
ActionType actionType = ActionType.from(getActionTypeFromRestRequest(request));
System.out.println("actionType is " + actionType);
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove this? or use log?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Already removed. But don't want to waste time running CI again. Will include the removal in my next PR.

if (FunctionName.REMOTE.name().equals(algorithm) && !mlFeatureEnabledSetting.isRemoteInferenceEnabled()) {
throw new IllegalStateException(REMOTE_INFERENCE_DISABLED_ERR_MSG);
} else if (FunctionName.isDLModel(FunctionName.from(algorithm.toUpperCase())) && !mlFeatureEnabledSetting.isLocalModelEnabled()) {
throw new IllegalStateException(LOCAL_MODEL_DISABLED_ERR_MSG);
} else if (!ActionType.isValidActionInModelPrediction(actionType)) {
System.out.println(actionType.toString());
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here?

@Zhangxunmt Zhangxunmt merged commit 39efbe7 into opensearch-project:main Jul 22, 2024
7 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.x 2.x
# Navigate to the new working tree
cd .worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-2661-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 39efbe7eda14b995f8c14a1ece06c7eabc453cd2
# Push it to GitHub
git push --set-upstream origin backport/backport-2661-to-2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-2661-to-2.x.

Zhangxunmt added a commit to Zhangxunmt/ml-commons that referenced this pull request Jul 22, 2024
…nce (opensearch-project#2661)

* add batch predict job actiontype in connector

Signed-off-by: Xun Zhang <[email protected]>

* remove async and streaming mode temporarily

Signed-off-by: Xun Zhang <[email protected]>

* rename predict mode to action type

Signed-off-by: Xun Zhang <[email protected]>

* use method name in the url path for action type

Signed-off-by: Xun Zhang <[email protected]>

* add stats for actionType and more UTs

Signed-off-by: Xun Zhang <[email protected]>

* add bwx for actiontype

Signed-off-by: Xun Zhang <[email protected]>

* address more comments

Signed-off-by: Xun Zhang <[email protected]>

---------

Signed-off-by: Xun Zhang <[email protected]>
@Zhangxunmt Zhangxunmt temporarily deployed to ml-commons-cicd-env July 22, 2024 21:45 — with GitHub Actions Inactive
Zhangxunmt added a commit that referenced this pull request Jul 22, 2024
…nce (#2661) (#2701)

* add batch predict job actiontype in connector



* remove async and streaming mode temporarily



* rename predict mode to action type



* use method name in the url path for action type



* add stats for actionType and more UTs



* add bwx for actiontype



* address more comments



---------

Signed-off-by: Xun Zhang <[email protected]>
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jul 22, 2024
…nce (#2661) (#2701)

* add batch predict job actiontype in connector

* remove async and streaming mode temporarily

* rename predict mode to action type

* use method name in the url path for action type

* add stats for actionType and more UTs

* add bwx for actiontype

* address more comments

---------

Signed-off-by: Xun Zhang <[email protected]>
(cherry picked from commit 310d023)
b4sjoo pushed a commit that referenced this pull request Jul 23, 2024
…nce (#2661) (#2701) (#2705)

* add batch predict job actiontype in connector

* remove async and streaming mode temporarily

* rename predict mode to action type

* use method name in the url path for action type

* add stats for actionType and more UTs

* add bwx for actiontype

* address more comments

---------

Signed-off-by: Xun Zhang <[email protected]>
(cherry picked from commit 310d023)

Co-authored-by: Xun Zhang <[email protected]>
mingshl pushed a commit to mingshl/ml-commons that referenced this pull request Jul 24, 2024
…nce (opensearch-project#2661)

* add batch predict job actiontype in connector

Signed-off-by: Xun Zhang <[email protected]>

* remove async and streaming mode temporarily

Signed-off-by: Xun Zhang <[email protected]>

* rename predict mode to action type

Signed-off-by: Xun Zhang <[email protected]>

* use method name in the url path for action type

Signed-off-by: Xun Zhang <[email protected]>

* add stats for actionType and more UTs

Signed-off-by: Xun Zhang <[email protected]>

* add bwx for actiontype

Signed-off-by: Xun Zhang <[email protected]>

* address more comments

Signed-off-by: Xun Zhang <[email protected]>

---------

Signed-off-by: Xun Zhang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x v2.16.0 Issues targeting release v2.16.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants