I think you’d need something that iterates over model.parameters() to zero the ones you want out (if you can identify them):
E.g. something like this adapted from the main tutorial 4.
with torch.no_grad():
    for param in model.parameters():
        param.grad = param.grad*0

The problem with this is you’re still calculating all the gradients which can be expensive.