Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PseudoHuberLoss::LoadConfig() #9574

Closed
wants to merge 3 commits into from
Closed

Conversation

hcho3
Copy link
Collaborator

@hcho3 hcho3 commented Sep 12, 2023

This pull request fixes the serialization of PseudoHuberLoss.

Update. The bug also appears when using the JSON serializer.

Minimal reproducer:

import os
from tempfile import TemporaryDirectory

import xgboost as xgb
from sklearn.datasets import load_diabetes

X, y = load_diabetes(return_X_y=True)
dtrain = xgb.DMatrix(X, label=y)
param = {
    "max_depth": 8,
    "eta": 1,
    "verbosity": 0,
    "objective": "reg:pseudohubererror",
}
xgb_model = xgb.train(
    param,
    dtrain,
    num_boost_round=10,
    evals=[(dtrain, "train")],
)
with TemporaryDirectory() as tmpdir:
    model_name = "model.json"
    #  model_name = "model.model"
    model_path = os.path.join(tmpdir, model_name)
    xgb_model.save_model(model_path)

Error message

xgboost.core.XGBoostError: [13:04:11] xgboost/src/common/json.cc:166: Object of type Null can not be indexed by string.
Stack trace:
  [bt] (0) xgboost/lib/libxgboost.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x59) [0x7f385dc32bbd]
  [bt] (1) xgboost/lib/libxgboost.so(xgboost::Value::operator[](std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+0xa3) [0x7f385dd420c1]
  [bt] (2) xgboost/lib/libxgboost.so(xgboost::Json::operator[](std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const+0x36) [0x7f385dc34736]
  [bt] (3) xgboost/lib/libxgboost.so(xgboost::metric::PseudoErrorLoss::LoadConfig(xgboost::Json const&)+0x62) [0x7f385dfbac9c]
  [bt] (4) xgboost/lib/libxgboost.so(xgboost::LearnerImpl::EvalOneIter(int, std::vector<std::shared_ptr<xgboost::DMatrix>, std::allocator<std::shared_ptr<xgboost::DMatrix> > > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)+0x29b) [0x7f385df6e299]
  [bt] (5) xgboost/lib/libxgboost.so(XGBoosterEvalOneIter+0x24c) [0x7f385dc0fe0e]

@trivialfis
Copy link
Member

Apologies for the bug. let me fix it.

@trivialfis
Copy link
Member

I opened a different PR: #9575 , which adds the configuration to objective and have some tests.

The configuration passing is only implemented in the latest XGBoost (2.0) for metrics like ranking and quantile. I missed the pseudo huber function.

@hcho3 hcho3 closed this in #9575 Sep 13, 2023
@hcho3 hcho3 deleted the fix_mphe_config branch February 14, 2024 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants