Replace thr ^ operations with ** and if all inputs are defined it should work fine.
I don’t know what d_model is but it might be a constant or any other value you could pass to the scheduler.
You should be able to define this schedule in e.g. lr_scheduler.LambdaLR.