# Differentiated tensor not being used in a graph

I am trying to take derivatives of a network with respect to its arguments and I am confused about a result I have been getting. For this example my network, model, takes 3 inputs and has two outputs. Here is the code I am running:

x = ipt[:,0].unsqueeze(1)
y = ipt[:,1].unsqueeze(1)
z = ipt[:,2].unsqueeze(1)

out = model(ipt).cuda()
A = out[:,0].unsqueeze(1)
B = out[:,1].unsqueeze(1)

I get the following error on the A_z line:
RuntimeError: One of the differentiated Tensors appears to not have been used in the graph. Set allow_unused=True if this is the desired behavior.
This confuses me since this is the only derivative computed so far so it seems like A_z isn’t being added to the graph?

Hi,

From what I can see, x, y and z are not used to compute the output right? Hence the error that you’re seeing
You can simply ask for the gradients wrt ipt and then slice that gradient to get the subset you’re interested in