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

[train] Disallow trainer_resources() in ScalingConfig for GBDT trainers #39059

Merged
merged 11 commits into from
Sep 6, 2023
1 change: 1 addition & 0 deletions python/ray/air/_internal/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def ensure_only_allowed_dataclass_keys_updated(
key
for key in prohibited_keys
if dataclass.__dict__[key] != default_data.__dict__[key]
and (dataclass.__dict__[key] or default_data.__dict__[key])
]
if bad_keys:
raise ValueError(
Expand Down
3 changes: 2 additions & 1 deletion python/ray/train/gbdt_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ class GBDTTrainer(BaseTrainer):
**train_kwargs: Additional kwargs passed to framework ``train()`` function.
"""

_scaling_config_allowed_keys = BaseTrainer._scaling_config_allowed_keys + [
_scaling_config_allowed_keys = [
"_max_cpu_fraction_per_node",
"num_workers",
"resources_per_worker",
"use_gpu",
Expand Down
8 changes: 8 additions & 0 deletions python/ray/train/tests/test_lightgbm_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ def test_default_parameters_scaling_config():
assert trainer._ray_params.cpus_per_actor == 4


def test_lightgbm_trainer_resources():
"""`trainer_resources` is not allowed in the scaling config"""
with pytest.raises(ValueError):
LightGBMTrainer._validate_scaling_config(
ScalingConfig(trainer_resources={"something": 1})
)


if __name__ == "__main__":
import pytest
import sys
Expand Down
9 changes: 8 additions & 1 deletion python/ray/train/tests/test_xgboost_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def test_fit_with_advanced_scaling_config(ray_start_4_cpus):
valid_dataset = ray.data.from_pandas(test_df)
trainer = ScalingConfigAssertingXGBoostTrainer(
scaling_config=ScalingConfig(
trainer_resources={"CPU": 0},
num_workers=2,
placement_strategy="SPREAD",
_max_cpu_fraction_per_node=0.9,
Expand Down Expand Up @@ -216,6 +215,14 @@ def _train(self, params, dtrain, **kwargs):
trainer.fit()


def test_xgboost_trainer_resources():
"""`trainer_resources` is not allowed in the scaling config"""
with pytest.raises(ValueError):
XGBoostTrainer._validate_scaling_config(
ScalingConfig(trainer_resources={"something": 1})
)


if __name__ == "__main__":
import pytest
import sys
Expand Down