mc2-project / federated-xgboost

Federated gradient boosted decision tree learning
68 stars 20 forks source link

reading XGB json models #28

Closed EliasBrohammer closed 2 years ago

EliasBrohammer commented 2 years ago

Hello! I have some problem loading XGB trained models into federated-xgboost. It tells me I have the wrong model format, but it's the one recommended by xgboost via model.save_model('YYYY_MM_DD_model.json'). Do I have to retrain the model(s) with federated xgboost?

Used library versions:

federatedxgboost.__version__ = 0.9
xgboost.__version__ = 1.3.3

Terminal output:

import federatedxgboost as fxgb
model = fxgb.XGBRFRegressor()
>>> model.load_model('20220302_model.json')
Traceback (most recent call last):   
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/dist-packages/federatedxgboost-0.90-py3.10.egg/federatedxgboost/sklearn.py", line 300, in load_model
    self._Booster.load_model(fname)
  File "/usr/local/lib/python3.10/dist-packages/federatedxgboost-0.90-py3.10.egg/federatedxgboost/core.py", line 1366, in load_model
    _check_call(_LIB.XGBoosterLoadModel(self.handle, c_str(fname)))
  File "/usr/local/lib/python3.10/dist-packages/federatedxgboost-0.90-py3.10.egg/federatedxgboost/core.py", line 176, in _check_call
    raise XGBoostError(py_str(_LIB.XGBGetLastError()))
federatedxgboost.core.XGBoostError: [08:39:52] /home/ubuntu/federated-xgboost/src/learner.cc:349: Check failed: fi->Read(&name_obj_[0], len) == len (10761048 vs. 808333344) : BoostLearner: wrong model format
Stack trace:
  [bt] (0) /usr/local/lib/python3.10/dist-packages/federatedxgboost-0.90-py3.10.egg/federatedxgboost/./lib/libxgboost.so(xgboost::LearnerImpl::Load(dmlc::Stream*)+0x3e2) [0x7f79ec1d8002]
  [bt] (1) /usr/local/lib/python3.10/dist-packages/federatedxgboost-0.90-py3.10.egg/federatedxgboost/./lib/libxgboost.so(XGBoosterLoadModel+0x4e) [0x7f79ec13843e]
  [bt] (2) /lib/x86_64-linux-gnu/libffi.so.8(+0x7e2e) [0x7f7a1aaf7e2e]
  [bt] (3) /lib/x86_64-linux-gnu/libffi.so.8(+0x4493) [0x7f7a1aaf4493]
  [bt] (4) /usr/lib/python3.10/lib-dynload/_ctypes.cpython-310-x86_64-linux-gnu.so(+0xa451) [0x7f7a17ebf451]
  [bt] (5) /usr/lib/python3.10/lib-dynload/_ctypes.cpython-310-x86_64-linux-gnu.so(+0x9a68) [0x7f7a17ebea68]
  [bt] (6) python3(_PyObject_MakeTpCall+0x25b) [0x5580a120bbbb]
  [bt] (7) python3(_PyEval_EvalFrameDefault+0x6b50) [0x5580a1204590]
  [bt] (8) python3(_PyFunction_Vectorcall+0x7c) [0x5580a121595c]
EliasBrohammer commented 2 years ago

I could find another solution besides to retrain the model with the federatedxgboost library. Maybe someone has another idea, how to import nativ xgboost models into federated-xgboost.