Skip to content

Commit a277aca

Browse files
krfrickeamogkam
authored andcommitted
[tune] Allow 0 CPU head bundles in for placement group factories (#15338)
1 parent 0b4b444 commit a277aca

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

python/ray/tune/tests/test_trial_runner_pg.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,20 @@ def testPlacementGroupDistributedTrainingWithActorReuse(self):
231231
self.testPlacementGroupDistributedTraining(reuse_actors=True)
232232

233233

234+
class PlacementGroupNoAutoSetupTest(unittest.TestCase):
235+
def testPlacementGroupNoCPUDriver(self):
236+
"""Bundles with only GPU:1 but no CPU should work"""
237+
ray.init(num_gpus=1, num_cpus=1)
238+
239+
pgf = PlacementGroupFactory([{"GPU": 1, "CPU": 0}, {"CPU": 1}])
240+
241+
def train(config):
242+
time.sleep(1)
243+
return 5
244+
245+
tune.run(train, resources_per_trial=pgf)
246+
247+
234248
if __name__ == "__main__":
235249
import pytest
236250
sys.exit(pytest.main(["-v", __file__]))

python/ray/tune/utils/placement_groups.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ def __init__(self,
118118

119119
self._bind()
120120

121+
@property
122+
def head_cpus(self):
123+
return self._bundles[0].get("CPU", None)
124+
121125
def _bind(self):
122126
sig = signature(placement_group)
123127
try:
@@ -400,6 +404,11 @@ def get_full_actor_cls(self, trial: "Trial",
400404
# Only custom resources remain in `first_bundle`
401405
resources = first_bundle or None
402406

407+
if num_cpus is None:
408+
# If the placement group specifically set the number
409+
# of CPUs to 0, use this.
410+
num_cpus = pgf.head_cpus
411+
403412
logger.debug(f"For trial {trial} use pg {pg.id}")
404413

405414
return actor_cls.options(

0 commit comments

Comments
 (0)