You’re mixing different parameter handling styles here, which is why it doesn’t work. If you use setup and pass a model to (with)gradient, don’t use params (and vice versa). Change this to:
Flux.update!(optim, glob, grads)
And things should work.