No, you can’t do that. An nn.Parameter necessarily wants to be a leaf (i.e. have no upstream nodes), that is part of what it is. So the answer is a obvious as it may be unsatisfying: You cannot use nn.Parameter and keep this as one graph.
What you can do is take two steps:
y_grad = torch.autograd.grad(loss, param)[0]
d_loss_dx = d_loss_dx = torch.autograd.grad(y, x, only_inputs=True)[0]

There is a PyTorch issue discussing to allow 63 Parameters to be themselves calculated, but at the time, it had not gained enough traction to implement it.
Best regards
Thomas