如何验证 sagemaker 中是否安装了所有依赖项?

发布于 2025-01-09 12:10:26 字数 523 浏览 0 评论 0原文

我正在创建一个 sagemaker 端点并从 s3 存储桶加载预训练模型。模型 -> model.tar.gz 文件具有此处记录的目录结构, https://sagemaker.readthedocs.io/en/stable/frameworks/pytorch/using_pytorch.html#model-directory-struct

model.tar.gz/
|- model.pth
|- code/
  |- inference.py
  |- requirements.txt  # only for versions 1.3.1 and higher

我放置了一些依赖项在requirements.txt中,有没有办法验证所有依赖项是否已正确安装?

I am creating an sagemaker endpoint and loading a pretrained model from an s3 bucket. the model -> model.tar.gz file has directory structure as documented here, https://sagemaker.readthedocs.io/en/stable/frameworks/pytorch/using_pytorch.html#model-directory-structure

model.tar.gz/
|- model.pth
|- code/
  |- inference.py
  |- requirements.txt  # only for versions 1.3.1 and higher

I have put few dependencies in requirements.txt, is there a way to verify that all the dependencies were installed correctly?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

や莫失莫忘 2025-01-16 12:10:26

由于 SageMaker 的部署是无服务器的,因此无法访问或通过 SSH 访问正在运行部署的计算机。因此,一种方法是通过执行如下操作来断言“inference.py”内的 model_fn 中的依赖项版本。

如果您的requirements.txt如下所示:

numpy==1.20.3
pandas==1.3.4

获取版本并在`model_fn中断言它们,如下所示:

import os

### your other code ###

def model_fn(model_dir):
    # assuming you have numpy and pandas
    assert os.popen("python3 -m pip freeze | grep -E 'numpy|pandas'").read() == 'numpy==1.20.3\npandas==1.3.4\n'
    ### your other code ###
    return xxxx

### your other code ###

Since SageMaker's deployments are serverless, it is not possible to get access or SSH into the machine that's running your deployment. So, one way is to assert the versions of your dependencies in the model_fn inside "inference.py" by doing something like below.

if your requirements.txt looks like this:

numpy==1.20.3
pandas==1.3.4

get the versions and assert them in `model_fn like below:

import os

### your other code ###

def model_fn(model_dir):
    # assuming you have numpy and pandas
    assert os.popen("python3 -m pip freeze | grep -E 'numpy|pandas'").read() == 'numpy==1.20.3\npandas==1.3.4\n'
    ### your other code ###
    return xxxx

### your other code ###
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文