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

Issues downgrading xgboost 2 model #10257

Closed
farridav opened this issue May 9, 2024 · 4 comments
Closed

Issues downgrading xgboost 2 model #10257

farridav opened this issue May 9, 2024 · 4 comments

Comments

@farridav
Copy link

farridav commented May 9, 2024

I'm attempting to downgrade a trained xgboost 2 model down to 1.1 (as another system needs the model to be compatible with 1.1)

These are the steps that i taking

In an environment with xgboost==2.0.3 installed

# Model starts in pickle format
model: xgboost.Booster = pickle.load(open(in_pickle_path, "rb"))
model.save_model(out_json_path)

In an environment with xgboost==1.1 installed

booster = xgboost.Booster()
model = booster.load_model(out_json_path)

Which results in the following error:

XGBoostError: [14:46:41] /workspace/include/xgboost/json.h:65: Invalid cast, from Null to Array
Stack trace:
  [bt] (0) .../xgboost/lib/libxgboost.so(+0xfa146) [0x77622c2fa146]
  [bt] (1) .../xgboost/lib/libxgboost.so(+0x22f7dd) [0x77622c42f7dd]
  [bt] (2) .../xgboost/lib/libxgboost.so(+0x188af2) [0x77622c388af2]
  [bt] (3) .../xgboost/lib/libxgboost.so(+0x16a97f) [0x77622c36a97f]
  [bt] (4) .../xgboost/lib/libxgboost.so(+0x1a9e6a) [0x77622c3a9e6a]
  [bt] (5) .../xgboost/lib/libxgboost.so(XGBoosterLoadModel+0x796) [0x77622c292096]
  [bt] (6) /lib/x86_64-linux-gnu/libffi.so.8(+0x7e2e) [0x7762b6191e2e]
  [bt] (7) /lib/x86_64-linux-gnu/libffi.so.8(+0x4493) [0x7762b618e493]
  [bt] (8) .../lib-dynload/_ctypes.cpython-311-x86_64-linux-gnu.so(+0x13cd6) [0x7762b7a97cd6]

Is this the right approach? or is there something I need to do inbetween ? i also seem to struggle to re-import the model into other xgboost versions ive tried (e.g 1.6, for various other errors)

@hcho3
Copy link
Collaborator

hcho3 commented May 10, 2024

It is not possible to "downgrade" a trained model. This is analogous to Microsoft Word 97 being unable to load .docx files from Word 2019.
Is it possible to upgrade the other system to latest XGBoost?
If not, you would have to train a new model using XGBoost 1.1.

@farridav
Copy link
Author

Unfortunately not, and I read in the docs that the model is forwards compatible across versions (admittedly I'm going backwards)

https://xgboost.readthedocs.io/en/stable/tutorials/saving_model.html#a-note-on-backward-compatibility-of-models-and-memory-snapshots

It seems there is something that might need tweaking to transition between 2.0.3 and 1.1 though I've not yet found out what it is..

@hcho3
Copy link
Collaborator

hcho3 commented May 10, 2024

I read in the docs that the model is forwards compatible across versions

The docs say that the model is backwards compatible, which is in the opposite direction of forward compatibility. So the following is true:

  • XGBoost 1.1 can load a model that is trained with XGBoost 1.1
  • XGBoost 2.0.3 can load a model that is trained with XGBoost 1.1 (backwards compatible)
  • XGBoost 1.1 cannot load a model that is trained with XGBoost 2.0.3 (not forward compatible)

Unfortunately not

In this case, you should probably train a new model in an environment with xgboost==1.1.

@trivialfis
Copy link
Member

Feel free to reopen if there are further questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants