In the optimizer there is an input called model.parameters(). The name might fool you into beliving that it is something related to the parameters of the optimizer but it is actually the parameters or the weights of the network you defined. So you should define before the optimizer a network called model. For instance if you were to define your neural network using the name network then the optimizer would be called as
optimizer= torch.optim.SGD(network.parameters(), lr=0.01). Check here for a complete example: https://pytorch.org/tutorials/beginner/pytorch_with_examples.html#pytorch-optim 1