Is there a way to preserve a subgraph of the DAG which does not contains its root? As an example, consider the following code:
x1 = torch.randn(10, requires_grad=True)
x2 = x1 ** 2.
y1 = torch.randn(10, requires_grad=True)
y2 = y1 + 1.
z = (x2 + y1).sum()
z.backward(retain_graph=True)

I need to reuse x2, for other subsequent computation. To this end, I want to retain the subgraph associated to x2 and x1, zeroing its gradients but keeping their saved tensors for the intermediate computation, while I want to delete the subgraph associated to z, y2 and y1.