How to switch from optimizer during training

I tried your exact code with a basic MNIST example and the weights are updating.

Can you check if this function is correct? Although as you said it’s working with Adam, so I am not sure what might be wrong here.