# How to change the module's param in forward function?

**URL:** <https://discuss.pytorch.org/t/how-to-change-the-modules-param-in-forward-function/8022>\
**Category:** Uncategorized\
**Created:** [September 28, 2017, 11:37pm UTC](https://discuss.pytorch.org/t/how-to-change-the-modules-param-in-forward-function/8022 "2017-09-28T23:37:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![quoniammm](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/quoniammm/32/1761_2.png) [@quoniammm](https://discuss.pytorch.org/u/quoniammm)\
**Post date:** [September 28, 2017, 11:37pm UTC](https://discuss.pytorch.org/t/how-to-change-the-modules-param-in-forward-function/8022/1 "2017-09-28T23:37:44Z")

</div>

```auto
class CNNText(nn.Module): 
    def __init__ (self):
        super(CNNText, self). __init__ ()
        self.encoder_tit = nn.Embedding(3281, 64)
        self.encoder_con = nn.Embedding(496037, 512)
        self.kernel_size = 0

        self.content_conv_5 = nn.Sequential(
            nn.Conv1d(in_channels = 512,
                      out_channels = 1,
                      kernel_size = 5),
            nn.ReLU(),
            nn.MaxPool1d(kernel_size = self.kernel_size)
        )
        
        
            
        self.fc = nn.Linear(256, 9)

    def forward(self, title, content):
        pass

```

If I want to change the value of self.kernel\_size in function forward.And when I change the value of kernel\_size.The module is also changed.The kernel\_size of maxpool1d is also changed.

How can I implement it?I can’t imagine a way to finish it.Please help me, thank you very much

---

<div class="post-metadata">

**Author:** ![smth](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/smth/32/13_2.png) [@smth](https://discuss.pytorch.org/u/smth)\
**Post date:** [September 29, 2017, 4:03am UTC](https://discuss.pytorch.org/t/how-to-change-the-modules-param-in-forward-function/8022/2 "2017-09-29T04:03:29Z")

</div>

you can easily change kernel size of MaxPool1d, but how will you change kernel\_size of Conv1d? you cannot change it because the total learnable parameters will change. it’s mathematically not obvious how to map from x number of parameters to y number of parameters and retain learnability of function.
