i have implemented a custom loss function and learning weights using pytorch’s autograd system. in the weight matrix w of dimension 16*32 i want to only learn a subset of the weights say for instance w[0][0] ,w[0][1] in the first row and the remaining should be set to zero and w[1][2],w[1][3] in the second row and the remaining elements set to zero and so on for all the rows we have a fixed set of two weights i want to learn and i dont want to learn the remaining weights . i have read about the requires_grad flag but i have read in this 1 post that we cant set it to a subset of elements .

after learning the weights using gradient descent , is extracting only the required weights and setting all the remaining weights to zero useful?
is setting the unrequired weights to 0 after every iteration of gradient descent a possible solution ?
can you please suggest a way to achieve this ?