# Num\_cpus as a parameter?

**URL:** <https://discuss.ray.io/t/num-cpus-as-a-parameter/4467>\
**Category:** Ray Core\
**Created:** [December 16, 2021, 7:11pm UTC](https://discuss.ray.io/t/num-cpus-as-a-parameter/4467 "2021-12-16T19:11:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbehrendt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mbehrendt/32/516_2.png) [@mbehrendt](https://discuss.ray.io/u/mbehrendt)\
**Post date:** [December 16, 2021, 7:11pm UTC](https://discuss.ray.io/t/num-cpus-as-a-parameter/4467/1 "2021-12-16T19:11:07Z")

</div>

is it possible to specify the value of the `num_cpus` parameter of the `ray.remote` decorator as a parameter determined during runtime?

---

<div class="post-metadata">

**Author:** ![matthewdeng](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/matthewdeng/32/1446_2.png) [@matthewdeng](https://discuss.ray.io/u/matthewdeng)\
**Post date:** [December 16, 2021, 7:17pm UTC](https://discuss.ray.io/t/num-cpus-as-a-parameter/4467/2 "2021-12-16T19:17:34Z")

</div>

Hi @mbehrendt,

You can dynamically specify the value through `.options` - see [Dynamic Remote Parameters](https://docs.ray.io/en/latest/advanced.html#dynamic-remote-parameters).

---

<div class="post-metadata">

**Author:** ![mbehrendt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mbehrendt/32/516_2.png) [@mbehrendt](https://discuss.ray.io/u/mbehrendt)\
**Post date:** [December 16, 2021, 8:14pm UTC](https://discuss.ray.io/t/num-cpus-as-a-parameter/4467/3 "2021-12-16T20:14:39Z")

</div>

great – thank you @matthewdeng

Just a quick follow-up question, based on this statement in the docs you linked to:

> Ray will need to be started with sufficient CPU resources and the relevant custom resources:

Is that also true if the max\_workers value in the cluster.yaml is not yet reached? E.g. all resources on the currently running nodes are exhausted, but if ray scaled by adding more resources, it would be able to run the current task?

Also, if I’d to run nodes of different sizes in the same cluster – would that be possible?

---

<div class="post-metadata">

**Author:** ![matthewdeng](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/matthewdeng/32/1446_2.png) [@matthewdeng](https://discuss.ray.io/u/matthewdeng)\
**Post date:** [December 16, 2021, 8:59pm UTC](https://discuss.ray.io/t/num-cpus-as-a-parameter/4467/4 "2021-12-16T20:59:43Z")

</div>

> Is that also true if the max\_workers value in the cluster.yaml is not yet reached? E.g. all resources on the currently running nodes are exhausted, but if ray scaled by adding more resources, it would be able to run the current task?

Yeah, as long as your cluster scales so that the total available resources is greater than what’s requested by the current task, it will eventually run.

> Also, if I’d to run nodes of different sizes in the same cluster – would that be possible?

Yep, you can specify different [available\_node\_types](https://docs.ray.io/en/master/cluster/config.html#cluster-configuration-available-node-types).

---

<div class="post-metadata">

**Author:** ![mbehrendt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mbehrendt/32/516_2.png) [@mbehrendt](https://discuss.ray.io/u/mbehrendt)\
**Post date:** [December 16, 2021, 9:42pm UTC](https://discuss.ray.io/t/num-cpus-as-a-parameter/4467/5 "2021-12-16T21:42:30Z")

</div>

> [@matthewdeng](#):
>
> Yep, you can specify different [available\_node\_types](https://docs.ray.io/en/master/cluster/config.html#cluster-configuration-available-node-types).

for example – if i created 10 available\_node\_type definitions, each of them backed by a different machine profile. Which algorithm does ray use to pick the node type to provision? Is it based on the closest amount of cpu/mem capacity, or something else?

---

<div class="post-metadata">

**Author:** ![Dmitri](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/dmitri/32/657_2.png) [@Dmitri](https://discuss.ray.io/u/Dmitri)\
**Post date:** [December 16, 2021, 11:13pm UTC](https://discuss.ray.io/t/num-cpus-as-a-parameter/4467/6 "2021-12-16T23:13:33Z")

</div>

The heuristic used is [here](https://github.com/ray-project/ray/blob/29965ad3257baea064dd7af0c26df146a237b67d/python/ray/autoscaler/_private/resource_demand_scheduler.py#L814-L815).

```
# Prioritize matching multiple resource types first, then prioritize
# using all resources, then prioritize overall balance
# of multiple resources.
```

---

<div class="post-metadata">

**Author:** ![mbehrendt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mbehrendt/32/516_2.png) [@mbehrendt](https://discuss.ray.io/u/mbehrendt)\
**Post date:** [December 16, 2021, 11:43pm UTC](https://discuss.ray.io/t/num-cpus-as-a-parameter/4467/7 "2021-12-16T23:43:45Z")

</div>

great - thanks a lot. Is there also a way for me as a developer to somehow explicitly specify deterministically which node type i’d like to have used (and if needed, provisioned on demand) ? E.g. as a dynamic remote parameter?

---

<div class="post-metadata">

**Author:** ![Dmitri](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/dmitri/32/657_2.png) [@Dmitri](https://discuss.ray.io/u/Dmitri)\
**Post date:** [December 17, 2021, 12:30am UTC](https://discuss.ray.io/t/num-cpus-as-a-parameter/4467/8 "2021-12-17T00:30:05Z")

</div>

You can annotate the node with a custom resource in the autoscaling config and then specify that resource in the remote decorator in a ray program.
