`get_dump(dump_format="json")` writes bare `-inf` split conditions
Describe the bug
Since #12067, the GPU hist evaluator uses -inf as the threshold for a split that separates missing values from every present value. The JSON dump formats split conditions with operator<< (JsonGenerator::Quantitive and PlainNode in src/tree/tree_model.cc), so get_dump(dump_format="json") writes a bare -inf, which neither Python's json nor XGBoost's own Json::Load can parse. The model itself is fine, since save_model writes -Infinity and loads it back.
It's common on GPU: on a model trained on a T4, 86 of 2207 splits had this threshold.
Code to reproduce
On a GPU:
import json
import numpy as np
import xgboost as xgb
X = np.random.default_rng(0).normal(size=(1000, 1)).astype(np.float32)
X[:500, 0] = np.nan
y = np.isnan(X[:, 0]).astype(np.float32)
booster = xgb.train({"device": "cuda", "max_depth": 1}, xgb.DMatrix(X, y), num_boost_round=1)
print(booster.get_dump(dump_format="json")[0].splitlines()[0])
json.loads(booster.get_dump(dump_format="json")[0]) { "nodeid": 0, "depth": 0, "split": "f0", "split_condition": -inf, "yes": 1, "no": 2, "missing": 1 , "children": [
json.decoder.JSONDecodeError: Expecting value: line 1 column 64 (char 63)With device="cpu" the same split gets "split_condition": 4.97377586 and the dump parses.
Without a GPU, by setting the threshold the GPU produces:
import json
import numpy as np
import xgboost as xgb
X = np.array([[0.0], [1.0], [np.nan], [np.nan]], dtype=np.float32)
y = np.array([0.0, 0.0, 1.0, 1.0], dtype=np.float32)
booster = xgb.train({"max_depth": 1}, xgb.DMatrix(X, y), num_boost_round=1)
model = json.loads(booster.save_raw(raw_format="json"))
model["learner"]["gradient_booster"]["model"]["trees"][0]["split_conditions"][0] = float("-inf")
booster.load_model(bytearray(json.dumps(model), encoding="ascii"))
json.loads(booster.save_raw(raw_format="json")) # fine: -Infinity
json.loads(booster.get_dump(dump_format="json")[0]) # JSONDecodeErrorEnvironment
- GPU: xgboost 3.4.1 from PyPI, Python 3.12, Tesla T4, CUDA 13.1, RHEL 8.10
- CPU: xgboost 3.4.1 from PyPI, Python 3.14, macOS arm64, and
masterat085dff4
Affects v3.3.0 onwards.
Will you submit a PR?
Yes, it writes non-finite split conditions as -Infinity / Infinity / NaN, the same tokens save_model uses, and leaves finite values unchanged.
Source: dmlc/xgboost