dmlc / dmlc/xgboost

Integer overflow in `get_dump` and `trees_to_dataframe`

Open
#10,035 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
28.8k
Forks
8.9k
Avg merge
1d 12h
Merged PRs (30d)
54

Description

Dumping tree information using `get_dump` and `trees_to_dataframe` in Python for models with large split conditions causes integer overflow errors.
This has only been tested with Python regression models on v2.0.3.

### How to reproduce
In python:

```
model = XGBRegressor(n_jobs=100, n_estimators=1, min_child_weight=1, subsample=1, learning_rate=0.05, max_depth=4, random_state=1)
input = pd.DataFrame({'very_large_number': [2*10**10, 3*10**10]})
output = pd.DataFrame({'true_results': [0, 1]})

model.fit(input, output)

model.get_booster().trees_to_dataframe()
>>> Tree Node ID Feature Split Yes No Missing Gain Cover Category
>>> 0 0 0 0-0 very_large_number -2.147484e+09 0-1 0-2 0-2 0.2500 2.0 NaN
>>> 1 0 1 0-1 Leaf NaN NaN NaN NaN -0.0125 1.0 NaN
>>> 2 0 2 0-2 Leaf NaN NaN NaN NaN 0.0125 1.0 NaN

model.predict([-10, 2*10**10, 3*10**10])
>>> [0.4875 0.4875 0.5125]
```

Note the split condition for feature `very_large_number`: `-2.147484e+09 == -INT_MAX`.

If we are to trust the output of `trees_to_dataframe`, each prediction for `[-10, 2*10**10, 3*10**10]` should return `[0.5125, 0.5125, 0.5125]` since each of those values are larger than `-2.147484e+09`. However, this is not what is observed from the model.

The same integer overflow error can be observed when using `model.get_booster().get_dump()`.

However, when using `model.save_model(file)` the split conditions are saved correctly. This can be tested by saving and loading, in which case you will observe identical model outputs indicating there is no data loss in the process.

The `trees_to_dataframe()` function calls the underlying `get_dump()` which in turn accesses `XGBoosterDumpModelEx`. However, `save_model()` uses `XGBoosterSaveModel`. Thus, it seems like the problem is likely with `XGBoosterDumpModelEx`.

This is my first time contributing to this project (or any open source project). Please let me know if there are any issues or if any more information is needed.
Thanks!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.