Use the padding parameter. The formula for the output size is given in the shape section at the bottom of the torch.nn.Conv2d documentation 3.5k. So e.g. k//2 for odd kernel sizes k with default stride and dilation.
Best regards
Thomas