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

Use ctypes to pass parameters (fixes #3398) #3419

Merged
merged 1 commit into from
Sep 30, 2020

Conversation

btrotta
Copy link
Collaborator

@btrotta btrotta commented Sep 29, 2020

I was able to reproduce the bug from #3398 consistently on my machine with the script below (Windows, Visual Studio, Python 2.7). It always crashes on seed=105.

I think the cause is that LGBM_DatasetGetFeatureNames is expecting a size_t input for buffer_len but we pass a Python integer. Apparently this can cause unpredictable behavior depending on the compiler, see https://stackoverflow.com/questions/51903911/calling-c-functions-via-python-ctypes-why-does-passing-uints-to-a-function-expe

import lightgbm as lgb
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(*load_breast_cancer(return_X_y=True),
                                                                        test_size=0.1, random_state=1)
train_data = lgb.Dataset(X_train, y_train)

for seed in range(0, 200):
    print(seed)
    params = {
        "objective": "binary",
        "verbose": -1,
        "num_leaves": 3,
        "seed": seed
    }

    gbm1 = lgb.LGBMClassifier(n_estimators=3, num_leaves=3, silent=True)
    gbm1.fit(X_train, y_train)
    print(gbm1.booster_.feature_name()[27])

@btrotta btrotta added the fix label Sep 29, 2020
@btrotta btrotta changed the title Fix #3398 Fixes #3398 Sep 29, 2020
@btrotta btrotta changed the title Fixes #3398 Use ctypes to pass parameters (fixes #3398) Sep 29, 2020
@btrotta btrotta linked an issue Sep 29, 2020 that may be closed by this pull request
@github-actions
Copy link

This pull request 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 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flaky test with exception: access violation writing on Windows
2 participants