Skip to content

Commit e1ce3f6

Browse files
authored
[doc] Brief note for serialization. (dmlc#11265)
1 parent e5f29dd commit e1ce3f6

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

python-package/xgboost/core.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2752,7 +2752,9 @@ def save_model(self, fname: PathLike) -> None:
27522752
The model is saved in an XGBoost internal format which is universal among the
27532753
various XGBoost interfaces. Auxiliary attributes of the Python Booster object
27542754
(such as feature_names) are only saved when using JSON or UBJSON (default)
2755-
format. See :doc:`Model IO </tutorials/saving_model>` for more info.
2755+
format. Also, parameters that are not part of the model (like metrics,
2756+
`max_depth`, etc) are not saved, see :doc:`Model IO </tutorials/saving_model>`
2757+
for more info.
27562758
27572759
.. code-block:: python
27582760
@@ -2778,7 +2780,9 @@ def save_raw(self, raw_format: str = "ubj") -> bytearray:
27782780
The model is saved in an XGBoost internal format which is universal among the
27792781
various XGBoost interfaces. Auxiliary attributes of the Python Booster object
27802782
(such as feature_names) are only saved when using JSON or UBJSON (default)
2781-
format. See :doc:`Model IO </tutorials/saving_model>` for more info.
2783+
format. Also, parameters that are not part of the model (like metrics,
2784+
`max_depth`, etc) are not saved, see :doc:`Model IO </tutorials/saving_model>`
2785+
for more info.
27822786
27832787
Parameters
27842788
----------
@@ -2788,6 +2792,7 @@ def save_raw(self, raw_format: str = "ubj") -> bytearray:
27882792
Returns
27892793
-------
27902794
An in memory buffer representation of the model
2795+
27912796
"""
27922797
length = c_bst_ulong()
27932798
cptr = ctypes.POINTER(ctypes.c_char)()
@@ -2805,14 +2810,23 @@ def load_model(self, fname: ModelIn) -> None:
28052810
The model is saved in an XGBoost internal format which is universal among the
28062811
various XGBoost interfaces. Auxiliary attributes of the Python Booster object
28072812
(such as feature_names) are only saved when using JSON or UBJSON (default)
2808-
format. See :doc:`Model IO </tutorials/saving_model>` for more info.
2813+
format. Also, parameters that are not part of the model (like metrics,
2814+
`max_depth`, etc) are not saved, see :doc:`Model IO </tutorials/saving_model>`
2815+
for more info.
28092816
28102817
.. code-block:: python
28112818
2819+
model.save_model("model.json")
28122820
model.load_model("model.json")
2821+
28132822
# or
2823+
model.save_model("model.ubj")
28142824
model.load_model("model.ubj")
28152825
2826+
# or
2827+
buf = model.save_raw()
2828+
model.load_model(buf)
2829+
28162830
Parameters
28172831
----------
28182832
fname :

0 commit comments

Comments
 (0)