-
Notifications
You must be signed in to change notification settings - Fork 23
mlflow 2.0 compatibility #97
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
40fce28
Trigger build
shrinath-suresh 650d3ad
MLflow 2.0 fixes
shrinath-suresh ac56dcf
Accuracy fix
shrinath-suresh 707cc88
Merge branch 'master' of https://github.com/mlflow/mlflow-torchserve …
shrinath-suresh 9f7517f
UT fixes
shrinath-suresh 45a17fe
Optimizing imports
shrinath-suresh a0d4450
MNIST UT fix
shrinath-suresh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,26 +1,40 @@ | ||
| import docker | ||
| import json | ||
| import subprocess | ||
| import time | ||
| import logging | ||
| import os | ||
| import pandas as pd | ||
| import torch | ||
| import subprocess | ||
| import time | ||
| from pathlib import Path | ||
|
|
||
| import docker | ||
| import pandas as pd | ||
| import requests | ||
| from mlflow_torchserve.config import Config | ||
|
|
||
| import torch | ||
| from mlflow.deployments import BaseDeploymentClient, get_deploy_client | ||
| from mlflow.tracking.artifact_utils import _download_artifact_from_uri | ||
| from mlflow.deployments import PredictionsResponse | ||
| from mlflow.models.model import Model | ||
| from mlflow.tracking.artifact_utils import _download_artifact_from_uri | ||
|
|
||
| from mlflow_torchserve.config import Config | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
| _DEFAULT_TORCHSERVE_LOCAL_INFERENCE_PORT = "8080" | ||
| _DEFAULT_TORCHSERVE_LOCAL_MANAGEMENT_PORT = "8081" | ||
|
|
||
|
|
||
| class CustomPredictionsResponse(PredictionsResponse): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Do we want to call this
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| def __init__(self, resp): | ||
| super(CustomPredictionsResponse, self).__init__(self) | ||
| self.resp = resp | ||
|
|
||
| def to_json(self, path=None): | ||
| if path is not None: | ||
| with open(path, "w") as f: | ||
| json.dump(self.resp, f) | ||
| else: | ||
| return self.resp | ||
|
|
||
|
|
||
| class TorchServePlugin(BaseDeploymentClient): | ||
| def __init__(self, uri): | ||
|
|
||
|
|
@@ -268,7 +282,6 @@ def predict(self, deployment_name, df): | |
|
|
||
| :return: output - Returns the predicted value | ||
| """ | ||
|
|
||
| url = "{api}/{predictions}/{name}".format( | ||
| api=self.inference_api, predictions="predictions", name=deployment_name | ||
| ) | ||
|
|
@@ -286,14 +299,14 @@ def predict(self, deployment_name, df): | |
| raise ValueError("Unable to parse input json string: {}".format(e)) | ||
|
|
||
| resp = requests.post(url, data) | ||
| cust_resp = CustomPredictionsResponse(resp.text) | ||
| if resp.status_code != 200: | ||
| raise Exception( | ||
| "Unable to infer the results for the name %s. " | ||
| "Server returned status code %s and response: %s" | ||
| % (deployment_name, resp.status_code, resp.content) | ||
| ) | ||
|
|
||
| return resp.text | ||
| return cust_resp | ||
|
|
||
| def explain(self, deployment_name, df): | ||
| """ | ||
|
|
@@ -330,7 +343,6 @@ def explain(self, deployment_name, df): | |
| "Server returned status code %s and response: %s" | ||
| % (deployment_name, resp.status_code, resp.content) | ||
| ) | ||
|
|
||
| return resp.text | ||
|
|
||
| def __generate_mar_file( | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest torchmetrics expects
taskandnum_classesto be passed while usingAccuracy- https://torchmetrics.readthedocs.io/en/stable/classification/accuracy.html