Skip to content

Commit

Permalink
fix int overflow in FTI model convertor (#2053)
Browse files Browse the repository at this point in the history
* fix int overflow in fti model convertor

* fix if feature_types are not defined

* fix for absence of feature_type attribute

---------

Co-authored-by: Dmitry Razdoburdin <>
  • Loading branch information
razdoburdin authored Sep 20, 2024
1 parent 0bed2d6 commit b67ce9c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/gbt_convertors.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,17 @@ class TreeList(list):
Note: We cannot type-hint the xgb.Booster without loading xgb as dependency in pyx code,
therefore not type hint is added.
"""
# dump_format="json" is affected by the integer-overflow error,
# since XGBoost doesn't control numeric limits of integer features.
# For correct conversion we manulally replace feature types from 'int'->'float;
if hasattr(booster, "feature_types"):
feature_types = booster.feature_types
if feature_types:
for i in range(len(feature_types)):
if feature_types[i] == "int":
feature_types[i] = "float"
booster.feature_types = feature_types

tl = TreeList()
dump = booster.get_dump(dump_format="json", with_stats=True)
for tree_id, raw_tree in enumerate(dump):
Expand Down

0 comments on commit b67ce9c

Please sign in to comment.