No, I don’t think your approach would work, since the .grad attributes do not contain any label information, so you won’t be able to multiply the dict with it.
Depending on the used loss function you could use the weight argument (e.g. in nn.CrossEntropyLoss) or you could use an unreduced loss and multiply it before applying the reduction and calling backward().