Skip to content

Comments

[WIP][java][mmlspark] speed up inference by ~20% in java layer#3159

Closed
imatiach-msft wants to merge 1 commit intomicrosoft:masterfrom
imatiach-msft:ilmat/speedup-inference
Closed

[WIP][java][mmlspark] speed up inference by ~20% in java layer#3159
imatiach-msft wants to merge 1 commit intomicrosoft:masterfrom
imatiach-msft:ilmat/speedup-inference

Conversation

@imatiach-msft
Copy link
Contributor

Speed up inference by returning java array from LGBM_BoosterPredictForMatSingle and LGBM_BoosterPredictForCSRSingle. This reduces JNI calls when getting the values from the array and also removes one step to allocate the output array in the Java side, removing another JNI call.

Testing in mmlspark, time was reduced from 82159416923ns to 65852779813ns, ~20% improvement.

FYI @eisber

jenv->ReleasePrimitiveArrayCritical(data, data0, JNI_ABORT);

if (ret != 0) {
return nullptr;
Copy link
Contributor Author

@imatiach-msft imatiach-msft Jun 11, 2020

Choose a reason for hiding this comment

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

looks like I need to delete before returning here in case of error

delete[] out_result;

Copy link
Contributor

Choose a reason for hiding this comment

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

can you use

vector<double> data0;
data0.resize(*out_len);

this will get you RAII behavior for errors (exceptions,...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great idea

@imatiach-msft imatiach-msft changed the title [java][mmlspark] speed up inference by ~20% in java layer WIP [java][mmlspark] speed up inference by ~20% in java layer Jun 19, 2020
@imatiach-msft imatiach-msft changed the title WIP [java][mmlspark] speed up inference by ~20% in java layer [WIP][java][mmlspark] speed up inference by ~20% in java layer Jun 19, 2020
@AlbertoEAF
Copy link
Contributor

AlbertoEAF commented Jul 4, 2020

One question @imatiach-msft - why not reuse the array instead of allocating a new one each time?

I have another extremely fast high-throughput low-latency implementation that is already in production and uses this functions and instead reuses the array *out_result for every call, meaning you only have to read the values, and no allocations are necessary. Isn't this new change going to make it slower than that solution?

@imatiach-msft
Copy link
Contributor Author

@AlbertoEAF great point, I am investigating that as well, note this is still WIP. Sorry haven't had more time to look into this lately. I did discover an issue in how I was calculating the speedup, so this isn't quite ready yet.

@jameslamb
Copy link
Collaborator

Whenever you have time, can you please merge in master? Some changes have been made to our CI jobs to fix failures there. I apologize for the inconvenience.

@guolinke
Copy link
Collaborator

guolinke commented Sep 3, 2020

@imatiach-msft
What is the status of this PR?
do you have a plan for it?

@imatiach-msft
Copy link
Contributor Author

imatiach-msft commented Sep 3, 2020

@guolinke yes, I will work on it again when I have time, let me close it for now

@github-actions
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants