xgboost
Functions
Serialization

There are multiple ways to serialize a Booster object depending on the use case. More...

Collaboration diagram for Serialization:

Functions

int XGBoosterLoadModel (BoosterHandle handle, const char *fname)
 Load model from existing file. More...
 
int XGBoosterSaveModel (BoosterHandle handle, const char *fname)
 Save model into existing file. More...
 
int XGBoosterLoadModelFromBuffer (BoosterHandle handle, const void *buf, bst_ulong len)
 load model from in memory buffer More...
 
int XGBoosterSaveModelToBuffer (BoosterHandle handle, char const *config, bst_ulong *out_len, char const **out_dptr)
 Save model into raw bytes, return header of the array. User must copy the result out, before next xgboost call. More...
 
int XGBoosterGetModelRaw (BoosterHandle handle, bst_ulong *out_len, const char **out_dptr)
 Save booster to a buffer with in binary format. More...
 
int XGBoosterSerializeToBuffer (BoosterHandle handle, bst_ulong *out_len, const char **out_dptr)
 Memory snapshot based serialization method. Saves everything states into buffer. More...
 
int XGBoosterUnserializeFromBuffer (BoosterHandle handle, const void *buf, bst_ulong len)
 Memory snapshot based serialization method. Loads the buffer returned from XGBoosterSerializeToBuffer. More...
 
int XGBoosterLoadRabitCheckpoint (BoosterHandle handle, int *version)
 Initialize the booster from rabit checkpoint. This is used in distributed training API. More...
 
int XGBoosterSaveRabitCheckpoint (BoosterHandle handle)
 Save the current checkpoint to rabit. More...
 
int XGBoosterSaveJsonConfig (BoosterHandle handle, bst_ulong *out_len, char const **out_str)
 Save XGBoost's internal configuration into a JSON document. Currently the support is experimental, function signature may change in the future without notice. More...
 
int XGBoosterLoadJsonConfig (BoosterHandle handle, char const *config)
 Load XGBoost's internal configuration from a JSON document. Currently the support is experimental, function signature may change in the future without notice. More...
 

Detailed Description

There are multiple ways to serialize a Booster object depending on the use case.

Short note for serialization APIs. There are 3 different sets of serialization API.

Function Documentation

◆ XGBoosterGetModelRaw()

int XGBoosterGetModelRaw ( BoosterHandle  handle,
bst_ulong out_len,
const char **  out_dptr 
)

Save booster to a buffer with in binary format.

Deprecated:
since 1.6.0
See also
XGBoosterSaveModelToBuffer()

◆ XGBoosterLoadJsonConfig()

int XGBoosterLoadJsonConfig ( BoosterHandle  handle,
char const *  config 
)

Load XGBoost's internal configuration from a JSON document. Currently the support is experimental, function signature may change in the future without notice.

Parameters
handlehandle to Booster object.
configstring representation of a JSON document.
Returns
0 when success, -1 when failure happens

◆ XGBoosterLoadModel()

int XGBoosterLoadModel ( BoosterHandle  handle,
const char *  fname 
)

Load model from existing file.

Parameters
handlehandle
fnameFile URI or file name. The string must be UTF-8 encoded.
Returns
0 when success, -1 when failure happens
Examples
inference.c.

◆ XGBoosterLoadModelFromBuffer()

int XGBoosterLoadModelFromBuffer ( BoosterHandle  handle,
const void *  buf,
bst_ulong  len 
)

load model from in memory buffer

Parameters
handlehandle
bufpointer to the buffer
lenthe length of the buffer
Returns
0 when success, -1 when failure happens

◆ XGBoosterLoadRabitCheckpoint()

int XGBoosterLoadRabitCheckpoint ( BoosterHandle  handle,
int *  version 
)

Initialize the booster from rabit checkpoint. This is used in distributed training API.

Parameters
handlehandle
versionThe output version of the model.
Returns
0 when success, -1 when failure happens

◆ XGBoosterSaveJsonConfig()

int XGBoosterSaveJsonConfig ( BoosterHandle  handle,
bst_ulong out_len,
char const **  out_str 
)

Save XGBoost's internal configuration into a JSON document. Currently the support is experimental, function signature may change in the future without notice.

Parameters
handlehandle to Booster object.
out_lenlength of output string
out_strA valid pointer to array of characters. The characters array is allocated and managed by XGBoost, while pointer to that array needs to be managed by caller.
Returns
0 when success, -1 when failure happens

◆ XGBoosterSaveModel()

int XGBoosterSaveModel ( BoosterHandle  handle,
const char *  fname 
)

Save model into existing file.

Parameters
handlehandle
fnameFile URI or file name. The string must be UTF-8 encoded.
Returns
0 when success, -1 when failure happens
Examples
external_memory.c, and inference.c.

◆ XGBoosterSaveModelToBuffer()

int XGBoosterSaveModelToBuffer ( BoosterHandle  handle,
char const *  config,
bst_ulong out_len,
char const **  out_dptr 
)

Save model into raw bytes, return header of the array. User must copy the result out, before next xgboost call.

Parameters
handlehandle
configJSON encoded string storing parameters for the function. Following keys are expected in the JSON document:

"format": str

  • json: Output booster will be encoded as JSON.
  • ubj: Output booster will be encoded as Univeral binary JSON.
  • deprecated: Output booster will be encoded as old custom binary format. Do not use this format except for compatibility reasons.
Parameters
out_lenThe argument to hold the output length
out_dptrThe argument to hold the output data pointer
Returns
0 when success, -1 when failure happens

◆ XGBoosterSaveRabitCheckpoint()

int XGBoosterSaveRabitCheckpoint ( BoosterHandle  handle)

Save the current checkpoint to rabit.

Parameters
handlehandle
Returns
0 when success, -1 when failure happens

◆ XGBoosterSerializeToBuffer()

int XGBoosterSerializeToBuffer ( BoosterHandle  handle,
bst_ulong out_len,
const char **  out_dptr 
)

Memory snapshot based serialization method. Saves everything states into buffer.

Parameters
handlehandle
out_lenthe argument to hold the output length
out_dptrthe argument to hold the output data pointer
Returns
0 when success, -1 when failure happens

◆ XGBoosterUnserializeFromBuffer()

int XGBoosterUnserializeFromBuffer ( BoosterHandle  handle,
const void *  buf,
bst_ulong  len 
)

Memory snapshot based serialization method. Loads the buffer returned from XGBoosterSerializeToBuffer.

Parameters
handlehandle
bufpointer to the buffer
lenthe length of the buffer
Returns
0 when success, -1 when failure happens