I think the reason TensorFlow provides the stop_gradients for tf.gradients is mainly to “provides a way of stopping gradient after the graph has already been constructed” 3.
However, PyTorch builds the graph dynamically. But I think this stop_gradients feature is useful when we want to change the retained graph.
Regarding your scenario, I think something like this may work:
import torch

a = torch.tensor(1., requires_grad=True)
b = 2 * a
c = a + b
c_detach = a + b.detach()
d = 2 * c
loss = d.sum()

print(torch.autograd.grad(d, a, retain_graph=True))
print(torch.autograd.grad(c, a, retain_graph=True))
print(torch.autograd.grad(c_detach, a, retain_graph=True))
print(a.grad)
loss.backward()
print(a.grad)