Also this model definition works:

model = Discriminator(1, 1, 1)
x = torch.randn(1, 1)
target = torch.randn(1, 1)
outputs = model(x)
loss = mse_loss(outputs[0], target)
loss.backward()

for name, param in model.named_parameters():
    if param.grad is not None:
        print(name, param.grad.sum())
    else:
        print(name, param.grad)

> dis_model.0.weight tensor(-0.0065)
dis_model.0.bias tensor(-0.0575)
dis_model.2.weight tensor(-1.0274)
dis_model.2.bias tensor(-0.1347)
discriminator.0.weight tensor(0.9048)
discriminator.0.bias tensor(0.3326)
encoder.0.weight None
encoder.0.bias None
co_encoder.0.weight None
co_encoder.0.bias None