Saving best model in script without Trainer class

Hi. I have a script similar to this one. I would like to save the best models according to the evaluation metric (in this case, sacrebleu). Is there a quick way to achieve this behaviour?
Thanks in advance for any help you can provide.