# Question on code: \_wrapped\_forward

**URL:** <https://discuss.ray.io/t/question-on-code-wrapped-forward/4289>\
**Category:** RLlib\
**Created:** [November 29, 2021, 5:44pm UTC](https://discuss.ray.io/t/question-on-code-wrapped-forward/4289 "2021-11-29T17:44:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mg64ve](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mg64ve/32/606_2.png) [@mg64ve](https://discuss.ray.io/u/mg64ve)\
**Post date:** [November 29, 2021, 5:44pm UTC](https://discuss.ray.io/t/question-on-code-wrapped-forward/4289/1 "2021-11-29T17:44:02Z")

</div>

Hello,

can anyone explain me what is the reason of the following two lines:

```
    # Push obs through "unwrapped" net's `forward()` first.
    wrapped_out, _ = self._wrapped_forward(input_dict, [], None)

```

in the following file:

> <https://github.com/ray-project/ray/blob/e6ae08f41674d2ac1423f3c2a4f8d8bd3500379a/rllib/models/torch/recurrent_net.py>

it is in the LSTMWrapper class and forward method.  
Thanks.

---

<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:** [November 30, 2021, 2:03am UTC](https://discuss.ray.io/t/question-on-code-wrapped-forward/4289/2 "2021-11-30T02:03:03Z")

</div>

Hi @mg64ve,

When you set `config["model"]["use_lstm"] =True`, rllib will automatically create an lstm for you. This is the code you are looking at.

The way it does it is it first creates a model (base) with the layers before the lstm. These are fullyconnected or conv layers. Then it creates a second model that has the lstm and output layers (logits and value).

That line you asked about is when it passes the inputs from the environment to the base model to get the embedding inputs for the lstm.

---

<div class="post-metadata">

**Author:** ![mg64ve](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mg64ve/32/606_2.png) [@mg64ve](https://discuss.ray.io/u/mg64ve)\
**Post date:** [November 30, 2021, 10:39am UTC](https://discuss.ray.io/t/question-on-code-wrapped-forward/4289/3 "2021-11-30T10:39:33Z")

</div>

Ok Thank you very much @mannyv for your explanation.  
I would like to implement a custom RNN model with a L2 weights regularization.  
From this comment:

```
# === Built-in options ===
# FullyConnectedNetwork (tf and torch): rllib.models.tf|torch.fcnet.py
# These are used if no custom model is specified and the input space is 1D.
# Number of hidden layers to be used.
"fcnet_hiddens": [256, 256],
# Activation function descriptor.
# Supported values are: "tanh", "relu", "swish" (or "silu"),
# "linear" (or None).
"fcnet_activation": "tanh",

```

I believe for custom models there is no FC input layer, right?  
Now, if I implement my custom model, I believe this would not have a previous action/reward stacking mechanism, right? any good hint on how to implement it?
