It’s in https://github.com/pytorch/pytorch/blob/master/torch/csrc/autograd/functions/convolution.cpp 108
However, extending it might be difficult. I suspect there may be easier ways to achieve your goals:

Narrow the weight tensor if the input is smaller than the kernel size
Use groups, and set groups=channels http://pytorch.org/docs/master/nn.html#torch.nn.Conv2d 40