Ray actor with num_cpus=0

Hi guys, I would be appreciate to know what exact behavior of an actor with num_cpus=0.

@ray.remote(num_cpus=0)
class ActorClass:
    pass

Are there any docs on this?

Thanks in advance!

It will be an actor who needs 0 CPUs to run.

What does that mean 0 CPUs to run? I still see ray::Foo from top command when performing the following

@ray.remote(num_cpus=0)
class Foo:
    pass

f = Foo.remote()

All resources are logic resources. It just means it’ll cost 0 CPUs to run. It has nothing to do with the physical resources. (Resources (CPUs, GPUs) — Ray 0.6.3 documentation)
You can launch a ray cluster and telling it has 1k cpus while your local host only have 8 cpus.

Ok, I see, thanks! One more related question. Suppose a system has 16 CPUs.

import ray
ray.init(num_cpus=16)

@ray.remote(num_cpus=4)
class Foo:
    def foo(self):
        some_multithreaded_function() # this function is supposed to use all 16 threads/CPUs to do computation

f = Foo.remote()
f.foo.remote()

Will some_multithreaded_function(), which is called within from foo(), use all CPUs for threading or 4 CPUs only?

If the answer is 4 CPUs only, what is the benefit/reason for specifying num_cpus=4 for the actor?

I read the docs, but I am still missing something. How can an actor need 0 CPUs to run? If it contains code, it has to run on a CPU, right? What would be an example of an actor that doesn’t need a CPU?

Or, does it just mean that is doesn’t need a RESERVED CPU? If that’s the case, what is the difference between specifying needing 0 CPUs and not specifying CPU resources?

These are just logical resources. For example, if you specify 10 cpus, then you can’t create 11 actors using 1 CPU each. The 11th will just hang there until there is enough resource. It’s not like k8s where CPUs are reserved.
For 0 CPUs, you can launch infinite actors until it crashes the system.

They are just logic resources, so no reservation for the resources from the hardware or any isolations here.

This only helps ray to control how many actors you can create. For example, you won’t be able to create 5 Foo. The first 4 will be created and the last one will hang until there is enough resources.

Could you explain what the benefit to Ray is to know how many actors can be created?

@yic, just a friendly reminder.

I don’t think it’s about ray. It’s more about the user can control how many actors they can create per node.

1 Like