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

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.MaxPool1d(kernel_size = self.kernel_size)
        self.fc = nn.Linear(256, 9)

    def forward(self, title, content):

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

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.