Skip to content
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

Result of model with linear trees depends on the number of used during fitting CPU threads #5266

Closed
StrikerRUS opened this issue Jun 5, 2022 · 3 comments · Fixed by #5368
Labels

Comments

@StrikerRUS
Copy link
Collaborator

Reproducible example:

import sys

import numpy as np
import lightgbm as lgb

sys.path.append(r'LightGBM\tests\python_package_test')

from test_consistency import FileLoader, EXAMPLES_DIR

fd = FileLoader(EXAMPLES_DIR / 'binary_classification', 'binary', 'train_linear.conf')
X_train, y_train, _ = fd.load_dataset('.train')
X_test, _, _ = fd.load_dataset('.test')

def fit_predict(n_jobs):
    gbm = lgb.LGBMClassifier(**fd.params, verbose=-1, n_jobs=n_jobs)
    gbm.fit(X_train, y_train)
    return gbm.predict_proba(X_test)[:, 1]

pred_1 = fit_predict(n_jobs=2)
pred_2 = fit_predict(n_jobs=4)

np.testing.assert_allclose(pred_1, pred_2)
AssertionError: 
Not equal to tolerance rtol=1e-07, atol=0

Mismatched elements: 500 / 500 (100%)
Max absolute difference: 0.33526452
Max relative difference: 2.5919644
 x: array([0.814095, 0.543692, 0.029034, 0.763285, 0.151306, 0.157106,
       0.237552, 0.146994, 0.936084, 0.366068, 0.790745, 0.871099,
       0.862789, 0.84715 , 0.621987, 0.866871, 0.276202, 0.76066 ,...
 y: array([0.824547, 0.466547, 0.060617, 0.598674, 0.05619 , 0.097133,
       0.215748, 0.109334, 0.926242, 0.378924, 0.871532, 0.839161,
       0.857007, 0.845114, 0.69853 , 0.683535, 0.201123, 0.697704,...

Bug was originally found in #5105 (comment).

Fix of this issue should include removing n_jobs=0 workaround here

gbm = lgb.LGBMClassifier(**fd.params)

@StrikerRUS StrikerRUS added the bug label Jun 5, 2022
@StrikerRUS
Copy link
Collaborator Author

@btrotta Could you please help with this?

@btrotta
Copy link
Collaborator

btrotta commented Jul 12, 2022

I think I've fixed this; it was due to a numerical precision issue and was not specific to the scikit-learn interface (I've added a test that reproduces the issue in the normal python interface).

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
2 participants