-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix_overflow_largepredict'
- Loading branch information
Showing
10 changed files
with
91 additions
and
34 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
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
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
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,23 @@ | ||
import pytest | ||
from lightgbm import Booster | ||
|
||
from lleaves import Model | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def NYC_llvm(): | ||
llvm_model = Model(model_file="tests/models/NYC_taxi/model.txt") | ||
llvm_model.compile() | ||
return llvm_model | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def NYC_lgbm(): | ||
return Booster(model_file="tests/models/NYC_taxi/model.txt") | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def mtpl2_llvm(): | ||
llvm_model = Model(model_file="tests/models/mtpl2/model.txt") | ||
llvm_model.compile() | ||
return llvm_model |
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 |
---|---|---|
@@ -1,30 +1,37 @@ | ||
from ctypes import POINTER, c_double | ||
|
||
import numpy as np | ||
from lightgbm import Booster | ||
|
||
from lleaves import Model | ||
|
||
def test_parallel_edgecases(NYC_llvm, NYC_lgbm): | ||
# single row, multiple threads | ||
data = np.array(1 * [NYC_lgbm.num_feature() * [1.0]], dtype=np.float64) | ||
np.testing.assert_almost_equal( | ||
NYC_llvm.predict(data, n_jobs=4), NYC_lgbm.predict(data), decimal=14 | ||
) | ||
|
||
# last thread has only one prediction (batchsize is ceil(19/7)=3) | ||
data = np.array(19 * [NYC_lgbm.num_feature() * [1.0]], dtype=np.float64) | ||
np.testing.assert_almost_equal( | ||
NYC_llvm.predict(data, n_jobs=7), NYC_lgbm.predict(data), decimal=14 | ||
) | ||
|
||
def test_parallel_iteration(): | ||
llvm_model = Model(model_file="tests/models/NYC_taxi/model.txt") | ||
lgbm_model = Booster(model_file="tests/models/NYC_taxi/model.txt") | ||
llvm_model.compile() | ||
|
||
data = np.array(4 * [5 * [1.0]], dtype=np.float64) | ||
def test_parallel_iteration(NYC_llvm, NYC_lgbm): | ||
data = np.array(4 * [NYC_lgbm.num_feature() * [1.0]], dtype=np.float64) | ||
data_flat = np.array(data.reshape(data.size), dtype=np.float64) | ||
np.testing.assert_almost_equal( | ||
llvm_model.predict(data, n_jobs=4), lgbm_model.predict(data), decimal=14 | ||
NYC_llvm.predict(data, n_jobs=4), NYC_lgbm.predict(data), decimal=14 | ||
) | ||
|
||
ptr_data = data_flat.ctypes.data_as(POINTER(c_double)) | ||
preds = np.zeros(4, dtype=np.float64) | ||
ptr_preds = preds.ctypes.data_as(POINTER(c_double)) | ||
|
||
llvm_model._c_entry_func(ptr_data, ptr_preds, 2, 4) | ||
NYC_llvm._c_entry_func(ptr_data, ptr_preds, 2, 4) | ||
preds_l = list(preds) | ||
assert preds_l[0] == 0.0 and preds_l[1] == 0.0 | ||
assert preds_l[2] != 0.0 and preds_l[3] != 0.0 | ||
llvm_model._c_entry_func(ptr_data, ptr_preds, 0, 2) | ||
NYC_llvm._c_entry_func(ptr_data, ptr_preds, 0, 2) | ||
preds_l = list(preds) | ||
assert preds_l[0] != 0.0 and preds_l[1] != 0.0 |