If your models are in a list or tuple somewhere already, you can also use a nested list comprehension:
models = [nn.Linear(784, 500),
          nn.Linear(500, 10)
          ]
optimizer = torch.optim.SGD((par for model in models for par in model.parameters()),
                             lr=0.01)