scipy.optimize.minimize正在消耗高射线运行时

发布于 2025-01-23 14:37:24 字数 742 浏览 0 评论 0原文

scipy.optimize.minimize正在消耗大量的RAM,并且会话正在崩溃。我正在Google Colab中执行代码,其中提供了12.69 GB的RAM。我正在使用MNIST DATATSET,这也不是很大。我的约束和目标函数以 -

#Declaring the minimization equation here

def objective(x):
    alpha = x[0]
    v=x[1:len(x)]
    vnorm=torch.linalg.vector_norm(v) * torch.linalg.vector_norm(v)
    return alpha+(vnorm/2)

#Declaring the constraint here

def constraint(x):
    alpha=x[0]
    v=x[1:len(x)]
    return -(A @ v)+alpha


cons={'type':'ineq','fun':constraint}
result=minimize(objective,val,constraints=cons,options={"disp":True})

此处的大小为88字节,并且是2 x 318737张量。最小化方程中的阀为318738 x 1张量的

val已通过val.cpu()。但是,一旦调用了最小化方法,执行即将失败,因为RAM已被加载,并且超过了Google Colab提供的12.69 GB RAM。如何减少这一点?有什么解决方法吗?还是我可以使用的其他优化器?

Scipy.optimize.minimize is consuming lot of RAM and the session is crashing. I am executing the code in google colab where 12.69 GB of RAM is provided. I am using MNIST datatset which also not very huge. My constraint and objective function is given as -

#Declaring the minimization equation here

def objective(x):
    alpha = x[0]
    v=x[1:len(x)]
    vnorm=torch.linalg.vector_norm(v) * torch.linalg.vector_norm(v)
    return alpha+(vnorm/2)

#Declaring the constraint here

def constraint(x):
    alpha=x[0]
    v=x[1:len(x)]
    return -(A @ v)+alpha


cons={'type':'ineq','fun':constraint}
result=minimize(objective,val,constraints=cons,options={"disp":True})

Here size of A is 88 bytes and is a 2 by 318737 tensor. The val in the minimization equation is 318738 by 1 tensor

val has been copied to cpu by val.cpu().numpy() so that it works with scipy. However the execution is failing once the minimize() method is called because the RAM is getting over loaded and it is exceeding 12.69 GB RAM offered by google colab. How can I reduce this? Is there any workaround to this? or any other optimizer which I can use?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文