-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
[native] [jvm-packages] allow rebuild prediction cache when it is not initialized #5272
Changes from all commits
9dcae64
c6d85ba
c05eb4e
a05f76f
bdbdb3d
13a6da5
3018bfc
3190a69
4b968db
6386306
b34b7e4
b7af1b7
e251401
9b079eb
982ca88
a3ad395
8f1fde3
c70a826
3d8bc33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version=${project.version} | ||
version=${project.version} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,18 +171,25 @@ class CPUPredictor : public Predictor { | |
if (ntree_limit == 0 || ntree_limit > model.trees.size()) { | ||
ntree_limit = static_cast<unsigned>(model.trees.size()); | ||
} | ||
|
||
std::cout << "run PredLoopInternal in PredictBatch\n"; | ||
this->PredLoopInternal(dmat, &out_preds->HostVector(), model, | ||
tree_begin, ntree_limit); | ||
|
||
auto cache_entry = this->FindCache(dmat); | ||
if (cache_entry == cache_->cend()) { | ||
return; | ||
std::cout << "cannot find cache\n"; | ||
if (!generic_param_->adding_all_to_cache || !(*cache_).empty()) { | ||
return; | ||
} else { | ||
std::cout << "adding dmatrix to cache\n"; | ||
(*cache_)[dmat].data = static_cast<std::shared_ptr<DMatrix>>(dmat); | ||
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. I am a bit confused by this line of code. It was quite a while when I last dived into this part of code My C++ is a little bit rusty in regard to static_cast in this context so please feel free to correct me Are you creating a new shared_ptr from the pointer dmat? If so I strongly suggest against. It usually leads to errors. Cause I thought about similar fix but I rejected it cause I did not figure out how to retrieve already existing shared_pt from just DMatrix* (cause I want to have the copy of that reference counting pointer) What I had in mind is changing the interface of Predict to pass shared_ptr in the first place instead of just a raw pointer. That would permit us to recreate a cache 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. I consulted with my C++ friends and they pointed to https://stackoverflow.com/questions/32713083/explicit-constructor-and-static-cast Sooner or later this will result in double free cause each of these smart pointers will try to free the resource. In the end I suggest to wait @trivialfis refactoring. It should enable you (or us) to solve this problem 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. yeah that's why the current unit test broken |
||
return; | ||
} | ||
} | ||
if (cache_entry->second.predictions.Size() == 0) { | ||
// See comment in GPUPredictor::PredictBatch. | ||
InitOutPredictions(cache_entry->second.data->Info(), | ||
&(cache_entry->second.predictions), model); | ||
&(cache_entry->second.predictions), model); | ||
cache_entry->second.predictions.Copy(*out_preds); | ||
} | ||
} | ||
|
@@ -198,6 +205,7 @@ class CPUPredictor : public Predictor { | |
|
||
if (e.predictions.Size() == 0) { | ||
InitOutPredictions(e.data->Info(), &(e.predictions), model); | ||
std::cout << "calling PredLoopInternal in UpdatePredictionCache_1\n"; | ||
PredLoopInternal(e.data.get(), &(e.predictions.HostVector()), model, 0, | ||
model.trees.size()); | ||
} else if (model.learner_model_param_->num_output_group == 1 && updaters->size() > 0 && | ||
|
@@ -206,6 +214,7 @@ class CPUPredictor : public Predictor { | |
&(e.predictions))) { | ||
{} // do nothing | ||
} else { | ||
std::cout << "calling PredLoopInternal in UpdatePredictionCache_2\n"; | ||
PredLoopInternal(e.data.get(), &(e.predictions.HostVector()), model, old_ntree, | ||
model.trees.size()); | ||
} | ||
|
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.
Just do not forget to remove it before merging