Custom backpropagation groupwise

Is there a way to make a custom backpropagation groupwise?

For example, I have a single nn.Conv2d(16, 32, 2) layer and an array(len=32) of numbers from 0 to 5.
How can I propagate the same (mean) gradient for every filter from Conv2d with the same numbers in array?