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

[python-package] Expose ObjectiveFunction class #6586

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Skip cuda testing
  • Loading branch information
Atanas Dimitrov committed Aug 1, 2024
commit b246f606ebeacd22f77a2294b0baca26d103e9d3
12 changes: 7 additions & 5 deletions tests/python_package_test/test_engine.py
Original file line number Diff line number Diff line change
@@ -4413,22 +4413,24 @@ def test_quantized_training():
],
)
@pytest.mark.parametrize("num_boost_round", [5, 15])
@pytest.mark.skipif(getenv("TASK", "") == "cuda", reason="Skip due to ObjectiveFunction not exposed for cuda devices.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why couldn't this also be exposed for the CUDA implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It segfaults on the CI tests, and I cannot build the CUDA version on MacOS.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where exactly does it segfault? 🤔 it seems like this should work 😅

def test_objective_function_class(use_weight, test_data, num_boost_round):
X, y = test_data["df"]
rng = np.random.default_rng()
weight = rng.choice([1, 2], y.shape) if use_weight else None
lgb_train = lgb.Dataset(X, y, weight=weight, init_score=np.zeros((len(y), test_data["num_class"])))

params = {"verbose": -1, "objective": test_data["objective_name"], "num_class": test_data["num_class"]}
params = {
"verbose": -1,
"objective": test_data["objective_name"],
"num_class": test_data["num_class"],
"device": "cpu",
}
builtin_loss = builtin_objective(test_data["objective_name"], copy.deepcopy(params))

params["objective"] = builtin_loss
booster_exposed = lgb.train(params, lgb_train, num_boost_round=num_boost_round)

if getenv("TASK", "") != "cpu":
with pytest.raises(lgb.basic.LightGBMError):
builtin_loss(y, lgb_train)
return
params["objective"] = test_data["objective_name"]
booster = lgb.train(params, lgb_train, num_boost_round=num_boost_round)

Loading
Oops, something went wrong.