In your predict method you are explicitly detaching the tensors from the computation graph in:
samples_ = [self.forward(x).detach()
            for _ in range(samples)]

so that the samples_ doesn’t have a valid grad_fn anymore (it’s not attached to any computation graph) and thus the backward call fails.