This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Improve inference performance with loaded TransformerChain ML.NET model #371
Open
najeeb-kazmi
wants to merge
4
commits into
microsoft:master
Choose a base branch
from
najeeb-kazmi:model-loading
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7adb78e
Improve performance pf inferencing with ML.NET models loaded into Pip…
najeeb-kazmi d142639
Handle predictions without PredictedLabel column
najeeb-kazmi d797de1
Merge branch 'master' into model-loading
najeeb-kazmi aa10245
Add small model and test
najeeb-kazmi 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 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 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 |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
import numpy as np | ||
import pandas as pd | ||
|
||
from nimbusml import Pipeline | ||
from nimbusml import FileDataStream, Pipeline | ||
from nimbusml.datasets import get_dataset | ||
from nimbusml.feature_extraction.categorical import OneHotVectorizer | ||
from nimbusml.linear_model import FastLinearBinaryClassifier, OnlineGradientDescentRegressor | ||
|
@@ -33,6 +33,8 @@ | |
(train, label) = get_X_y(train_file, label_column, sep=',') | ||
(test, test_label) = get_X_y(test_file, label_column, sep=',') | ||
|
||
mlnet_model = os.path.join(os.path.dirname(__file__), '..', 'utils', 'models', 'UciAdultMlNetModel.zip') | ||
|
||
def get_temp_file(suffix=None): | ||
fd, file_name = tempfile.mkstemp(suffix=suffix) | ||
fl = os.fdopen(fd, 'w') | ||
|
@@ -148,6 +150,12 @@ def test_model_datastream(self): | |
|
||
os.remove(model_filename) | ||
|
||
def test_mlnet_model_can_be_scored(self): | ||
data = FileDataStream.read_csv(test_file, sep=',', numeric_dtype=np.float32) | ||
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. ML.NET model is trained on a file with label, and it expects label to be present in the schema of the data being passed to |
||
model = Pipeline() | ||
model.load_model(mlnet_model) | ||
model.predict(data) | ||
|
||
def test_pipeline_saves_complete_model_file_when_pickled(self): | ||
model_nimbusml = Pipeline( | ||
steps=[ | ||
|
Binary file not shown.
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.
How much is perf gain? If its not much I would like to leave this as it is. Reason is that we actually should move to new ML.NET format so then this will be broken with your new fix
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.
6% gain, with
.predict
called on 100 row UCI Adult test data, in a 100 rep for loop, repeated 5 times.I think we should take the change. (1) If we leave it as it is, it will still be broken when NimbusML moves to new ML.NET format, and how the graph is constructed will need to change anyway. (2) Moving to new ML.NET format will likely take a long time, as it requires non-trivial changes to how model loading is handled in the entrypoints infrastructure on ML.NET side i.e. new model implementation in addition to
PredictorModel
andTransformModel
. (3) The changes directly below this address an issue wherePredictedLabel
column is only converted to int32 from bool if it exists (i.e. it is not regression or ranking) and if the dtype is bool (i.e. if it is Binary classification).