The reason is, that your conv layer resamples the input differently than your pooling layer.
While both should halve the input in the spatial dimensions, the pool layer will use the floor operation by default, resulting in floor(341/2)=170 for the width. Setting ceil_mode=True will instead return 171 which matches the conv output.
Your new error seems to be related to the same issue. The target is a column smaller than the output.
Usually it’s simpler to use base2 sizes, but if that’s not possible in your use case, you would have to check, which operation creates the size mismatch.