Medial Code Documentation
Loading...
Searching...
No Matches
Functions
Serialization

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

Functions

XGB_DLL int XGBoosterLoadModel (BoosterHandle handle, const char *fname)
 Load model from existing file.
 
XGB_DLL int XGBoosterSaveModel (BoosterHandle handle, const char *fname)
 Save model into existing file.
 
XGB_DLL int XGBoosterLoadModelFromBuffer (BoosterHandle handle, const void *buf, bst_ulong len)
 load model from in memory buffer
 
XGB_DLL 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.
 
XGB_DLL int XGBoosterGetModelRaw (BoosterHandle handle, bst_ulong *out_len, const char **out_dptr)
 Save booster to a buffer with in binary format.
 
XGB_DLL int XGBoosterSerializeToBuffer (BoosterHandle handle, bst_ulong *out_len, const char **out_dptr)
 Memory snapshot based serialization method. Saves everything states into buffer.
 
XGB_DLL int XGBoosterUnserializeFromBuffer (BoosterHandle handle, const void *buf, bst_ulong len)
 Memory snapshot based serialization method. Loads the buffer returned from XGBoosterSerializeToBuffer.
 
XGB_DLL int XGBoosterLoadRabitCheckpoint (BoosterHandle handle, int *version)
 Initialize the booster from rabit checkpoint. This is used in distributed training API.
 
XGB_DLL int XGBoosterSaveRabitCheckpoint (BoosterHandle handle)
 Save the current checkpoint to rabit.
 
XGB_DLL 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.
 
XGB_DLL 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.
 

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()

XGB_DLL 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()

XGB_DLL 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()

XGB_DLL 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()

XGB_DLL 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()

XGB_DLL 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()

XGB_DLL 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()

XGB_DLL 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()

XGB_DLL 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()

XGB_DLL int XGBoosterSaveRabitCheckpoint ( BoosterHandle  handle)

Save the current checkpoint to rabit.

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

◆ XGBoosterSerializeToBuffer()

XGB_DLL 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()

XGB_DLL 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