Trials with remote function calls not scheduled


Say I have a function run_trial to be called by with different hyperparameter configurations. Further, inside run_trial, a remote function is called and the result is retrieved via ray.get.

However when executing, none of the trials is finished and Ray outputs that tasks cannot be scheduled.

An MWE is:

import ray
import time
from ray import tune

def remote_hello(name):
    """a function to be called inside MyClass"""
    return "Hello, {}!".format(name)

class MyClass:
    def hello(self, name):
        ret_id = remote_hello.remote(name)
        return ray.get(ret_id)

def run_trial(config):
    obj = MyClass()
    ret = obj.hello(config['name'])

trial_config = {
    'name': tune.choice(['Ray', 'Tune'])

analysis =

The output is something like:

The actor or task with ID {some id} cannot be scheduled right now. You can ignore this message if this Ray cluster is expected to auto-scale or if you specified a runtime_env for this actor or task, which may take time to install.  Otherwise, this is likely due to all cluster resources being claimed by actors. To resolve the issue, consider creating fewer actors or increasing the resources available to this Ray cluster.
Required resources for this actor or task: {CPU_group_0: 1.000000}

The reason that the tasks cannot be scheduled is: to call remote functions, you need to specify extra resources, which I didn’t do.

One solution is to use tune.PlacementGroupFactory, which I found here.

analysis =
            [{"CPU": 1}, {"CPU": 1}], strategy="PACK"

The first {"CPU": 1} specifies the number of CPUs for the main function,
while the second {"CPU": 1} specifies the number of CPUs for remote function calls.