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

[jvm-packages] Removing synchronized predict #6021

Closed

Conversation

viswanathk
Copy link

predict method is now thread safe, so the predict method need not be synchronized. There's nothing else that maintains state in the Java world.

cc: @CodingCat

@viswanathk viswanathk changed the title Removing synchronized predict [jvm-packages] Removing synchronized predict Aug 17, 2020
Copy link
Member

@CodingCat CodingCat left a comment

Choose a reason for hiding this comment

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

this LGTM

@trivialfis do we still have to be locked in c++ layer when doing prediction? and is the fix for the problem mentioned in #5272 also applying to the normal prediction method (or we have to use in_place_pred? )

@trivialfis
Copy link
Member

trivialfis commented Aug 17, 2020

@CodingCat

Inplace prediction is not used during training. For training it's always predicting on DMatrix.

do we still have to be locked in c++ layer when doing prediction

Yes. Only inplace prediction is lock free at the moment. Normal prediction can be made to lock free, but it might create some overhead during training as there's a work space for prediction (should be minor). From my perspective, for low latency/low memory usage prediction inplace predict is a better choice, so I didn't try to clear the lock for normal predict.

and is the fix for the problem mentioned in #5272 also applying to the normal prediction method

The fix was for normal prediction, as there's no cache for inplace predict right now. I restructured the cache implementation. So training from checkpoint should not have any issue.

@trivialfis
Copy link
Member

Could you please rebase the branch to master?

@CodingCat
Copy link
Member

@trivialfis

for xgb-spark, we are calling normal prediction, so it is eventually locked? not sure if removing synchronize can bring much improvements

I restructured the cache implementation. So training from checkpoint should not have any issue.

IIUC, so now the normal prediction will not go over all trees even without a prediction cache?

@trivialfis
Copy link
Member

for xgb-spark, we are calling normal prediction, so it is eventually locked?

Yes.

not sure if removing synchronize can bring much improvements

Removing a lock in language binding is still an improvement as it's a duplicated lock.

IIUC, so now the normal prediction will not go over all trees even without a prediction cache?

It will rebuild the cache on first iteration, then works as usual.

@viswanathk viswanathk force-pushed the multithreaded-java-predict branch from e276339 to 36d0dd7 Compare August 20, 2020 17:11
@viswanathk
Copy link
Author

for xgb-spark, we are calling normal prediction, so it is eventually locked? not sure if removing synchronize can bring much improvements

Yeah. I did not know there's a lock internally for predict, so this won't give as much performance boost. Removing it still makes sense though, in case there's a future expensive op before the lock, Java client will benefit from it.

@trivialfis Rebased.

@trivialfis
Copy link
Member

Thanks, best scenario would be having inplace predict implemented for java. Just that I'm not familiar with the language's ecosystem so not sure what data to support.

@trivialfis
Copy link
Member

Okay, the prediction contribution is not thread safe ...

@viswanathk viswanathk closed this Aug 25, 2020
@trivialfis
Copy link
Member

I will make that function thread safe later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants