简体   繁体   English

从本地ipython笔记本在EC2上运行python进程

[英]Running python process on EC2 from local ipython notebook

I'm playing around with some python deep learning packages (Theano/Lasagne/Keras). 我在玩一些python深度学习软件包(Theano / Lasagne / Keras)。 I've been running it on CPU on my laptop, which takes a very long time to train the models. 我一直在笔记本电脑的CPU上运行它,这花费了很长时间来训练模型。

For a while I was also using Amazon GPU instances, with an iPython notebook server running, which obviously ran much faster for full runs, but was pretty expensive to use for prototyping. 一段时间以来,我还使用了运行iPython笔记本服务器的Amazon GPU实例,该服务器显然可以以更快的速度运行,但要进行原型制作非常昂贵。

Is there any way to set things up that would let me prototype in iPython on my local machine, and then when I have a large model to train spin up a GPU instance, do all processing/training on that, then shut down the instance. 有什么方法可以让我在本地计算机上的iPython中进行原型制作,然后当我有一个大型模型来训练一个GPU实例时,对其进行所有处理/训练,然后关闭该实例。

Is a setup like this possible, or does anyone have any suggestions to combine the convenience of the local machine with temporary processing on AWS? 这样的设置是否可行,或者有人建议将本地计算机的便利性与AWS上的临时处理结合起来吗?

My thoughts so far were along the lines of 到目前为止,我的想法是

  1. Prototype on local ipython notebook 本地ipython笔记本上的原型

  2. Set up cell to run a long process from start to finish. 设置单元以从头到尾运行一个漫长的过程。

  3. Use boto to start up an ec2 instance ssh into the instance using boto's sshclient_from_instance 使用boto使用boto的sshclient_from_instance将ec2实例ssh启动到实例中

     ssh_client = sshclient_from_instance(instance, key_path='<path to SSH keyfile>', user_name='ec2-user') 
  4. Get the contents of the cell I've set up using the script using the solution here , say the script is in cell 13 Execute that script using 使用此处的解决方案获取我使用脚本设置的单元格的内容,说该脚本在单元格13中,请使用执行该脚本

     ssh_client.run('python -c "'+ _i13 + '"' ) 
  5. Shut down instance using boto 使用Boto关闭实例

This just seems a bit convoluted, is there a proper way to do this? 这似乎有点令人费解,是否有适当的方法来做到这一点?

So when it comes to EC2 you don't have to shut down the instance every time. 因此,当涉及到EC2时,您不必每次都关闭实例。 The beauty of AWS is that you stop and start your instance when you use it, and only pay for the time you have it up and running. AWS的优点在于,您可以在使用实例时停止并启动实例,而只为启动和运行实例付费。 Also you can always try your code on a smaller and cheaper instance, and if its too slow for your liking then you just scale up to a larger instance. 另外,您始终可以在更小,更便宜的实例上尝试代码,如果它太慢而无法满足您的需求,那么您就可以扩展到更大的实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM