How to set bias a tensor of (C_out, C_out, kernel_size, kernel_size)?

I have a trained model. I want to chenge bias of some convolutions in the model for better inference performance. for example, the shape of kernel is (C_out, C_in, 3, 3) and the shape of bias is (C_out, ). I want to set new value to bias. the shape of new bias is (C_out, C_in, 3, 3) and it can set different bias for every point in kernel. how can i achieve this?

Docs in Conv2d — PyTorch 1.13 documentation that told shape of kernel and bias.

Do you mean you want a bias of shape e.g., (k, k, C_out), or of (output_y, output_x, C_out)? For the former, note that it should basically be equivalent to the existing case as the values would simply be added up. For the latter, you would need to need to disable the bias in the convolution and create a new layer for the bias as it would have different semantics than native Conv2d.

thank you. I misunderstood my needs. I calculate a new bias of shape (C_out, C_in, k, k),and just add the bias in (C_in, k, k).