gpt4 book ai didi

Programmatically "stop" Sagemaker instance(以编程方式“停止”Sagemaker实例)

转载 作者:bug小助手 更新时间:2023-10-24 20:38:39 26 4
gpt4 key购买 nike



I can automatically shutdown a sagemaker instance as indicated here, by using lifecycle configuration

通过使用生命周期配置,我可以自动关闭Sagemaker实例,如下所示


https://stackoverflow.com/questions/53609409/automatically-stop-sagemaker-notebook-instance-after-inactivity

Is there a way to achieve this programmatically, by means of any ''image terminal'' command?
By image terminal, it is meant the Linux shell that can be opened via ''Launcher'' in ''Sagemaker Studio''

有没有办法通过编程实现这一点,通过任何‘’图像终端‘’命令?所谓的图像终端,是指可以通过Sagemaker Studio中的Launcher打开的Linux外壳。


My use case is large computational jobs, where the idle inactive time in the automatic solution would be quite expensive.
It would be useful to have a shutdown_instance(), to be added as last command in lengthy shell scripts

我的用例是大型计算作业,在这种情况下,自动解决方案中的空闲非活动时间将非常昂贵。将Shutdown_Instance()作为最后一个命令添加到冗长的外壳脚本中会很有用


更多回答

"image terminal command" ? What is "image" terminal. Sadly your question is unclear and lacks details.

“图像终端命令”?什么是“形象”终端。遗憾的是,你的问题不清楚,也缺乏细节。

Details have been added

已添加详细信息

优秀答案推荐

I was trying to do something similar with Sagemaker JupyterLab notebooks. (We have some long-running analytics which will eventually move to lambdas or similar, but for now are Notebook Scheduled Jobs). As the instances are bundled up in Apps (you'll note that commands like List_Instances() don't show these up!), we needed to:

我正试图用Sagemaker JupyterLab笔记本电脑做类似的事情。(我们有一些长期运行的分析,最终将转移到lambdas或类似的,但目前是笔记本计划的作业)。由于实例被捆绑在应用程序中(您会注意到像List_Insts()这样的命令不会显示这些实例!),我们需要:



  1. Identify what app is driving the notebook.

  2. Delete that app.


We run this as the last cell of the notebook. This is in Python, but you can just use the equivalent commands in the AWS CLI for the same effect in any bash script.

我们把它作为笔记本的最后一个单元来运行。这是在Python中实现的,但您只需在AWS CLI中使用相同的命令,即可在任何bash脚本中实现相同的效果。



def Cleanup_Notebook_Resouces():
log_path = '/opt/ml/metadata/resource-metadata.json'
with open(log_path, 'r') as logs:
AppDetails = json.load(logs)
AppDetails

AppDetails["AppName"] = AppDetails.pop("ResourceName")
AppDetails.pop("ResourceArn")
AppDetails.pop("AppImageVersion")

sage = boto3.client("sagemaker")

try:
sage.delete_app(**AppDetails)

except sage.exceptions.ClientError:
print("***" + AppDetails["AppName"] + " App Likely already deleted ***")
print("Current apps:")
print()
[print(a, "\n") for a in sage.list_apps()["Apps"]]


The same should be possible for true notebook instances... You can use boto3.client("sagemaker").List_Notebook_Instances() - the metadata logs may include a helpful resource name you can use as per the below, but I've not verified that.

对于真正的笔记本实例来说,同样的情况也是可能的。您可以使用boto3.client(“sagemaker”).List_Notebook_Instances()-元数据日志可能包含一个有用的资源名称,如下所示,但我还没有验证过这一点。


更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com