-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tests/profiling] Profile Fast predict methods
Build with -DBUILD_PROFILING_TESTS=ON and copy the default model trained on the Higgs dataset from the benchmarks repo https://github.com/guolinke/boosting_tree_benchmarks.git to LightGBM repo root and run the lightgbm_profile_* binaries. The single instance used is the first row from that dataset.
- Loading branch information
1 parent
d24eabe
commit f299506
Showing
3 changed files
with
66 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <iostream> | ||
#include "LightGBM/c_api.h" | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
cout << "start\n"; | ||
|
||
BoosterHandle boosterHandle; | ||
int num_iterations; | ||
LGBM_BoosterCreateFromModelfile("./LightGBM_model.txt", &num_iterations, &boosterHandle); | ||
cout << "Model iterations " << num_iterations<< "\n"; | ||
|
||
double values[] = {1.000000000000000000e+00,8.692932128906250000e-01,-6.350818276405334473e-01,2.256902605295181274e-01,3.274700641632080078e-01,-6.899932026863098145e-01,7.542022466659545898e-01,-2.485731393098831177e-01,-1.092063903808593750e+00,0.000000000000000000e+00,1.374992132186889648e+00,-6.536741852760314941e-01,9.303491115570068359e-01,1.107436060905456543e+00,1.138904333114624023e+00,-1.578198313713073730e+00,-1.046985387802124023e+00,0.000000000000000000e+00,6.579295396804809570e-01,-1.045456994324922562e-02,-4.576716944575309753e-02,3.101961374282836914e+00,1.353760004043579102e+00,9.795631170272827148e-01,9.780761599540710449e-01,9.200048446655273438e-01,7.216574549674987793e-01,9.887509346008300781e-01,8.766783475875854492e-01}; // score = 0.487278 | ||
|
||
int64_t dummy; | ||
|
||
double score[1]; | ||
for (size_t i = 0; i < 3e5; ++i) { | ||
LGBM_BoosterPredictForMatSingleRow(boosterHandle, values, C_API_DTYPE_FLOAT64, 28, 1, C_API_PREDICT_NORMAL, num_iterations, "", &dummy, score); | ||
} | ||
cout << "len=" << dummy << endl; | ||
|
||
cout << "Score = " << score[0] << "\n"; | ||
|
||
cout << "end\n"; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <iostream> | ||
#include "LightGBM/c_api.h" | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
cout << "start\n"; | ||
|
||
BoosterHandle boosterHandle; | ||
int num_iterations; | ||
LGBM_BoosterCreateFromModelfile("./LightGBM_model.txt", &num_iterations, &boosterHandle); | ||
cout << "Model iterations " << num_iterations<< "\n"; | ||
|
||
double values[] = {1.000000000000000000e+00,8.692932128906250000e-01,-6.350818276405334473e-01,2.256902605295181274e-01,3.274700641632080078e-01,-6.899932026863098145e-01,7.542022466659545898e-01,-2.485731393098831177e-01,-1.092063903808593750e+00,0.000000000000000000e+00,1.374992132186889648e+00,-6.536741852760314941e-01,9.303491115570068359e-01,1.107436060905456543e+00,1.138904333114624023e+00,-1.578198313713073730e+00,-1.046985387802124023e+00,0.000000000000000000e+00,6.579295396804809570e-01,-1.045456994324922562e-02,-4.576716944575309753e-02,3.101961374282836914e+00,1.353760004043579102e+00,9.795631170272827148e-01,9.780761599540710449e-01,9.200048446655273438e-01,7.216574549674987793e-01,9.887509346008300781e-01,8.766783475875854492e-01}; // score = 0.487278 | ||
|
||
FastConfigHandle fastConfigHandle; | ||
LGBM_BoosterPredictForMatSingleRowFastInit(boosterHandle, C_API_DTYPE_FLOAT64, 28, "", &fastConfigHandle); | ||
|
||
int64_t dummy_out_len; | ||
double score[1]; | ||
for (size_t i = 0; i < 3e5; ++i) { | ||
LGBM_BoosterPredictForMatSingleRowFast(fastConfigHandle, values, C_API_PREDICT_NORMAL, num_iterations, &dummy_out_len, score); | ||
} | ||
|
||
LGBM_FastConfigFree(fastConfigHandle); | ||
|
||
cout << "len=" << dummy_out_len << endl; | ||
|
||
cout << "Score = " << score[0] << "\n"; | ||
|
||
cout << "end\n"; | ||
} |