-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SYCL. Add more test for sycl-objectives (#11064)
- Loading branch information
1 parent
3162e0d
commit a2a348b
Showing
14 changed files
with
416 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
*/ | ||
// Dummy file to keep the CUDA tests. | ||
|
||
#include "test_aft_obj.cc" | ||
#include "test_aft_obj_cpu.cc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright 2020-2024 by XGBoost Contributors | ||
*/ | ||
#ifndef XGBOOST_TEST_AFT_OBJ_H_ | ||
#define XGBOOST_TEST_AFT_OBJ_H_ | ||
|
||
#include <xgboost/context.h> // for Context | ||
|
||
namespace xgboost::common { | ||
|
||
void TestAFTObjConfiguration(const Context* ctx); | ||
|
||
void TestAFTObjGPairUncensoredLabels(const Context* ctx); | ||
|
||
void TestAFTObjGPairLeftCensoredLabels(const Context* ctx); | ||
|
||
void TestAFTObjGPairRightCensoredLabels(const Context* ctx); | ||
|
||
void TestAFTObjGPairIntervalCensoredLabels(const Context* ctx); | ||
|
||
} // namespace xgboost::common | ||
|
||
#endif // XGBOOST_TEST_AFT_OBJ_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright 2020-2024, XGBoost Contributors | ||
*/ | ||
#include <gtest/gtest.h> | ||
#include <memory> | ||
#include <vector> | ||
#include <limits> | ||
#include <cmath> | ||
|
||
#include "xgboost/objective.h" | ||
#include "xgboost/logging.h" | ||
#include "../helpers.h" | ||
#include "test_aft_obj.h" | ||
|
||
namespace xgboost::common { | ||
TEST(Objective, DeclareUnifiedTest(AFTObjConfiguration)) { | ||
auto ctx = MakeCUDACtx(GPUIDX); | ||
TestAFTObjConfiguration(&ctx); | ||
} | ||
|
||
TEST(Objective, DeclareUnifiedTest(AFTObjGPairUncensoredLabels)) { | ||
auto ctx = MakeCUDACtx(GPUIDX); | ||
TestAFTObjGPairUncensoredLabels(&ctx); | ||
} | ||
|
||
TEST(Objective, DeclareUnifiedTest(AFTObjGPairLeftCensoredLabels)) { | ||
auto ctx = MakeCUDACtx(GPUIDX); | ||
TestAFTObjGPairLeftCensoredLabels(&ctx); | ||
} | ||
|
||
TEST(Objective, DeclareUnifiedTest(AFTObjGPairRightCensoredLabels)) { | ||
auto ctx = MakeCUDACtx(GPUIDX); | ||
TestAFTObjGPairRightCensoredLabels(&ctx); | ||
} | ||
|
||
TEST(Objective, DeclareUnifiedTest(AFTObjGPairIntervalCensoredLabels)) { | ||
auto ctx = MakeCUDACtx(GPUIDX); | ||
TestAFTObjGPairIntervalCensoredLabels(&ctx); | ||
} | ||
|
||
} // namespace xgboost::common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,6 +124,167 @@ void TestsLogisticRawGPair(const Context* ctx) { | |
{0.25f, 0.24f, 0.20f, 0.19f, 0.25f, 0.24f, 0.20f, 0.19f}); | ||
} | ||
|
||
void TestPoissonRegressionGPair(const Context* ctx) { | ||
std::vector<std::pair<std::string, std::string>> args; | ||
std::unique_ptr<ObjFunction> obj { | ||
ObjFunction::Create("count:poisson", ctx) | ||
}; | ||
|
||
args.emplace_back("max_delta_step", "0.1f"); | ||
obj->Configure(args); | ||
|
||
CheckObjFunction(obj, | ||
{ 0, 0.1f, 0.9f, 1, 0, 0.1f, 0.9f, 1}, | ||
{ 0, 0, 0, 0, 1, 1, 1, 1}, | ||
{ 1, 1, 1, 1, 1, 1, 1, 1}, | ||
{ 1, 1.10f, 2.45f, 2.71f, 0, 0.10f, 1.45f, 1.71f}, | ||
{1.10f, 1.22f, 2.71f, 3.00f, 1.10f, 1.22f, 2.71f, 3.00f}); | ||
CheckObjFunction(obj, | ||
{ 0, 0.1f, 0.9f, 1, 0, 0.1f, 0.9f, 1}, | ||
{ 0, 0, 0, 0, 1, 1, 1, 1}, | ||
{}, // Empty weight | ||
{ 1, 1.10f, 2.45f, 2.71f, 0, 0.10f, 1.45f, 1.71f}, | ||
{1.10f, 1.22f, 2.71f, 3.00f, 1.10f, 1.22f, 2.71f, 3.00f}); | ||
} | ||
|
||
void TestPoissonRegressionBasic(const Context* ctx) { | ||
std::vector<std::pair<std::string, std::string>> args; | ||
std::unique_ptr<ObjFunction> obj { | ||
ObjFunction::Create("count:poisson", ctx) | ||
}; | ||
|
||
obj->Configure(args); | ||
CheckConfigReload(obj, "count:poisson"); | ||
|
||
// test label validation | ||
EXPECT_ANY_THROW(CheckObjFunction(obj, {0}, {-1}, {1}, {0}, {0})) | ||
<< "Expected error when label < 0 for PoissonRegression"; | ||
|
||
// test ProbToMargin | ||
EXPECT_NEAR(obj->ProbToMargin(0.1f), -2.30f, 0.01f); | ||
EXPECT_NEAR(obj->ProbToMargin(0.5f), -0.69f, 0.01f); | ||
EXPECT_NEAR(obj->ProbToMargin(0.9f), -0.10f, 0.01f); | ||
|
||
// test PredTransform | ||
HostDeviceVector<bst_float> io_preds = {0, 0.1f, 0.5f, 0.9f, 1}; | ||
std::vector<bst_float> out_preds = {1, 1.10f, 1.64f, 2.45f, 2.71f}; | ||
obj->PredTransform(&io_preds); | ||
auto& preds = io_preds.HostVector(); | ||
for (int i = 0; i < static_cast<int>(io_preds.Size()); ++i) { | ||
EXPECT_NEAR(preds[i], out_preds[i], 0.01f); | ||
} | ||
} | ||
|
||
void TestGammaRegressionGPair(const Context* ctx) { | ||
std::vector<std::pair<std::string, std::string>> args; | ||
std::unique_ptr<ObjFunction> obj { | ||
ObjFunction::Create("reg:gamma", ctx) | ||
}; | ||
|
||
obj->Configure(args); | ||
CheckObjFunction(obj, | ||
{0, 0.1f, 0.9f, 1, 0, 0.1f, 0.9f, 1}, | ||
{2, 2, 2, 2, 1, 1, 1, 1}, | ||
{1, 1, 1, 1, 1, 1, 1, 1}, | ||
{-1, -0.809, 0.187, 0.264, 0, 0.09f, 0.59f, 0.63f}, | ||
{2, 1.809, 0.813, 0.735, 1, 0.90f, 0.40f, 0.36f}); | ||
CheckObjFunction(obj, | ||
{0, 0.1f, 0.9f, 1, 0, 0.1f, 0.9f, 1}, | ||
{2, 2, 2, 2, 1, 1, 1, 1}, | ||
{}, // Empty weight | ||
{-1, -0.809, 0.187, 0.264, 0, 0.09f, 0.59f, 0.63f}, | ||
{2, 1.809, 0.813, 0.735, 1, 0.90f, 0.40f, 0.36f}); | ||
} | ||
|
||
void TestGammaRegressionBasic(const Context* ctx) { | ||
std::vector<std::pair<std::string, std::string>> args; | ||
std::unique_ptr<ObjFunction> obj{ObjFunction::Create("reg:gamma", ctx)}; | ||
|
||
obj->Configure(args); | ||
CheckConfigReload(obj, "reg:gamma"); | ||
|
||
// test label validation | ||
EXPECT_ANY_THROW(CheckObjFunction(obj, {0}, {0}, {1}, {0}, {0})) | ||
<< "Expected error when label = 0 for GammaRegression"; | ||
EXPECT_ANY_THROW(CheckObjFunction(obj, {-1}, {-1}, {1}, {-1}, {-3})) | ||
<< "Expected error when label < 0 for GammaRegression"; | ||
|
||
// test ProbToMargin | ||
EXPECT_NEAR(obj->ProbToMargin(0.1f), -2.30f, 0.01f); | ||
EXPECT_NEAR(obj->ProbToMargin(0.5f), -0.69f, 0.01f); | ||
EXPECT_NEAR(obj->ProbToMargin(0.9f), -0.10f, 0.01f); | ||
|
||
// test PredTransform | ||
HostDeviceVector<bst_float> io_preds = {0, 0.1f, 0.5f, 0.9f, 1}; | ||
std::vector<bst_float> out_preds = {1, 1.10f, 1.64f, 2.45f, 2.71f}; | ||
obj->PredTransform(&io_preds); | ||
auto& preds = io_preds.HostVector(); | ||
for (int i = 0; i < static_cast<int>(io_preds.Size()); ++i) { | ||
EXPECT_NEAR(preds[i], out_preds[i], 0.01f); | ||
} | ||
} | ||
|
||
void TestTweedieRegressionGPair(const Context* ctx) { | ||
std::vector<std::pair<std::string, std::string>> args; | ||
std::unique_ptr<ObjFunction> obj{ObjFunction::Create("reg:tweedie", ctx)}; | ||
|
||
args.emplace_back("tweedie_variance_power", "1.1f"); | ||
obj->Configure(args); | ||
|
||
CheckObjFunction(obj, | ||
{ 0, 0.1f, 0.9f, 1, 0, 0.1f, 0.9f, 1}, | ||
{ 0, 0, 0, 0, 1, 1, 1, 1}, | ||
{ 1, 1, 1, 1, 1, 1, 1, 1}, | ||
{ 1, 1.09f, 2.24f, 2.45f, 0, 0.10f, 1.33f, 1.55f}, | ||
{0.89f, 0.98f, 2.02f, 2.21f, 1, 1.08f, 2.11f, 2.30f}); | ||
CheckObjFunction(obj, | ||
{ 0, 0.1f, 0.9f, 1, 0, 0.1f, 0.9f, 1}, | ||
{ 0, 0, 0, 0, 1, 1, 1, 1}, | ||
{}, // Empty weight. | ||
{ 1, 1.09f, 2.24f, 2.45f, 0, 0.10f, 1.33f, 1.55f}, | ||
{0.89f, 0.98f, 2.02f, 2.21f, 1, 1.08f, 2.11f, 2.30f}); | ||
ASSERT_EQ(obj->DefaultEvalMetric(), std::string{"[email protected]"}); | ||
} | ||
|
||
void TestTweedieRegressionBasic(const Context* ctx) { | ||
std::vector<std::pair<std::string, std::string>> args; | ||
std::unique_ptr<ObjFunction> obj{ObjFunction::Create("reg:tweedie", ctx)}; | ||
|
||
obj->Configure(args); | ||
CheckConfigReload(obj, "reg:tweedie"); | ||
|
||
// test label validation | ||
EXPECT_ANY_THROW(CheckObjFunction(obj, {0}, {-1}, {1}, {0}, {0})) | ||
<< "Expected error when label < 0 for TweedieRegression"; | ||
|
||
// test ProbToMargin | ||
EXPECT_NEAR(obj->ProbToMargin(0.1f), -2.30f, 0.01f); | ||
EXPECT_NEAR(obj->ProbToMargin(0.5f), -0.69f, 0.01f); | ||
EXPECT_NEAR(obj->ProbToMargin(0.9f), -0.10f, 0.01f); | ||
|
||
// test PredTransform | ||
HostDeviceVector<bst_float> io_preds = {0, 0.1f, 0.5f, 0.9f, 1}; | ||
std::vector<bst_float> out_preds = {1, 1.10f, 1.64f, 2.45f, 2.71f}; | ||
obj->PredTransform(&io_preds); | ||
auto& preds = io_preds.HostVector(); | ||
for (int i = 0; i < static_cast<int>(io_preds.Size()); ++i) { | ||
EXPECT_NEAR(preds[i], out_preds[i], 0.01f); | ||
} | ||
} | ||
|
||
void TestCoxRegressionGPair(const Context* ctx) { | ||
std::vector<std::pair<std::string, std::string>> args; | ||
std::unique_ptr<ObjFunction> obj{ObjFunction::Create("survival:cox", ctx)}; | ||
|
||
obj->Configure(args); | ||
CheckObjFunction(obj, | ||
{ 0, 0.1f, 0.9f, 1, 0, 0.1f, 0.9f, 1}, | ||
{ 0, -2, -2, 2, 3, 5, -10, 100}, | ||
{ 1, 1, 1, 1, 1, 1, 1, 1}, | ||
{ 0, 0, 0, -0.799f, -0.788f, -0.590f, 0.910f, 1.006f}, | ||
{ 0, 0, 0, 0.160f, 0.186f, 0.348f, 0.610f, 0.639f}); | ||
} | ||
|
||
void TestAbsoluteError(const Context* ctx) { | ||
std::unique_ptr<ObjFunction> obj{ObjFunction::Create("reg:absoluteerror", ctx)}; | ||
obj->Configure({}); | ||
|
Oops, something went wrong.