as far as I can see,  the code looks correct to me.  Can you please print the intermediate output of some layer  (say, a linear layer) for the same input with different batch size (in eval mode)  to ensure that the model behaves differently with varying batch size?