How to train only certain weights in a model?

Let’s say a I have boolean mask dict with the masks having the same shape of the weight tensors of the model. Is it possible to perform back propagation and update only for the masked weights?