# How to allocate specific gpu to trials when use ray tune

**URL:** <https://discuss.ray.io/t/how-to-allocate-specific-gpu-to-trials-when-use-ray-tune/3004>\
**Category:** Ray Tune\
**Created:** [July 24, 2021, 5:30pm UTC](https://discuss.ray.io/t/how-to-allocate-specific-gpu-to-trials-when-use-ray-tune/3004 "2021-07-24T17:30:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjs](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@mjs](https://discuss.ray.io/u/mjs)\
**Post date:** [July 24, 2021, 5:30pm UTC](https://discuss.ray.io/t/how-to-allocate-specific-gpu-to-trials-when-use-ray-tune/3004/1 "2021-07-24T17:30:56Z")

</div>

I have a question about changing the gpu allocation order when using ray tune. For example, Ray tune allocates 2 trials to gpu 0 and then to gpu 1 when I set resource\_per\_trial gpu to 0.5. However, I want to assign trials to gpu 0, 1 and 2 each. Further, when I create a trial, I want to assign it to the specific gpu (i.e., assign first trial to gpu 2, not 0). Please let me know if there is a way to do this.

---

<div class="post-metadata">

**Author:** ![rliaw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/rliaw/32/24_2.png) [@rliaw](https://discuss.ray.io/u/rliaw)\
**Post date:** [July 24, 2021, 5:35pm UTC](https://discuss.ray.io/t/how-to-allocate-specific-gpu-to-trials-when-use-ray-tune/3004/2 "2021-07-24T17:35:15Z")

</div>

Hey @mjs , thanks for making this post!

Ray uses CUDA\_VISIBLE\_DEVICES to do resource allocation. So if you want to assign a trial to a specific GPU, you’ll need to manually set CUDA\_VISIBLE\_DEVICES by yourself.

What type of allocation pattern do you have specifically?

---

<div class="post-metadata">

**Author:** ![mjs](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@mjs](https://discuss.ray.io/u/mjs)\
**Post date:** [July 24, 2021, 7:16pm UTC](https://discuss.ray.io/t/how-to-allocate-specific-gpu-to-trials-when-use-ray-tune/3004/3 "2021-07-24T19:16:01Z")

</div>

I am using 4 GPUs. And I have 4 data sets A, B, C and D. I think of the allocation pattern as below.

“Trial 1, 2, 3, 4” to train a neural network composed of hyperparamters F are run simultaneously on gpus 0, 1, 2, and 3. Then, I want to train the network using data set A on gpu 0, data set B on gpu 1, data set C on gpu 2, and data set C on gpu 3.

At the same time, I want to create additional hyperparamters called G and H on each GPU as above.

Therefore, each gpu must allocate 0.33 resources for one hyperparamter trial.

“F” trials are executed concurrently because I want to  
Data set A —\> GPU 0 ----\> “F” trial 0 ----\> metric for dataset A -----\> aggregate metric A, B, C, D  
Data set B —\> GPU 1 ----\> “F” trial 1 ----\> metric for dataset B  
Data set C —\> GPU 2 ----\> “F” trial 2 ----\> metric for dataset C  
Data set D —\> GPU 3 ----\> “F” trial 3 ----\> metric for dataset D

GPU 0 has “F” trial 0, “G” trial 0, “H” trial 0.  
GPU 1 has “F” trial 1, “G” trial 1, “H” trial 1.  
GPU 2 has “F” trial 2, “G” trail 2, “H” trial 2.  
GPU 3 has “F” trial 3, “G” trial 3, “H” trial 3.

Therefore, each GPU allocates 0.33 of its memory to each “–” trial.

---

<div class="post-metadata">

**Author:** ![rliaw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/rliaw/32/24_2.png) [@rliaw](https://discuss.ray.io/u/rliaw)\
**Post date:** [July 25, 2021, 1:57am UTC](https://discuss.ray.io/t/how-to-allocate-specific-gpu-to-trials-when-use-ray-tune/3004/4 "2021-07-25T01:57:38Z")

</div>

I think you should probably use Ray Core for this. Are “F”, “G”, and “H” different values of the same parameter?

---

<div class="post-metadata">

**Author:** ![mjs](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@mjs](https://discuss.ray.io/u/mjs)\
**Post date:** [July 25, 2021, 7:05am UTC](https://discuss.ray.io/t/how-to-allocate-specific-gpu-to-trials-when-use-ray-tune/3004/5 "2021-07-25T07:05:58Z")

</div>

Trials 0,1,2 and 3 of F have the same parameters. However, I consider the case where F, G and H are all different parameters.
