If you’re trying to compute your loss with pcc = scipy.stats.pearsonr(gtlabel, output.squeeze(-1))[0]. Then this is not possible. The only operations that are allowed to be able to differentiate them are pytorch operations.
If you’re using pcc = scipy.stats.pearsonr(gtlabel, output.squeeze(-1))[0] just to get some metric but don’t need to backprop through it, then you need to detach() your output before giving it to this function as output.detach().squeeze(-1).