1

This is my environment and parameter of xgboost when I saved a xgboost model.

environment

  • xgboost version 0.90

parameter

  • objective: gpu:binary:logistic

I want to load a saved xgboost model in version 1.0.0. However, this error massage is occurred.

XGBoostError: [12:51:46] C:\Users\Administrator\workspace\xgboost-win64_release_1.0.0\src\objective\objective.cc:26: Unknown objective function: `gpu:binary:logistic`

This is because gpu:binary:logistic is now deprecated. When I loaded my model in version 0.90, this warnings is occurred.

[13:45:14] WARNING: C:/Jenkins/workspace/xgboost-win64_release_0.90/src/objective/regression_obj.cu:170: gpu:binary:logistic is now deprecated, use binary:logistic instead.

I tried to apply set_params for replacing gpu:binary:logistic to binary:logistic and saved a model. But, it didn't work.

import xgboost as xgb

model = xgb.XGBClassifier()
model.load_model('xgb.model')

params = {'objective':'binary:logistic'}
model.set_params(**params)

I tried to replace 'gpu:binary:logistic' to 'binary:'logistic' from a saved model file, but OSError was occurred.

temp = open('test.model','rb')
lines = temp.readlines()
lines[0] = lines[0].replace(b'gpu:',b'')

new_model = open('test_replace.model','wb')

for line in lines:
    new_model.write(line)
new_model.close()

And OSError was appeared when I loaded model.

model = xgb.XGBClassifier()
model.load_model('test_replace.model')
OSError: [WinError -529697949] Windows Error 0xe06d7363

This is a saved xgboost model. This file was saved as model format

b'\x00\x00\x00\x80\x19\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00gpu:binary:logistic\x06\x00\x00\x00\x00\x00\x00\x00gbtree\xfb\x00\x00\x00\x01\x00\x00\x00\x19\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x19\x00\x00\x00\x00\x00

I can't re-train my model. For this reason, I have to fix this problem from a saved model.

How to fix this problem?

Touch Too
  • 13
  • 3

1 Answers1

0

The name of the objective function is stored as a string in the model file. Simply perform a binary-aware replacement gpu:binary:logistic -> binary:logistic on your model file!

Should be doable using command-line tools, see for example this SO thread: binary sed replacement

Upon a successful replacement, the size of the model file should shrink by 4 bytes (the length of the gpu: prefix).

user1808924
  • 4,563
  • 2
  • 17
  • 20
  • As your answer, I opened my model in python and replaced `gpu:' to ''. However, OSError was occurred. – Touch Too Dec 28 '20 at 17:54
  • OK, my bad. The string value is stored as ``. In addition to changing the string value, you'd need to update the leading string length indicator field as well (subtract 4 from the current value). – user1808924 Dec 28 '20 at 18:01
  • Right now you have: `gpu:binary:logistic`, but you'd need to have `binary:logistic` – user1808924 Dec 28 '20 at 18:02
  • Please note that the length is actually written using the `long64` data type, so it's 8 bytes right before the beginning of the string value. – user1808924 Dec 28 '20 at 18:04
  • A model file was written using `int` data type, But I'm not sure if this file used the `long64` data type. How can I figure out if `long64` data type is used? – Touch Too Dec 28 '20 at 18:17
  • TLDR: look up the eight byte sequence right before the `gpu:binary:logistic` byte sequence part starts in the model file. There should be seven `0`-value bytes and a single `19`-value byte (`0x13` in hexadecimal). Change this byte to `15`-value byte (`0xf`). Does it work then? – user1808924 Dec 28 '20 at 19:29
  • I see you've edited your question so that it includes the head of the model file. This is the byte sequence `\x13\x00\x00\x00\x00\x00\x00\x00gpu:binary:logistic`; replace it with `\x0f\x00\x00\x00\x00\x00\x00\x00binary:logistic` and you should be good to go! – user1808924 Dec 28 '20 at 19:35
  • Great! According to SO guidelines, you should mark this answer (and its comments) as "accepted" to show to others that you problem has been solved. – user1808924 Dec 30 '20 at 07:23