Search code examples
pythoncpudistributed-computingray

Limiting CPU resources of Ray


I'm trying to manage the resources of a remote machine that we use for a daily task (that uses Ray). Is it possible to limit the number of CPUs (or equivalently the number of workers) that Ray uses?

The remote machine has 16 cores. Can I limit Ray to use only 12 of them or so?


Solution

  • You can limit resources using:

    # To start a head node.
    ray start --head --num-cpus=12
    
    # To start a non-head node.
    ray start --redis-address=<redis-address> --num-cpus=12
    

    Or via ray.init:

    ray.init(num_cpus=12)
    

    Source: Ray documentation.