HI,
Could you define what you mean by “cost” here? Are they gradients?
If you want to backprop each module independently, you can do:
X2_out = module_one(X1)

X2_in = X2_out.detach().requires_grad_()
Y = module_two(X2_in)
loss = crit(Y, target)


grad_X2 = autograd.grad(loss, X2_in) # backprop module 2
grad_X1 = autograd.grad(X2_out, X1, grad_X2) # backprop module 1