-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
python api can't continue train with binary file data #4311
Comments
@papillonyi thanks very much for using LightGBM. sorry for the very long delay in responding to this! In the future, please do not post logs, error messages, or code as screenshots. Post such things as text instead, so others facing the same challenges can find this discussion from search engines. Providing a minimal, reproducible example that can be easily copied and run by others would also make it much more likely that issues will be addressed quickly. I tried to create a minimal, reproducible example based on the provided code snippet, using the Python package as of the latest commit on The code below produces the reported error. import lightgbm as lgb
from sklearn.datasets import make_regression
X, y = make_regression(n_samples=1_000, n_informative=5)
data_file_name = "output.bin"
model_file_name = "model-temp.text"
params = {
"boosting_type": "gbdt",
"verbose": 1,
"deterministic": True,
"objective": "regression"
}
# create dataset and save it to binary file
lgb.Dataset(data=X, label=y).save_binary(data_file_name)
# train for 10 iterations on data from file
dtrain = lgb.Dataset(data_file_name)
booster = lgb.train(
params=params,
train_set=dtrain,
num_boost_round=10
)
booster.save_model(model_file_name)
# clear booster and dataset
del booster
del dtrain
# try to containue training for 10 more rounds on
# model and Dataset from file
dtrain = lgb.Dataset(data_file_name)
booster = lgb.train(
params=params,
train_set=dtrain,
init_model=model_file_name,
num_boost_round=10
)
stack trace (click me)
|
Looking at the stacktrace, this is coming from a call to LightGBM/python-package/lightgbm/basic.py Line 784 in af5b40e
Related conversations:
I was able to replicate that behavior as well, and confirm that the CLI does support training continuation using a Dataset binary file First, I installed the Python package and built the CLI. cd python-package
python setup.py install
cd ..
mkdir build
cd build
cmake ..
make -j2
cd .. Then I ran the following Python code to generate the Dataset binary file and initial model. import lightgbm as lgb
from sklearn.datasets import make_regression
X, y = make_regression(n_samples=1_000, n_informative=5)
data_file_name = "output.bin"
model_file_name = "model-temp.text"
params = {
"boosting_type": "gbdt",
"verbose": 1,
"deterministic": True,
"objective": "regression"
}
# create dataset and save it to binary file
lgb.Dataset(data=X, label=y).save_binary(data_file_name)
# train for 10 iterations on data from file
dtrain = lgb.Dataset(data_file_name)
booster = lgb.train(
params=params,
train_set=dtrain,
num_boost_round=10
)
booster.save_model(model_file_name) Checked that the model produced had exactly 10 trees. cat model-temp.text | grep 'Tree=' | tail -1
Next, I created a file
Next, ran training with the CLI and checked that a new model file was produced, with 17 total trees (10 from initial training, 7 from training continuation). ./lightgbm config=train.conf
cat model-from-cli.txt | grep 'Tree=' | tail -1
|
I think at this point we should convert this issue into a feature request like And that solutions for supporting that might be one of the following:
|
Description
when i tried to continue train with binary file data, it raise a error
I train with a binary file with 10 iterations first and it success;
then, i try to train with
init_model=last_train_result,
and it raise such error;And i try do the same thing with lightgbm cli, it works
Reproducible example
here is my code
Environment info
th version of lightGBM i used is 3.1.1 in linux
Command(s) you used to install LightGBM
Additional Comments
The text was updated successfully, but these errors were encountered: