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

Loading a model can result in std::out_of_range exception #2722

Closed
jpkoponen opened this issue Jan 31, 2020 · 1 comment
Closed

Loading a model can result in std::out_of_range exception #2722

jpkoponen opened this issue Jan 31, 2020 · 1 comment

Comments

@jpkoponen
Copy link
Contributor

jpkoponen commented Jan 31, 2020

The leaf values (leaf outputs) can become denormal doubles, meaning their absolute value is less than the minimum positive normal value of a double. (https://en.wikipedia.org/wiki/Denormal_number)

You can check the minimum value for normal and denormal doubles in C++ with std::numeric_limits<double>::min() and std::numeric_limits<double>::denorm_min().

This can cause that when loading the model from a string, you get an std::out_of_range exception because std::stod() cannot transform a string representing a denormal double to double.

I propose a solution where the leaf outputs are rounded to zero if they are denormal.

Unfortunately, I cannot give you an example of how the model was made because the data I used is sensitive. I can say that I encountered this problem with quantile regression and with many different parameter combinations.

Environment info

Operating System: Ubuntu 18.04.3 LTS

CPU/GPU model: Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz

Python version: 3.7.4
g++ version: 7.4.0

LightGBM version: 2.3.2

Error message

[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
[LightGBM] [Warning] stod
terminate called without an active exception
Process finished with exit code 134

Reproducible examples

import lightgbm as lgb
booster = lgb.Booster(model_file='model_string.txt')

Steps to reproduce

  1. Download the attached model_string.txt
  2. Run the above Python code in the same directory as the downloaded file.
@guolinke
Copy link
Collaborator

thanks @jpkoponen . PR for fixing this is very welcomed.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants