In your example you are applying the convolution for the 4 samples in the current batch and 4 channels.
This should work as you’ve suggested:
batch_size = 10
channels = 10
h, w = 24, 24
x = torch.randn(batch_size, channels, h, w)

conv = nn.Conv2d(4, 1, 3, 1, 1)
output = conv(x[1:5, 1:5])