# Right way to use tuple action space

**URL:** <https://discuss.ray.io/t/right-way-to-use-tuple-action-space/3594>\
**Category:** RLlib\
**Created:** [September 22, 2021, 1:40pm UTC](https://discuss.ray.io/t/right-way-to-use-tuple-action-space/3594 "2021-09-22T13:40:20Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ofir\_Abu](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/ofir_abu/32/650_2.png) [@Ofir\_Abu](https://discuss.ray.io/u/Ofir_Abu)\
**Post date:** [September 22, 2021, 1:40pm UTC](https://discuss.ray.io/t/right-way-to-use-tuple-action-space/3594/1 "2021-09-22T13:40:20Z")

</div>

Hi there, I’m using a custom environment with a tuple (gym space) action space.  
TL;DR - I’m having trouble about how should I construct the output of the model from the forward function.

Specifically:  
my action space is defined as:

```auto
Tuple((DiscreteWithDType(9, dtype=np.uint8), DiscreteWithDType(9, dtype=np.uint8)))

```

And I don’t know how to output the value in the forwad pass, is there some example to look at?

---

<div class="post-metadata">

**Author:** ![Ofir\_Abu](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/ofir_abu/32/650_2.png) [@Ofir\_Abu](https://discuss.ray.io/u/Ofir_Abu)\
**Post date:** [September 23, 2021, 8:26am UTC](https://discuss.ray.io/t/right-way-to-use-tuple-action-space/3594/2 "2021-09-23T08:26:12Z")

</div>

I know it’s not enough time since the last update but time is of the essence ☹

I just need an example of the shape and type of the output forward model for this kind of action space (any tupled action space will do).

---

<div class="post-metadata">

**Author:** ![mannyv](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mannyv/32/606_2.png) [@mannyv](https://discuss.ray.io/u/mannyv)\
**Post date:** [September 23, 2021, 12:48pm UTC](https://discuss.ray.io/t/right-way-to-use-tuple-action-space/3594/3 "2021-09-23T12:48:32Z")

</div>

Hi @Ofir_Abu,

Perhaps looking through this example will help you figure out what you need.

> <https://github.com/ray-project/ray/blob/698b4eeed3e2699f3181baeadecf966702a55eaf/rllib/examples/two_step_game.py>

---

<div class="post-metadata">

**Author:** ![mannyv](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mannyv/32/606_2.png) [@mannyv](https://discuss.ray.io/u/mannyv)\
**Post date:** [September 23, 2021, 12:54pm UTC](https://discuss.ray.io/t/right-way-to-use-tuple-action-space/3594/4 "2021-09-23T12:54:38Z")

</div>

@Ofir_Abu

This function here should also help:

> <https://github.com/ray-project/ray/blob/698b4eeed3e2699f3181baeadecf966702a55eaf/rllib/models/catalog.py#L295-L329>

---

<div class="post-metadata">

**Author:** ![Ofir\_Abu](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/ofir_abu/32/650_2.png) [@Ofir\_Abu](https://discuss.ray.io/u/Ofir_Abu)\
**Post date:** [September 23, 2021, 1:15pm UTC](https://discuss.ray.io/t/right-way-to-use-tuple-action-space/3594/5 "2021-09-23T13:15:18Z")

</div>

Thank you! The first example helps me, but I specifically have trouble with a custom tf model, I don’t know how to define the type and shape of the forward pass.

I guess I will debug a simple case of non-costum model to understand it, but if someone has a reference that would be a great help 🙂

---

<div class="post-metadata">

**Author:** ![rusu24edward](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/rusu24edward/32/333_2.png) [@rusu24edward](https://discuss.ray.io/u/rusu24edward)\
**Post date:** [September 23, 2021, 3:43pm UTC](https://discuss.ray.io/t/right-way-to-use-tuple-action-space/3594/6 "2021-09-23T15:43:10Z")

</div>

@Ofir_Abu what is `DiscreteWithDType`? I’m not familiar with this. I don’t believe it’s a gym space…

---

<div class="post-metadata">

**Author:** ![Ofir\_Abu](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/ofir_abu/32/650_2.png) [@Ofir\_Abu](https://discuss.ray.io/u/Ofir_Abu)\
**Post date:** [September 23, 2021, 4:04pm UTC](https://discuss.ray.io/t/right-way-to-use-tuple-action-space/3594/7 "2021-09-23T16:04:45Z")

</div>

Correct, but it’s a compatible wrapper to the official Discrete space of gym, basically has some extra dtype casting functions.

Does someone have an example of the forward function’s output in a similar case?

---

<div class="post-metadata">

**Author:** ![Ofir\_Abu](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/ofir_abu/32/650_2.png) [@Ofir\_Abu](https://discuss.ray.io/u/Ofir_Abu)\
**Post date:** [September 23, 2021, 5:43pm UTC](https://discuss.ray.io/t/right-way-to-use-tuple-action-space/3594/8 "2021-09-23T17:43:43Z")

</div>

thanks again @mannyv !  
Is there an easy way to how the output of the forward pass is constructed? specifically - how do I debug it?

---

<div class="post-metadata">

**Author:** ![sven1977](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sven1977/32/53_2.png) [@sven1977](https://discuss.ray.io/u/sven1977)\
**Post date:** [September 24, 2021, 10:06am UTC](https://discuss.ray.io/t/right-way-to-use-tuple-action-space/3594/9 "2021-09-24T10:06:36Z")

</div>

Hey @Ofir_Abu , your Tuple space results in a MultiActionDistribution to be chosen by RLlib as the model’s output (the model parameterizes this distribution type and outputs an according number of nodes). The output values of the model are then split inside this distribution, according to the individual sub-spaces (2x DiscreteWDtype) and then actions will be sampled from these two spaces individually using the logits produced by your model.

You can debug into your forward pass by setting a breakpoint in e.g. `rllib/models/torch/torch_action_dist::TorchMultiActionDistribution::sample()` (of the respective tf version) AND setting `local_mode=True` in your call to `ray.init()`.

---

<div class="post-metadata">

**Author:** ![Ofir\_Abu](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/ofir_abu/32/650_2.png) [@Ofir\_Abu](https://discuss.ray.io/u/Ofir_Abu)\
**Post date:** [September 24, 2021, 11:30am UTC](https://discuss.ray.io/t/right-way-to-use-tuple-action-space/3594/10 "2021-09-24T11:30:09Z")

</div>

Sounds great thank you for the explanation about the 2 distributions.  
I will try now to debug it and edit the message with the results 🙂
