I changed my code to
    with torch.no_grad():
        ax.scatter(X_train.detach().numpy(), y_train.detach().numpy(), color = "orange")
        ax.plot(X_train.detach().numpy(), score.detach().numpy(), 'g-', lw=3)

I hope that this is what you meant.