Optimize Lossguide#2835
Conversation
merge catboost to levachev/catboost
|
Optimizing Lossguide with the subtract trick. When testing, it was found that the result will be different(compared to the master version) if you do not set the parameters of CatBoostRegressor |
| const TTrainingDataProviders& data, | ||
| const TFold& fold, | ||
| ui32 oneHotMaxSize | ||
| const TTrainingDataProviders& data, |
There was a problem hiding this comment.
please restore indentation -- once this is done, i will get back with more comments
|
@Evgueni-Petrov-aka-espetrov restore indentation complete |
|
Minor Nit: The PR description is very brief. Given this is a significant algorithmic optimization replacing the previous |
|
@a-holm |
|
@Levachev very cool! Thank you |
| return; | ||
| } | ||
| auto candidatesContextsLeftLeaf = SelectFeaturesForScoring(data, {}, fold, ctx); | ||
| auto candidatesContextsRightLeaf = SelectFeaturesForScoring(data, {}, fold, ctx); |
There was a problem hiding this comment.
this should be identical to candidatesContextsLeftLeaf
could we use copy instead of calling SelectFeaturesForScoring?
| } | ||
| }; | ||
|
|
||
| const auto findBestCandidate = [&](TIndexType leftLeaf, TIndexType rightLeaf, const std::shared_ptr<TVector<TBucketStats>> &parent) { |
There was a problem hiding this comment.
please make this a normal static function to improve readability
| const TCandidateInfo* bestSplitCandidate = nullptr; | ||
| const double scoreBeforeSplit = CalcScoreWithoutSplit(leaf, *fold, *ctx); | ||
| SelectBestCandidate(data, *ctx, candidatesContexts, maxFeatureValueCount, *fold, scoreBeforeSplit, &bestScore, &bestSplitCandidate); | ||
| fold->DropEmptyCTRs(); |
There was a problem hiding this comment.
why does not optimized GreedyTensorSearchLossguide call DropEmptyCTRs anywhere?
it may free some memory
| fold, | ||
| ctx); | ||
| const size_t maxFeatureValueCount = CalcMaxFeatureValueCount(*fold, candidatesContexts); | ||
| CheckInterrupted(); // check after long-lasting operation |
There was a problem hiding this comment.
why does not optimized GreedyTensorSearchLossguide call CheckInterrupted anywhere?
this call is needed to ensure catboost can be interrupted here
| const bool needSplitLeftLeaf = leafDepth[leftLeaf] < ctx->Params.ObliviousTreeOptions->MaxDepth | ||
| && leftLeafBoundsSize >= ctx->Params.ObliviousTreeOptions->MinDataInLeaf; |
There was a problem hiding this comment.
please store max depth and min data in leaf in some variables to avoid code duplication
| *parent); | ||
|
|
||
| } else { | ||
| if(needSplitLeftLeaf) { |
There was a problem hiding this comment.
need space after if -- please check everywhere
| &rightLeafBestSplitCandidate, | ||
| &rightLeafBestSplit, | ||
| *parent); | ||
|
|
There was a problem hiding this comment.
pls remove empty line
| &rightLeafGain, | ||
| &rightLeafBestSplitCandidate, | ||
| &rightLeafBestSplit); | ||
| leftLeafStats = CalculateWithSubtractTrickNoParentQueue( |
There was a problem hiding this comment.
pls insert empty line before leftLeafStats
| &leftLeafBestSplitCandidate, | ||
| &leftLeafBestSplit, | ||
| *parent); | ||
|
|
There was a problem hiding this comment.
pls remove empty line
| TVector<TBucketStats> leftLeafStats; | ||
| TVector<TBucketStats> rightLeafStats; | ||
|
|
||
| if ((leftLeafBoundsSize <= rightLeafBoundsSize) && isSubtractTrickAllowed && needSplitLeftLeaf && needSplitRightLeaf) { |
There was a problem hiding this comment.
please structure as follows for better readability
if (isSubtractTrickAllowed && needSplitLeftLeaf && needSplitRightLeaf) {
if (leftLeafBoundsSize <= rightLeafBoundsSize) {
// ...
} else {
// ...
}
} else {
if (needSplitLeftLeaf) {
// ...
}
if (needSplitRightLeaf) {
// ...
}
}|
I hereby agree to the terms of the CLA available at: link. |
| auto leftLeafStatsPtr = MakeSimpleShared<TVector<TBucketStats>>(leftLeafStats); | ||
| auto rightLeafStatsPtr = MakeSimpleShared<TVector<TBucketStats>>(rightLeafStats); |
There was a problem hiding this comment.
please avoid unnecessary copy here and in findBestCandidateRoot as follows
leftLeafStatsPtr = MakeSimpleShared<TVector<TBucketStats>>();
leftLeafStatsPtr->swap(leftLeafStats);|
Since this optim reorders summation of derivatives, canonical outputs of pytest and python-package/ut/medium will change for Lossguide. |
|
Shipped! |
Optimize Lossguide with subtract trick