Sycl implementation for objective functions (#9846)
--------- Co-authored-by: Dmitry Razdoburdin <>
This commit is contained in:
committed by
GitHub
parent
ddab49a8be
commit
43897b8296
@@ -21,6 +21,8 @@
|
||||
#include "../common/math.h"
|
||||
#include "../common/transform.h"
|
||||
|
||||
#include "multiclass_param.h"
|
||||
|
||||
namespace xgboost {
|
||||
namespace obj {
|
||||
|
||||
@@ -28,15 +30,6 @@ namespace obj {
|
||||
DMLC_REGISTRY_FILE_TAG(multiclass_obj_gpu);
|
||||
#endif // defined(XGBOOST_USE_CUDA)
|
||||
|
||||
struct SoftmaxMultiClassParam : public XGBoostParameter<SoftmaxMultiClassParam> {
|
||||
int num_class;
|
||||
// declare parameters
|
||||
DMLC_DECLARE_PARAMETER(SoftmaxMultiClassParam) {
|
||||
DMLC_DECLARE_FIELD(num_class).set_lower_bound(1)
|
||||
.describe("Number of output class in the multi-class classification.");
|
||||
}
|
||||
};
|
||||
|
||||
class SoftmaxMultiClassObj : public ObjFunction {
|
||||
public:
|
||||
explicit SoftmaxMultiClassObj(bool output_prob)
|
||||
|
||||
25
src/objective/multiclass_param.h
Normal file
25
src/objective/multiclass_param.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*!
|
||||
* Copyright 2015-2023 by Contributors
|
||||
* \file multiclass_param.h
|
||||
* \brief Definition of multi-class classification parameters.
|
||||
*/
|
||||
#ifndef XGBOOST_OBJECTIVE_MULTICLASS_PARAM_H_
|
||||
#define XGBOOST_OBJECTIVE_MULTICLASS_PARAM_H_
|
||||
|
||||
#include "xgboost/parameter.h"
|
||||
|
||||
namespace xgboost {
|
||||
namespace obj {
|
||||
|
||||
struct SoftmaxMultiClassParam : public XGBoostParameter<SoftmaxMultiClassParam> {
|
||||
int num_class;
|
||||
// declare parameters
|
||||
DMLC_DECLARE_PARAMETER(SoftmaxMultiClassParam) {
|
||||
DMLC_DECLARE_FIELD(num_class).set_lower_bound(1)
|
||||
.describe("Number of output class in the multi-class classification.");
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace obj
|
||||
} // namespace xgboost
|
||||
#endif // XGBOOST_OBJECTIVE_MULTICLASS_PARAM_H_
|
||||
@@ -18,7 +18,11 @@ DMLC_REGISTRY_ENABLE(::xgboost::ObjFunctionReg);
|
||||
namespace xgboost {
|
||||
// implement factory functions
|
||||
ObjFunction* ObjFunction::Create(const std::string& name, Context const* ctx) {
|
||||
auto *e = ::dmlc::Registry< ::xgboost::ObjFunctionReg>::Get()->Find(name);
|
||||
std::string obj_name = name;
|
||||
if (ctx->IsSycl()) {
|
||||
obj_name = GetSyclImplementationName(obj_name);
|
||||
}
|
||||
auto *e = ::dmlc::Registry< ::xgboost::ObjFunctionReg>::Get()->Find(obj_name);
|
||||
if (e == nullptr) {
|
||||
std::stringstream ss;
|
||||
for (const auto& entry : ::dmlc::Registry< ::xgboost::ObjFunctionReg>::List()) {
|
||||
@@ -32,6 +36,22 @@ ObjFunction* ObjFunction::Create(const std::string& name, Context const* ctx) {
|
||||
return pobj;
|
||||
}
|
||||
|
||||
/* If the objective function has sycl-specific implementation,
|
||||
* returns the specific implementation name.
|
||||
* Otherwise return the orginal name without modifications.
|
||||
*/
|
||||
std::string ObjFunction::GetSyclImplementationName(const std::string& name) {
|
||||
const std::string sycl_postfix = "_sycl";
|
||||
auto *e = ::dmlc::Registry< ::xgboost::ObjFunctionReg>::Get()->Find(name + sycl_postfix);
|
||||
if (e != nullptr) {
|
||||
// Function has specific sycl implementation
|
||||
return name + sycl_postfix;
|
||||
} else {
|
||||
// Function hasn't specific sycl implementation
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
void ObjFunction::InitEstimation(MetaInfo const&, linalg::Tensor<float, 1>* base_score) const {
|
||||
CHECK(base_score);
|
||||
base_score->Reshape(1);
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
#include "xgboost/span.h"
|
||||
#include "xgboost/tree_model.h" // RegTree
|
||||
|
||||
#include "regression_param.h"
|
||||
|
||||
#if defined(XGBOOST_USE_CUDA)
|
||||
#include "../common/cuda_context.cuh" // for CUDAContext
|
||||
#include "../common/device_helpers.cuh"
|
||||
@@ -53,14 +55,7 @@ void CheckRegInputs(MetaInfo const& info, HostDeviceVector<bst_float> const& pre
|
||||
DMLC_REGISTRY_FILE_TAG(regression_obj_gpu);
|
||||
#endif // defined(XGBOOST_USE_CUDA)
|
||||
|
||||
struct RegLossParam : public XGBoostParameter<RegLossParam> {
|
||||
float scale_pos_weight;
|
||||
// declare parameters
|
||||
DMLC_DECLARE_PARAMETER(RegLossParam) {
|
||||
DMLC_DECLARE_FIELD(scale_pos_weight).set_default(1.0f).set_lower_bound(0.0f)
|
||||
.describe("Scale the weight of positive examples by this factor");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename Loss>
|
||||
class RegLossObj : public FitIntercept {
|
||||
|
||||
25
src/objective/regression_param.h
Normal file
25
src/objective/regression_param.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*!
|
||||
* Copyright 2015-2023 by Contributors
|
||||
* \file multiclass_param.h
|
||||
* \brief Definition of single-value regression and classification parameters.
|
||||
*/
|
||||
#ifndef XGBOOST_OBJECTIVE_REGRESSION_PARAM_H_
|
||||
#define XGBOOST_OBJECTIVE_REGRESSION_PARAM_H_
|
||||
|
||||
#include "xgboost/parameter.h"
|
||||
|
||||
namespace xgboost {
|
||||
namespace obj {
|
||||
|
||||
struct RegLossParam : public XGBoostParameter<RegLossParam> {
|
||||
float scale_pos_weight;
|
||||
// declare parameters
|
||||
DMLC_DECLARE_PARAMETER(RegLossParam) {
|
||||
DMLC_DECLARE_FIELD(scale_pos_weight).set_default(1.0f).set_lower_bound(0.0f)
|
||||
.describe("Scale the weight of positive examples by this factor");
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace obj
|
||||
} // namespace xgboost
|
||||
#endif // XGBOOST_OBJECTIVE_REGRESSION_PARAM_H_
|
||||
Reference in New Issue
Block a user