KFrank:

def MSE_toOptimize(params,yHat,y):
    ...
    x = torch.tensor(x).to('cuda:0')
    ...
    return res_.cpu().detach().numpy()



Only when the function returns the result transfered on cpu, detached and converted to numpy, the minimize function can accept MSE_toOptimize as its first argument. This probably breaks the flow of computation graph, but I am not sure how to make minimize work otherwise. Would you be aware of a simple workaround solution?