Puzzling question

I have code that consistently achieves a certain score on a computer vision task.

Whenever I grab that code and try to make a class out of it with a .run() and similar methods, I get a slightly lower score. Even when I average over many runs.

Same exact code, but I try to abstract it. I copy paste it into methods basically. I do not change anything. I make attributes out of model, optimizer, scheduler and use those attributes in methods.

Is there anything that would be causing this from PyTorch?