Expose build info (#7399)

This commit is contained in:
Jiaming Yuan
2021-11-12 18:22:46 +08:00
committed by GitHub
parent 937fa282b5
commit 46726ec176
7 changed files with 158 additions and 11 deletions

View File

@@ -6,7 +6,7 @@ Contributors: https://github.com/dmlc/xgboost/blob/master/CONTRIBUTORS.md
import os
from .core import DMatrix, DeviceQuantileDMatrix, Booster, DataIter
from .core import DMatrix, DeviceQuantileDMatrix, Booster, DataIter, build_info
from .training import train, cv
from . import rabit # noqa
from . import tracker # noqa
@@ -21,14 +21,34 @@ try:
except ImportError:
pass
VERSION_FILE = os.path.join(os.path.dirname(__file__), 'VERSION')
VERSION_FILE = os.path.join(os.path.dirname(__file__), "VERSION")
with open(VERSION_FILE, encoding="ascii") as f:
__version__ = f.read().strip()
__all__ = ['DMatrix', 'DeviceQuantileDMatrix', 'Booster', 'DataIter',
'train', 'cv',
'RabitTracker',
'XGBModel', 'XGBClassifier', 'XGBRegressor', 'XGBRanker',
'XGBRFClassifier', 'XGBRFRegressor',
'plot_importance', 'plot_tree', 'to_graphviz', 'dask',
'set_config', 'get_config', 'config_context']
__all__ = [
# core
"DMatrix",
"DeviceQuantileDMatrix",
"Booster",
"DataIter",
"train",
"cv",
# utilities
"RabitTracker",
"build_info",
"plot_importance",
"plot_tree",
"to_graphviz",
"set_config",
"get_config",
"config_context",
# sklearn
"XGBModel",
"XGBClassifier",
"XGBRegressor",
"XGBRanker",
"XGBRFClassifier",
"XGBRFRegressor",
# dask
"dask",
]

View File

@@ -192,6 +192,22 @@ def _check_call(ret: int) -> None:
raise XGBoostError(py_str(_LIB.XGBGetLastError()))
def build_info() -> dict:
"""Build information of XGBoost. The returned value format is not stable. Also, please
note that build time dependency is not the same as runtime dependency. For instance,
it's possible to build XGBoost with older CUDA version but run it with the lastest
one.
.. versionadded:: 1.6.0
"""
j_info = ctypes.c_char_p()
_check_call(_LIB.XGBBuildInfo(ctypes.byref(j_info)))
assert j_info.value is not None
res = json.loads(j_info.value.decode()) # pylint: disable=no-member
return res
def _numpy2ctypes_type(dtype):
_NUMPY_TO_CTYPES_MAPPING = {
np.float32: ctypes.c_float,