-
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.
[docs][ci] added docs about GPU support out of the box for Windows wh…
…eels and small refactoring for dual test (#3660) * added docs about GPU support out of the box for Windows and small refactoring for dual test * test * Revert "test" This reverts commit 4518810. * fix docs * fix docs * hotfix config * Apply suggestions from code review Co-authored-by: TP Boudreau <tpboudreau@gmail.com> Co-authored-by: TP Boudreau <tpboudreau@gmail.com>
- Loading branch information
1 parent
e5554e1
commit 1fb2744
Showing
8 changed files
with
50 additions
and
49 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 |
---|---|---|
@@ -1,36 +1,34 @@ | ||
# coding: utf-8 | ||
"""Tests for dual GPU+CPU support.""" | ||
|
||
import os | ||
import pytest | ||
|
||
import lightgbm as lgb | ||
import numpy as np | ||
from lightgbm.basic import LightGBMError | ||
|
||
from sklearn.metrics import log_loss | ||
|
||
@pytest.mark.skipif( | ||
os.environ.get("LIGHTGBM_TEST_DUAL_CPU_GPU", None) is None, | ||
reason="Only run if appropriate env variable is set", | ||
) | ||
def test_cpu_works(): | ||
"""If compiled appropriately, the same installation will support both GPU and CPU.""" | ||
data = np.random.rand(500, 10) | ||
label = np.random.randint(2, size=500) | ||
validation_data = train_data = lgb.Dataset(data, label=label) | ||
|
||
param = {"verbosity": 2, "num_leaves": 31, "objective": "binary", "device": "cpu"} | ||
gbm = lgb.train(param, train_data, 10, valid_sets=[validation_data]) | ||
from .utils import load_breast_cancer | ||
|
||
|
||
@pytest.mark.skipif( | ||
os.environ.get("LIGHTGBM_TEST_DUAL_CPU_GPU", None) is None, | ||
reason="Only run if appropriate env variable is set", | ||
) | ||
def test_gpu_works(): | ||
"""If compiled appropriately, the same installation will support both GPU and CPU.""" | ||
data = np.random.rand(500, 10) | ||
label = np.random.randint(2, size=500) | ||
validation_data = train_data = lgb.Dataset(data, label=label) | ||
|
||
param = {"verbosity": 2, "num_leaves": 31, "objective": "binary", "device": "gpu"} | ||
gbm = lgb.train(param, train_data, 10, valid_sets=[validation_data]) | ||
def test_cpu_and_gpu_work(): | ||
# If compiled appropriately, the same installation will support both GPU and CPU. | ||
X, y = load_breast_cancer(return_X_y=True) | ||
data = lgb.Dataset(X, y) | ||
|
||
params_cpu = {"verbosity": -1, "num_leaves": 31, "objective": "binary", "device": "cpu"} | ||
cpu_bst = lgb.train(params_cpu, data, num_boost_round=10) | ||
cpu_score = log_loss(y, cpu_bst.predict(X)) | ||
|
||
params_gpu = params_cpu.copy() | ||
params_gpu["device"] = "gpu" | ||
gpu_bst = lgb.train(params_gpu, data, num_boost_round=10) | ||
gpu_score = log_loss(y, gpu_bst.predict(X)) | ||
|
||
np.testing.assert_allclose(cpu_score, gpu_score, rtol=1e-4) | ||
assert gpu_score < 0.25 |