I think your dimensions might be wrong.
nn.Conv2d expects inputs of [batch_size, channels, height, width].
Based on your example, it seems you are using 512 channels, while the spatial size is 49x49.
If that’s the case, a kernel_size of 25 with stride=1 and no padding might work:
conv = nn.Conv2d(512, 512, 25)
output = conv(torch.randn(1, 512, 49, 49))
print(output.size())
> torch.Size([1, 512, 25, 25])