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

[Tune] Fix ResourceChangingScheduler dropping PGF args #30304

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions python/ray/air/tests/test_resource_changing.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def training_loop(self) -> None:
scaling_config = self._validate_scaling_config(self.scaling_config)
pgf = scaling_config.as_placement_group_factory()
tr = session.get_trial_resources()
assert pgf.strategy == "SPREAD"
assert pgf == tr, (pgf, tr)
return super().training_loop()

Expand All @@ -65,14 +66,18 @@ def _ray_params(self):
scaling_config = self._validate_scaling_config(self.scaling_config)
pgf = scaling_config.as_placement_group_factory()
tr = session.get_trial_resources()
assert pgf.strategy == "SPREAD"
assert pgf == tr, (scaling_config, pgf, tr)
return super()._ray_params


def test_data_parallel_trainer(ray_start_8_cpus):
num_workers = 2
trainer = AssertingDataParallelTrainer(
train_fn, scaling_config=ScalingConfig(num_workers=num_workers)
train_fn,
scaling_config=ScalingConfig(
num_workers=num_workers, placement_strategy="SPREAD"
),
)
tuner = Tuner(
trainer,
Expand Down Expand Up @@ -108,7 +113,7 @@ def test_gbdt_trainer(ray_start_8_cpus):
trainer = AssertingXGBoostTrainer(
datasets={TRAIN_DATASET_KEY: train_ds},
label_column="target",
scaling_config=ScalingConfig(num_workers=2),
scaling_config=ScalingConfig(num_workers=2, placement_strategy="SPREAD"),
params={
"objective": "binary:logistic",
"eval_metric": ["logloss"],
Expand Down
20 changes: 19 additions & 1 deletion python/ray/train/gbdt_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ray.tune.trainable.util import TrainableUtil
from ray.util.annotations import DeveloperAPI
from ray._private.dict import flatten_dict
from ray.tune.execution.placement_groups import PlacementGroupFactory

if TYPE_CHECKING:
import xgboost_ray
Expand Down Expand Up @@ -298,8 +299,25 @@ def default_resource_request(cls, config):
validated_scaling_config = trainer_cls._validate_scaling_config(
updated_scaling_config
)
return _convert_scaling_config_to_ray_params(
# RayParams PGF drops strategy, args and kwargs so we have to get them
# from ScalingConfig PGF and then create a new PGF combining it
# all together.
pgf_from_scaling_config = (
validated_scaling_config.as_placement_group_factory()
)
pgf_from_ray_params = _convert_scaling_config_to_ray_params(
validated_scaling_config, ray_params_cls, default_ray_params
).get_tune_resources()
new_bundles = pgf_from_ray_params.bundles
final_pgf = PlacementGroupFactory(
new_bundles,
strategy=pgf_from_scaling_config.strategy,
*pgf_from_scaling_config._args,
**pgf_from_scaling_config._kwargs,
)
final_pgf._head_bundle_is_empty = (
pgf_from_ray_params._head_bundle_is_empty
)
return final_pgf

return GBDTTrainable
7 changes: 6 additions & 1 deletion python/ray/tune/schedulers/resource_changing_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,12 @@ def __call__(
base_bundles, added_bundles, increase_by, False
)

pgf = PlacementGroupFactory(new_bundles)
pgf = PlacementGroupFactory(
new_bundles,
strategy=base_trial_resource.strategy,
*base_trial_resource._args,
**base_trial_resource._kwargs,
)
pgf._head_bundle_is_empty = base_trial_resource._head_bundle_is_empty
return pgf

Expand Down