Hello, I am looking for a way to backpropagate with respect to some mask matrix, which weights (let’s say weights from torch.nn.Linear or Conv2d) are multiplicated by. The problem is, the weights are Parameter’s class, thus leaf nodes.
Right now I am doing it like this before backpropagading through the mask:
        temp = model[layer_nr].weight.data
        del model[layer_nr].weight
        model[layer_nr].weight = temp

And later, when I want to go back to backprop with respect to parameters:
model[layer_nr].weight = nn.Parameter(model[layer_nr].weight)
I am looking for a better, simpler way. Is there something in PyTorch to help me do such a thing?