Sure, you are more familiar with your use case so take my post with a grain of salt. 
I don’t know which operation causes the shape mismatch and also don’t know if you are even dealing with a batch dimension. Just check the shape before and after the reduction and make sure the shapes are explainable and make sense. E.g. if you are dealing with a simple model using linear layers, using sum(0) on an activation would remove the batch dimension and you would have to think about if that’s the right approach as your model would “map” N samples to a single output.