【问题标题】:How to install python packages within Amazon Sagemaker Processing Job?如何在 Amazon Sagemaker 处理作业中安装 python 包?
【发布时间】:2021-12-08 04:38:32
【问题描述】:

我正在尝试在 Amazon Sagemekar 中创建一个 Sklearn 处理作业,以便在进行模型训练之前对我的输入数据执行一些数据转换。

我编写了一个自定义 python 脚本preprocessing.py,它可以满足需要。我在这个脚本中使用了一些 python 包。 Here is the Sagemaker example I followed.

当我尝试提交处理作业时出现错误 -

............................Traceback (most recent call last):
  File "/opt/ml/processing/input/code/preprocessing.py", line 6, in <module>
    import snowflake.connector
ModuleNotFoundError: No module named 'snowflake.connector'

我了解我的处理工作找不到此软件包,我需要安装它。我的问题是如何使用 Sagemaker 处理作业 API 完成此任务?理想情况下,应该有一种方法可以在 API 调用中定义 requirements.txt,但我在文档中没有看到这样的功能。

我知道我可以 create a custom Image with relevant packages 并稍后在处理作业中使用此图像,但这对于应该内置的东西来说似乎太多了?

是否有更简单/优雅的方式来安装 Sagemaker 处理作业所需的软​​件包?

【问题讨论】:

    标签: amazon-web-services amazon-sagemaker


    【解决方案1】:

    一种方法是call pip from Python:

    subprocess.check_call([sys.executable, "-m", "pip", "install", package])
    

    另一种方法是改用SKLearn Estimator(培训工作)来做同样的事情。您可以提供source_dir,其中可以包含requirements.txt 文件,系统将为您安装这些要求

    estimator = SKLearn(
        entry_point="foo.py",
        source_dir="./foo", # no trailing slash! put requirements.txt here
        framework_version="0.23-1",
        role = ...,
        instance_count = 1,
        instance_type = "ml.m5.large"
    )
    

    【讨论】:

      猜你喜欢
      • 2022-01-14
      • 1970-01-01
      • 2023-01-09
      • 1970-01-01
      • 1970-01-01
      • 2022-01-24
      • 2021-10-13
      • 2021-02-26
      • 2022-01-23
      相关资源
      最近更新 更多