class Generator(nn.Module):
    def __init__(self):
        super(Generator, self).__init__()

        self.l1 = nn.Sequential(
            nn.Linear(1200, 240)
        )
        self.l2 = nn.Sequential(
            nn.Linear(1200, 100)
        )

    def forward(self, z):
        zh = self.l1(z)
        zh2 = self.l2(z)
        return torch.cat((zh,zh2), dim=1)

Ignore the meaningless network. I am wondering why can’t I define a function
def my_func(n_out):
  return nn.Sequential(
            nn.Linear(1200, n_out)
        )

and call
    def forward(self, z):
        zh = my_func(100)(z)
        zh2 = my_func(200)(z)
        return torch.cat((zh,zh2), dim=1)