-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Python: Booster.load_model() should not require buffer writeability #3013
Comments
See also: #542 |
Basically, instead of using |
However, apparently, there is some problem with Here's a modified version that uses read-only buffer: import ctypes
import xgboost
import xgboost.core
def xgb_load_model(buf):
if isinstance(buf, str):
buf = buf.encode()
bst = xgboost.core.Booster()
n = len(buf)
length = xgboost.core.c_bst_ulong(n)
ptr = (ctypes.c_char * n).from_buffer_copy(buf)
xgboost.core._check_call(
xgboost.core._LIB.XGBoosterLoadModelFromBuffer(bst.handle, ptr, length)
) # segfault
return bst |
Consolidating to #3439. This issue should be re-opened if you or others decide to actively work on implementing this feature. |
It is impossible to load a model from a buffer (e.g. bytestring) in Python, due to a bug where ctypes is used incorrectly to get a
const char*
pointer:Here's a short example of what it is basically trying to do:
The text was updated successfully, but these errors were encountered: