The parameters of a model should be consistency, no matter what mode it is (train or eval). So your patch commit is the right way to go.
And the parameters you used when training and inference have different values, so it will have different output. I do not know what you are actually doing here but the output of training and inference don’t match seems to reasonable to me.
And, it’s weird to loop the parameters in forward , you can refactor your code like this:
slope = getattr(slope_name, self)
intercept = getattr(intercept_name, self)