microsoft / LightGBM

A fast, distributed, high performance gradient boosting (GBT, GBDT, GBRT, GBM or MART) framework based on decision tree algorithms, used for ranking, classification and many other machine learning tasks.
https://lightgbm.readthedocs.io/en/latest/
MIT License
16.56k stars 3.82k forks source link

lightgbm v3 model file not compatible with v4 #6082

Closed Sammus187 closed 11 months ago

Sammus187 commented 1 year ago

Description

Model file fit and output with v3.3.0 can not be loaded in with v4.0.0.

Tested working using lightgbm v2.3.1 and v3.3.0.

Throws exception in v4.0.0. Tested in both Windows and Linux.

In Linux (Ubuntu 20.04):

  File "test.py", line 3, in <module>
    lgb.Booster(model_file='./test.txt')
  File "/opt/conda/lib/python3.8/site-packages/lightgbm/basic.py", line 3142, in __init__
    params = self._get_loaded_param()
  File "/opt/conda/lib/python3.8/site-packages/lightgbm/basic.py", line 3196, in _get_loaded_param
    _safe_call(_LIB.LGBM_BoosterGetLoadedParam(
  File "/opt/conda/lib/python3.8/site-packages/lightgbm/basic.py", line 237, in _safe_call
    raise LightGBMError(_LIB.LGBM_GetLastError().decode('utf-8'))
lightgbm.basic.LightGBMError: unordered_map::at

Windows gives a slightly different error (attached screencap - could not copy text from test environment) b283e05b-048d-482c-b654-1592c4bbf15c

Reproducible example

Using attached test.txt

import lightgbm as lgb
lgb.Booster(model_file='./test.txt')

Environment info

python 3.8.6 and python 3.11.3 LightGBM version: 3.3.0 and 4.0.0

Command(s) you used to install LightGBM

pip install lightgbm==3.3.0 

and

pip install lightgbm==4.0.0

Additional Comments

ryan-gunderson commented 11 months ago

I am experiencing the same problem. Through trial and error, the parameters in the model file that was causing this problem for me are

[max_conflict_rate: 0]
[sparse_threshold: 0.8]
[max_position: 20]
[lambdamart_norm: 1]

I'm not sure if there are others. Removing them allows the model to be loaded but I have not verified that the loaded model behaves correctly.