Hi,
I have created the following optimizer.
optimizer = optim.SGD(model.parameters(), lr=learning_rate, momentum=momentum)
Based on a condition, I am updating the weights for the new inputs. Whenever I update the weight, I am running through the following code body.
optimizer = optim.SGD(model.parameters(), lr=learning_rate, momentum=0.9) # doubt here
optimizer.zero_grad()
inputs_new, _ = data_list[max_index]
outputs_new = model(inputs_new)
loss = criterion(outputs_new, torch.tensor([y]))
loss.backward()
optimizer.step()

Is it correct to instantiate optimizer again and again (the line with the comment)? Is it a wrong practice? Is it logically wrong?
Thanks in advance.