# Grouping variables together in ray tune

**URL:** <https://discuss.ray.io/t/grouping-variables-together-in-ray-tune/6797>\
**Category:** Ray Tune\
**Created:** [July 12, 2022, 2:58pm UTC](https://discuss.ray.io/t/grouping-variables-together-in-ray-tune/6797 "2022-07-12T14:58:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pamparana](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@pamparana](https://discuss.ray.io/u/pamparana)\
**Post date:** [July 12, 2022, 2:58pm UTC](https://discuss.ray.io/t/grouping-variables-together-in-ray-tune/6797/1 "2022-07-12T14:58:37Z")

</div>

I have a ray tune configuration which is specified as follows:

```auto

config={
         "params.central_layer_sizes:": tune.grid_search([[1600,800], [403, 200], [400, 400]]),
         "params.right_layer_sizes": tune.grid_search([[48,24], [12, 6], [12, 12]]),
         "params.joint_layer_sizes": tune.grid_search([[800,400], [400, 200], [400, 400]])
     }

```

I would like to sample in a concerted way i.e. the index 0 of the three variables go together, index 1 and index 2. Is there a way to specify such grouping out of the box in ray? At the moment, everything is sampled independent of the other and generating configurations that I do not want to test.

---

<div class="post-metadata">

**Author:** ![xwjiang2010](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/xwjiang2010/32/1476_2.png) [@xwjiang2010](https://discuss.ray.io/u/xwjiang2010)\
**Post date:** [July 12, 2022, 3:20pm UTC](https://discuss.ray.io/t/grouping-variables-together-in-ray-tune/6797/2 "2022-07-12T15:20:22Z")

</div>

got it, could you try grouping them before passing into config and handle it in your function?

Something like:

```auto
tune.grid_search([[[1600,800], [48,24], [800,400]], [...], [...]])

```

---

<div class="post-metadata">

**Author:** ![pamparana](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@pamparana](https://discuss.ray.io/u/pamparana)\
**Post date:** [July 12, 2022, 4:12pm UTC](https://discuss.ray.io/t/grouping-variables-together-in-ray-tune/6797/3 "2022-07-12T16:12:45Z")

</div>

The thing is I am using Facebook hydra for specifying all the configurations and it is a nice way to somehow pass directly from config to the object instantiation but I am guessing there is no way to bypass some custom mapping code in the middle.

---

<div class="post-metadata">

**Author:** ![Lars\_Simon\_Zehnder](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/lars_simon_zehnder/32/1185_2.png) [@Lars\_Simon\_Zehnder](https://discuss.ray.io/u/Lars_Simon_Zehnder)\
**Post date:** [July 14, 2022, 7:54pm UTC](https://discuss.ray.io/t/grouping-variables-together-in-ray-tune/6797/4 "2022-07-14T19:54:58Z")

</div>

@pamparana, I don’t know, if this helps with your problem, but with `tune.sample_from()` you can actually define your custom sample functions using for example a `lambda` function as shown [here](https://pytorch.org/tutorials/beginner/hyperparameter_tuning_tutorial.html#configuring-the-search-space) for PyTorch training.
