If I understand the question correctly, you are concerned about the “conversion” of the model output and the loss computation. As long as you are not using a non-differentiable operation in this “conversion” and the new output is thus still attached to the computation graph, Autograd will be able to compute the gradients of all parameters, which were used to create the original output.