-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
SYCL. Add more test for sycl-objectives #11064
Merged
trivialfis
merged 5 commits into
dmlc:master
from
razdoburdin:dev/sycl/more_tests_for_objectives
Dec 12, 2024
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bd83108
add more tests for sycl-objectives
7ca7faf
linting
b54fd19
Merge branch 'master' into dev/sycl/more_tests_for_objectives
trivialfis f5189f2
fix cuda-linking issue
ed426d1
Merge branch 'dmlc:master' into dev/sycl/more_tests_for_objectives
razdoburdin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to make suggestion on how we should structure the project in the future.