This is my simple model:
class Generator(nn.Module):
    def __init__(self):
        super(Generator, self).__init__()
        self.latent_dim = 2
        self.model = nn.Linear(self.latent_dim, 2)

    def forward(self, z):
        return self.model(z)

    def generate_samples(self, N_samples):
        z = torch.tensor(np.random.normal(0, 1, (N_samples, self.latent_dim))).float()
        samples = self(z)
        return z

The following code returns False:
G = Generator()
G.generate_samples(20).requires_grad

What’s the problem here?